Merge lp:~xnox/apparmor/py3 into lp:apparmor/2.12

Proposed by Dimitri John Ledkov
Status: Merged
Merged at revision: 2052
Proposed branch: lp:~xnox/apparmor/py3
Merge into: lp:apparmor/2.12
Diff against target: 420 lines (+79/-60)
8 files modified
common/Make.rules (+15/-0)
libraries/libapparmor/m4/ac_python_devel.m4 (+22/-24)
utils/Makefile (+2/-4)
utils/aa-easyprof (+2/-2)
utils/apparmor/easyprof.py (+15/-10)
utils/test/test-aa-easyprof.py (+4/-3)
utils/vim/Makefile (+4/-1)
utils/vim/create-apparmor.vim.py (+15/-16)
To merge this branch: bzr merge lp:~xnox/apparmor/py3
Reviewer Review Type Date Requested Status
Jamie Strandboge Approve
Adam Conrad (community) Approve
Canonical Foundations Team Pending
AppArmor Developers Pending
Review via email: mp+109682@code.launchpad.net

Description of the change

This is a complete port to make apparmor Python2/Python3 bilingual.
There are 3 variables in use:
PYTHON, used by common/Make.rule and libapparmor configure script pointing to a python interpreter
PYTHON_VERSION, used by libapparmor configure script with just version number e.g. '3.2' or '2.7'
PYTHON_VERSIONS, list of all pythons to run checks/tests with for python utilities e.g. 'python2 python3'

If none are specified, defaults will be autodetected to:
PYTHON=/usr/bin/python2 in Make.rule
PYTHON=/usr/bin/python2.7 in configure
PYTHON_VERSION=2.7
PYTHON_VERSIONS='python2 python3'

To build libapparmor (including the python swig bindings) with python3 it seems like you must set these two variables:
PYTHON=/usr/bin/python3.2
PYTHON_VERSIONS=3.2

All test and check targets pass and build succeeds.
Scripts are functional.
Swig python module can import and doesn't segfault in smoke testing.

