[apparmor] [Merge] lp:~dmitrij.ledkov/apparmor/py3 into lp:apparmor
barry at canonical.com
Mon Jun 11 20:34:22 UTC 2012
On Jun 11, 2012, at 05:04 PM, Dmitrijs Ledkovs wrote:
>Dmitrijs Ledkovs has proposed merging lp:~dmitrij.ledkov/apparmor/py3 into lp:apparmor.
> Canonical Foundations Team (canonical-foundations)
> AppArmor Developers (apparmor-dev)
>For more details, see:
>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 @@
> sp = subprocess.Popen(command, stdout=subprocess.PIPE,
> - except OSError, ex:
> + except OSError:
> + ex = sys.exc_info()
> return [127, str(ex)]
I think in general, a better way of doing this would be to change the except
except OSError as ex:
> @@ -181,7 +183,8 @@
> fn = policy
> 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)
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.
Your team AppArmor Developers is requested to review the proposed merge of lp:~dmitrij.ledkov/apparmor/py3 into lp:apparmor.
More information about the AppArmor