TODO:
/usr/bin/aa-easyprof gets installed without updated shebang to point at python3
ac_python_devel patch should probably be submitted to autoconf-archive (updating it's ax_python_devel), not sure about the install location as historically a*_python_devel installs into site-packages, instead of dist-packages.

To post a comment you must log in.
Revision history for this message
Barry Warsaw (barry) wrote :

On Jun 11, 2012, at 05:04 PM, Dmitrijs Ledkovs wrote:

>Dmitrijs Ledkovs has proposed merging lp:~dmitrij.ledkov/apparmor/py3 into lp:apparmor.
>
>Requested reviews:
> Canonical Foundations Team (canonical-foundations)
> AppArmor Developers (apparmor-dev)
>
>For more details, see:
>https://code.launchpad.net/~dmitrij.ledkov/apparmor/py3/+merge/109682
>
>Initial port to python3 for utilities.
>
>Python2 compatibility is not broken, all code should be 'bilingual'.
>
>Adds helpers in the Make.rules to detect python2 and/or python3.
>
>Runs test and check targets with both pythons, if available.
>
>Python3 is entirely optional with these changes, but the test/check targets will fail if python3 incompatible code is introduced and python3 is available during build. If you do not want the build to fail export PYTHON_VERSIONS=python2 before running check/test targets.
>
>Currently the install defaults to python2, with fallback to python3
>
>This does not have anything to do with swig python binding.

=== modified file 'utils/apparmor/easyprof.py'
--- utils/apparmor/easyprof.py 2012-05-08 05:37:48 +0000
+++ utils/apparmor/easyprof.py 2012-06-11 17:03:23 +0000
> @@ -70,7 +70,8 @@
> try:
> sp = subprocess.Popen(command, stdout=subprocess.PIPE,
> stderr=subprocess.STDOUT)
> - except OSError, ex:
> + except OSError:
> + ex = sys.exc_info()[1]
> return [127, str(ex)]

I think in general, a better way of doing this would be to change the except
line to

    except OSError as ex:

> @@ -181,7 +183,8 @@
> fn = policy
> else:
> f, fn = tempfile.mkstemp(prefix='aa-easyprof')
> - os.write(f, policy)
> + policy_bytes = bytes(policy, 'utf-8') if sys.version > '3' else policy
> + os.write(f, policy_bytes)

I generally don't like version checks unless there's no other way. In this
case, you could do something like this instead:

    if not isinstance(policy, bytes):
        policy = policy.encode('utf-8')

=== modified file 'utils/test/test-aa-easyprof.py'
--- utils/test/test-aa-easyprof.py 2012-05-09 18:05:07 +0000
+++ utils/test/test-aa-easyprof.py 2012-06-11 17:03:23 +0000
> @@ -101,6 +101,7 @@
> def tearDown(self):
> '''Teardown for tests'''
> if os.path.exists(self.tmpdir):
> + sys.stdout.write("%s\n" % self.tmpdir)
> recursive_rm(self.tmpdir)
>
> #

Why did you decide against using print(). I'm sure there's a good reason, but
it might be useful in at least some of these cases to explain in comments why
sys.stdout.write() is being used instead of print(). Otherwise, when the next
person comes along they probably won't understand why this idiom was chosen.

lp:~xnox/apparmor/py3 updated
2053. By Dimitri John Ledkov

newline parity with print statement vs sys.stdout.write

Revision history for this message
Adam Conrad (adconrad) wrote :

Looks good to me, but I can't commit to the parent branch, so waiting on someone from AppArmor Devs to pick it up and run with it.

review: Approve
Revision history for this message
Evan (ev) wrote :

> - print open(i).read()
> + sys.stdout.write(open(i).read()+"\n")

This will leak fds, which python wonderfully loudly complains about in Python 3. It's also a good opportunity to replace any pairs of open() and close() with a with statement. If an open() and close() isn't wrapped in a with or try/finally, I would argue that is a bug.

Revision history for this message
Dimitri John Ledkov (xnox) wrote :
Download full text (3.2 KiB)

On 11/06/12 21:34, Barry Warsaw wrote:
> On Jun 11, 2012, at 05:04 PM, Dmitrijs Ledkovs wrote:
>
>> Dmitrijs Ledkovs has proposed merging lp:~dmitrij.ledkov/apparmor/py3 into lp:apparmor.
>>
>> Requested reviews:
>> Canonical Foundations Team (canonical-foundations)
>> AppArmor Developers (apparmor-dev)
>>
>> For more details, see:
>> https://code.launchpad.net/~dmitrij.ledkov/apparmor/py3/+merge/109682
>>
>> Initial port to python3 for utilities.
>>
>> Python2 compatibility is not broken, all code should be 'bilingual'.
>>
>> Adds helpers in the Make.rules to detect python2 and/or python3.
>>
>> Runs test and check targets with both pythons, if available.
>>
>> Python3 is entirely optional with these changes, but the test/check targets will fail if python3 incompatible code is introduced and python3 is available during build. If you do not want the build to fail export PYTHON_VERSIONS=python2 before running check/test targets.
>>
>> Currently the install defaults to python2, with fallback to python3
>>
>> This does not have anything to do with swig python binding.
>
> === modified file 'utils/apparmor/easyprof.py'
> --- utils/apparmor/easyprof.py 2012-05-08 05:37:48 +0000
> +++ utils/apparmor/easyprof.py 2012-06-11 17:03:23 +0000
>> @@ -70,7 +70,8 @@
>> try:
>> sp = subprocess.Popen(command, stdout=subprocess.PIPE,
>> stderr=subprocess.STDOUT)
>> - except OSError, ex:
>> + except OSError:
>> + ex = sys.exc_info()[1]
>> return [127, str(ex)]
>
> I think in general, a better way of doing this would be to change the except
> line to
>
> except OSError as ex:
>

Ok, this does look better. This way was not documented on the Python/3
wiki page, nor in the porting to python3 book.

Noted.

>> @@ -181,7 +183,8 @@
>> fn = policy
>> else:
>> f, fn = tempfile.mkstemp(prefix='aa-easyprof')
>> - os.write(f, policy)
>> + policy_bytes = bytes(policy, 'utf-8') if sys.version > '3' else policy
>> + os.write(f, policy_bytes)
>
> I generally don't like version checks unless there's no other way. In this
> case, you could do something like this instead:
>
> if not isinstance(policy, bytes):
> policy = policy.encode('utf-8')
>

Makes sense. Cjwatson was arguing for version checks, as they are easy
to grep for when eventually going python3 only.

> === modified file 'utils/test/test-aa-easyprof.py'
> --- utils/test/test-aa-easyprof.py 2012-05-09 18:05:07 +0000
> +++ utils/test/test-aa-easyprof.py 2012-06-11 17:03:23 +0000
>> @@ -101,6 +101,7 @@
>> def tearDown(self):
>> '''Teardown for tests'''
>> if os.path.exists(self.tmpdir):
>> + sys.stdout.write("%s\n" % self.tmpdir)
>> recursive_rm(self.tmpdir)
>>
>> #
>
> Why did you decide against using print(). I'm sure there's a good reason, but
> it might be useful in at least some of these cases to explain in comments why
> sys.stdout.write() is being used instead of print(). Otherwise, when the next
> person comes along they probably won't understand why this idiom was chosen.
>

You should ask this question to apparmor's upstre...

Read more...

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

Pushed revision 2054:
* closes file descriptors
* uses except OSError as ex
* doesn't do version checks
* more stray print statements converted to sys.stdXXX.write() syntax

lp:~xnox/apparmor/py3 updated
2054. By Dimitri John Ledkov

* Use with open('file') as f, to prevent leaking file descriptors
* More print -> sys.stdXXX.write() conversions
* Use `except Error as ex` & no sys.version checks
* add with_statement import for py2.5 compat
* remove unused import

2055. By Dimitri John Ledkov

python2/3 compatible ac_python_devel.m4

2056. By Dimitri John Ledkov

Remaining typos

2057. By Dimitri John Ledkov

typo

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Thanks for your work on this, it looks great! :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'common/Make.rules'
2--- common/Make.rules 2012-04-11 16:16:47 +0000
3+++ common/Make.rules 2012-06-12 13:52:18 +0000
4@@ -27,6 +27,10 @@
5 DISTRIBUTION=AppArmor
6 VERSION=$(shell cat common/Version)
7
8+# Convenience functions
9+pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))
10+map = $(foreach a,$(2),$(call $(1),$(a)))
11+
12 # OVERRIDABLE variables
13 # Set these variables before including Make.rules to change its behavior
14 # SPECFILE - for packages that have a non-standard specfile name
15@@ -127,6 +131,17 @@
16
17 endif
18
19+ifndef PYTHON_VERSIONS
20+PYTHON_VERSIONS = $(call map, pathsearch, python2 python3)
21+endif
22+
23+ifndef PYTHON
24+PYTHON = $(firstword ${PYTHON_VERSIONS})
25+endif
26+
27+#Helper function to be used with $(call pyalldo, run_test_with_all.py)
28+pyalldo=set -e; $(foreach py, $(PYTHON_VERSIONS), $(py) $(1);)
29+
30 .PHONY: version
31 .SILENT: version
32 version:
33
34=== modified file 'libraries/libapparmor/m4/ac_python_devel.m4'
35--- libraries/libapparmor/m4/ac_python_devel.m4 2012-04-25 19:15:19 +0000
36+++ libraries/libapparmor/m4/ac_python_devel.m4 2012-06-12 13:52:18 +0000
37@@ -17,9 +17,9 @@
38 # Check for a version of Python >= 2.1.0
39 #
40 AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
41- ac_supports_python_ver=`$PYTHON -c "import sys, string; \
42- ver = string.split(sys.version)[[0]]; \
43- print ver >= '2.1.0'"`
44+ ac_supports_python_ver=`$PYTHON -c "import sys; \
45+ ver = sys.version.split()[[0]]; \
46+ sys.stdout.write(str(ver >= '2.1.0'))"`
47 if test "$ac_supports_python_ver" != "True"; then
48 if test -z "$PYTHON_NOVERSIONCHECK"; then
49 AC_MSG_RESULT([no])
50@@ -44,9 +44,9 @@
51 #
52 if test -n "$1"; then
53 AC_MSG_CHECKING([for a version of Python $1])
54- ac_supports_python_ver=`$PYTHON -c "import sys, string; \
55- ver = string.split(sys.version)[[0]]; \
56- print ver $1"`
57+ ac_supports_python_ver=`$PYTHON -c "import sys; \
58+ ver = sys.version.split()[[0]]; \
59+ sys.stdout.write("%s\n" % (ver == $1))"`
60 if test "$ac_supports_python_ver" = "True"; then
61 AC_MSG_RESULT([yes])
62 else
63@@ -80,8 +80,8 @@
64 #
65 AC_MSG_CHECKING([for Python include path])
66 if test -z "$PYTHON_CPPFLAGS"; then
67- python_path=`$PYTHON -c "import distutils.sysconfig; \
68- print distutils.sysconfig.get_python_inc();"`
69+ python_path=`$PYTHON -c "import sys; import distutils.sysconfig;\
70+sys.stdout.write('%s\n' % distutils.sysconfig.get_python_inc());"`
71 if test -n "${python_path}"; then
72 python_path="-I$python_path"
73 fi
74@@ -97,22 +97,20 @@
75 if test -z "$PYTHON_LDFLAGS"; then
76 # (makes two attempts to ensure we've got a version number
77 # from the interpreter)
78- py_version=`$PYTHON -c "from distutils.sysconfig import *; \
79- from string import join; \
80- print join(get_config_vars('VERSION'))"`
81+ py_version=`$PYTHON -c "import sys; from distutils.sysconfig import *; \
82+sys.stdout.write('%s\n' % ''.join(get_config_vars('VERSION')))"`
83 if test "$py_version" == "[None]"; then
84 if test -n "$PYTHON_VERSION"; then
85 py_version=$PYTHON_VERSION
86 else
87 py_version=`$PYTHON -c "import sys; \
88- print sys.version[[:3]]"`
89+sys.stdout.write("%s\n" % sys.version[[:3]])"`
90 fi
91 fi
92
93- PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
94- from string import join; \
95- print '-L' + get_python_lib(0,1), \
96- '-lpython';"`$py_version
97+ PYTHON_LDFLAGS=`$PYTHON -c "import sys; from distutils.sysconfig import *; \
98+sys.stdout.write('-L' + get_python_lib(0,1) + ' -lpython\n')"`$py_version`$PYTHON -c \
99+"import sys; sys.stdout.write('%s' % getattr(sys,'abiflags',''))"`
100 fi
101 AC_MSG_RESULT([$PYTHON_LDFLAGS])
102 AC_SUBST([PYTHON_LDFLAGS])
103@@ -122,8 +120,8 @@
104 #
105 AC_MSG_CHECKING([for Python site-packages path])
106 if test -z "$PYTHON_SITE_PKG"; then
107- PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
108- print distutils.sysconfig.get_python_lib(0,0);"`
109+ PYTHON_SITE_PKG=`$PYTHON -c "import sys; import distutils.sysconfig; \
110+sys.stdout.write('%s\n' % distutils.sysconfig.get_python_lib(0,0));"`
111 fi
112 AC_MSG_RESULT([$PYTHON_SITE_PKG])
113 AC_SUBST([PYTHON_SITE_PKG])
114@@ -133,9 +131,9 @@
115 #
116 AC_MSG_CHECKING(python extra libraries)
117 if test -z "$PYTHON_EXTRA_LIBS"; then
118- PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
119- conf = distutils.sysconfig.get_config_var; \
120- print conf('LOCALMODLIBS'), conf('LIBS')"`
121+ PYTHON_EXTRA_LIBS=`$PYTHON -c "import sys; import distutils.sysconfig; \
122+conf = distutils.sysconfig.get_config_var; \
123+sys.stdout.write('%s %s\n' % (conf('LOCALMODLIBS'), conf('LIBS')))"`
124 fi
125 AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
126 AC_SUBST(PYTHON_EXTRA_LIBS)
127@@ -145,9 +143,9 @@
128 #
129 AC_MSG_CHECKING(python extra linking flags)
130 if test -z "$PYTHON_EXTRA_LDFLAGS"; then
131- PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
132- conf = distutils.sysconfig.get_config_var; \
133- print conf('LINKFORSHARED')"`
134+ PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import sys; import distutils.sysconfig; \
135+conf = distutils.sysconfig.get_config_var; \
136+sys.stdout.write('%s\n' % conf('LINKFORSHARED'))"`
137 fi
138 AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
139 AC_SUBST(PYTHON_EXTRA_LDFLAGS)
140
141=== modified file 'utils/Makefile'
142--- utils/Makefile 2012-05-08 05:37:48 +0000
143+++ utils/Makefile 2012-06-12 13:52:18 +0000
144@@ -65,7 +65,7 @@
145 $(MAKE) install_manpages DESTDIR=${DESTDIR}
146 $(MAKE) -C vim install DESTDIR=${DESTDIR}
147 ln -sf aa-status.8 ${DESTDIR}/${MANDIR}/man8/apparmor_status.8
148- python ${PYSETUP} install --prefix=${PYPREFIX} --root=${DESTDIR} --version=${VERSION}
149+ ${PYTHON} ${PYSETUP} install --prefix=${PYPREFIX} --root=${DESTDIR} --version=${VERSION}
150
151 .PHONY: clean
152 ifndef VERBOSE
153@@ -105,6 +105,4 @@
154 test -s $$tmpfile && cat $$tmpfile && rm -f $$tmpfile && exit 1; \
155 done || true; \
156 rm -f $$tmpfile
157- for i in test/* ; do \
158- python $$i || exit 1; \
159- done
160+ $(foreach test, $(wildcard test/test-*.py), $(call pyalldo, $(test)))
161
162=== modified file 'utils/aa-easyprof'
163--- utils/aa-easyprof 2012-05-09 18:05:07 +0000
164+++ utils/aa-easyprof 2012-06-12 13:52:18 +0000
165@@ -35,7 +35,7 @@
166
167 try:
168 easyp = apparmor.easyprof.AppArmorEasyProfile(binary, opt)
169- except AppArmorException, e:
170+ except AppArmorException as e:
171 error(e.value)
172 except Exception:
173 raise
174@@ -61,5 +61,5 @@
175 # if we made it here, generate a profile
176 params = apparmor.easyprof.gen_policy_params(binary, opt)
177 p = easyp.gen_policy(**params)
178- print p,
179+ sys.stdout.write('%s\n' % p)
180
181
182=== modified file 'utils/apparmor/easyprof.py'
183--- utils/apparmor/easyprof.py 2012-05-08 05:37:48 +0000
184+++ utils/apparmor/easyprof.py 2012-06-12 13:52:18 +0000
185@@ -8,6 +8,8 @@
186 #
187 # ------------------------------------------------------------------
188
189+from __future__ import with_statement
190+
191 import codecs
192 import glob
193 import optparse
194@@ -40,7 +42,7 @@
195 def error(out, exit_code=1, do_exit=True):
196 '''Print error message and exit'''
197 try:
198- print >> sys.stderr, "ERROR: %s" % (out)
199+ sys.stderr.write("ERROR: %s\n" % (out))
200 except IOError:
201 pass
202
203@@ -51,7 +53,7 @@
204 def warn(out):
205 '''Print warning message'''
206 try:
207- print >> sys.stderr, "WARN: %s" % (out)
208+ sys.stderr.write("WARN: %s\n" % (out))
209 except IOError:
210 pass
211
212@@ -59,7 +61,7 @@
213 def msg(out, output=sys.stdout):
214 '''Print message'''
215 try:
216- print >> output, "%s" % (out)
217+ sys.stdout.write("%s\n" % (out))
218 except IOError:
219 pass
220
221@@ -70,7 +72,7 @@
222 try:
223 sp = subprocess.Popen(command, stdout=subprocess.PIPE,
224 stderr=subprocess.STDOUT)
225- except OSError, ex:
226+ except OSError as ex:
227 return [127, str(ex)]
228
229 out = sp.communicate()[0]
230@@ -82,7 +84,7 @@
231 try:
232 sp1 = subprocess.Popen(command1, stdout=subprocess.PIPE)
233 sp2 = subprocess.Popen(command2, stdin=sp1.stdout)
234- except OSError, ex:
235+ except OSError as ex:
236 return [127, str(ex)]
237
238 out = sp2.communicate()[0]
239@@ -93,7 +95,7 @@
240 '''Print debug message'''
241 if DEBUGGING:
242 try:
243- print >> sys.stderr, "DEBUG: %s" % (out)
244+ sys.stderr.write("DEBUG: %s\n" % (out))
245 except IOError:
246 pass
247
248@@ -181,6 +183,8 @@
249 fn = policy
250 else:
251 f, fn = tempfile.mkstemp(prefix='aa-easyprof')
252+ if not isinstance(policy, bytes):
253+ policy = policy.encode('utf-8')
254 os.write(f, policy)
255 os.close(f)
256
257@@ -219,9 +223,9 @@
258 if opt.policy_groups_dir and os.path.isdir(opt.policy_groups_dir):
259 self.dirs['policygroups'] = os.path.abspath(opt.policy_groups_dir)
260
261- if not self.dirs.has_key('templates'):
262+ if not 'templates' in self.dirs:
263 raise AppArmorException("Could not find templates directory")
264- if not self.dirs.has_key('policygroups'):
265+ if not 'policygroups' in self.dirs:
266 raise AppArmorException("Could not find policygroups directory")
267
268 self.aa_topdir = "/etc/apparmor.d"
269@@ -445,11 +449,12 @@
270
271 def print_basefilenames(files):
272 for i in files:
273- print "%s" % (os.path.basename(i))
274+ sys.stdout.write("%s\n" % (os.path.basename(i)))
275
276 def print_files(files):
277 for i in files:
278- print open(i).read()
279+ with open(i) as f:
280+ sys.stdout.write(f.read()+"\n")
281
282 def parse_args(args=None):
283 '''Parse arguments'''
284
285=== modified file 'utils/test/test-aa-easyprof.py'
286--- utils/test/test-aa-easyprof.py 2012-05-09 18:05:07 +0000
287+++ utils/test/test-aa-easyprof.py 2012-06-12 13:52:18 +0000
288@@ -101,6 +101,7 @@
289 def tearDown(self):
290 '''Teardown for tests'''
291 if os.path.exists(self.tmpdir):
292+ sys.stdout.write("%s\n" % self.tmpdir)
293 recursive_rm(self.tmpdir)
294
295 #
296@@ -328,7 +329,7 @@
297 def test_binary_symlink(self):
298 '''Test binary (symlink)'''
299 exe = os.path.join(self.tmpdir, 'exe')
300- open(exe, 'wa').close()
301+ open(exe, 'a').close()
302 symlink = exe + ".lnk"
303 os.symlink(exe, symlink)
304
305@@ -441,7 +442,7 @@
306 self.assertFalse(inv_s in p, "Found '%s' in :\n%s" % (inv_s, p))
307
308 if debugging:
309- print p
310+ sys.stdout.write("%s\n" % p)
311
312 return p
313
314@@ -859,7 +860,7 @@
315 # Create the necessary files to import aa-easyprof
316 init = os.path.join(os.path.dirname(absfn), '__init__.py')
317 if not os.path.exists(init):
318- open(init, 'wa').close()
319+ open(init, 'a').close()
320 created.append(init)
321
322 symlink = os.path.join(os.path.dirname(absfn), 'easyprof.py')
323
324=== modified file 'utils/vim/Makefile'
325--- utils/vim/Makefile 2012-03-23 16:02:20 +0000
326+++ utils/vim/Makefile 2012-06-12 13:52:18 +0000
327@@ -14,12 +14,15 @@
328 all: apparmor.vim
329
330 apparmor.vim: apparmor.vim.in Makefile create-apparmor.vim.py
331- python create-apparmor.vim.py > $@
332+ ${PYTHON} create-apparmor.vim.py > apparmor.vim
333
334 install: apparmor.vim
335 install -d $(VIM_INSTALL_PATH)
336 install -m 644 $< $(VIM_INSTALL_PATH)
337
338+test: apparmor.vim.in Makefile create-apparmor.vim.py
339+ #Testing with all pythons
340+ $(call pyalldo, create-apparmor.vim.py > /dev/null)
341
342 clean:
343 rm -f apparmor.vim common
344
345=== modified file 'utils/vim/create-apparmor.vim.py'
346--- utils/vim/create-apparmor.vim.py 2012-06-08 21:30:22 +0000
347+++ utils/vim/create-apparmor.vim.py 2012-06-12 13:52:18 +0000
348@@ -10,7 +10,6 @@
349 # Christian Boltz <apparmor@cboltz.de>
350
351 from __future__ import with_statement
352-import os
353 import re
354 import subprocess
355 import sys
356@@ -30,9 +29,9 @@
357 return a textual error if it failed.'''
358
359 try:
360- sp = subprocess.Popen(command, stdin=stdin, stdout=stdout, stderr=stderr, close_fds=True)
361- except OSError, e:
362- return [127, str(e)]
363+ sp = subprocess.Popen(command, stdin=stdin, stdout=stdout, stderr=stderr, close_fds=True, universal_newlines=True)
364+ except OSError as ex:
365+ return [127, str(ex)]
366
367 out, outerr = sp.communicate(input)
368
369@@ -47,7 +46,7 @@
370 # get capabilities list
371 (rc, output) = cmd(['make', '-s', '--no-print-directory', 'list_capabilities'])
372 if rc != 0:
373- print >>sys.stderr, ("make list_capabilities failed: " + output)
374+ sys.stderr.write("make list_capabilities failed: " + output)
375 exit(rc)
376
377 capabilities = re.sub('CAP_', '', output.strip()).lower().split(" ")
378@@ -59,7 +58,7 @@
379 # get network protos list
380 (rc, output) = cmd(['make', '-s', '--no-print-directory', 'list_af_names'])
381 if rc != 0:
382- print >>sys.stderr, ("make list_af_names failed: " + output)
383+ sys.stderr.write("make list_af_names failed: " + output)
384 exit(rc)
385
386 af_names = []
387@@ -106,7 +105,7 @@
388 }
389
390 def my_repl(matchobj):
391- #print matchobj.group(1)
392+ matchobj.group(1)
393 if matchobj.group(1) in aa_regex_map:
394 return aa_regex_map[matchobj.group(1)]
395
396@@ -164,16 +163,16 @@
397
398 regex = "@@(" + "|".join(aa_regex_map) + ")@@"
399
400-print '" generated from apparmor.vim.in by create-apparmor.vim.py'
401-print '" do not edit this file - edit apparmor.vim.in or create-apparmor.vim.py instead' + "\n"
402+sys.stdout.write('" generated from apparmor.vim.in by create-apparmor.vim.py\n')
403+sys.stdout.write('" do not edit this file - edit apparmor.vim.in or create-apparmor.vim.py instead' + "\n\n")
404
405-with file("apparmor.vim.in") as template:
406+with open("apparmor.vim.in") as template:
407 for line in template:
408 line = re.sub(regex, my_repl, line.rstrip())
409- print line
410-
411-print "\n\n\n"
412-
413-print '" file rules added with create_file_rule()'
414-print re.sub(regex, my_repl, filerule)
415+ sys.stdout.write('%s\n' % line)
416+
417+sys.stdout.write("\n\n\n\n")
418+
419+sys.stdout.write('" file rules added with create_file_rule()\n')
420+sys.stdout.write(re.sub(regex, my_repl, filerule)+'\n')
421

Subscribers

People subscribed via source and target branches