Hello, I'd like to propose the python3 compability changes from trunk r2052 to the 2.8 branch.
Most of trunk r2052 also applies to the 2.8 branch. The only difference is one part for utils/vim/create-apparmor.vim.py: Trunk r2052 has: create-apparmor.vim.py @@ -164,16 +163,16 @@ regex = "@@(" + "|".join(aa_regex_map) + ")@@" -print '" generated from apparmor.vim.in by create-apparmor.vim.py' -print '" do not edit this file - edit apparmor.vim.in or create-apparmor.vim.py instead' + "\n" +sys.stdout.write('" generated from apparmor.vim.in by create-apparmor.vim.py\n') +sys.stdout.write('" do not edit this file - edit apparmor.vim.in or create-apparmor.vim.py instead' + "\n\n") -with file("apparmor.vim.in") as template: +with open("apparmor.vim.in") as template: for line in template: line = re.sub(regex, my_repl, line.rstrip()) - print line - -print "\n\n\n" - -print '" file rules added with create_file_rule()' -print re.sub(regex, my_repl, filerule) + sys.stdout.write('%s\n' % line) + +sys.stdout.write("\n\n\n\n") + +sys.stdout.write('" file rules added with create_file_rule()\n') +sys.stdout.write(re.sub(regex, my_repl, filerule)+'\n') The patch I'm proposing just has create-apparmor.vim.py @@ -113,7 +112,8 @@ def my_repl(matchobj): regex = "@@(" + "|".join(aa_regex_map) + ")@@" -with file("apparmor.vim.in") as template: +with open("apparmor.vim.in") as template: for line in template: line = re.sub(regex, my_repl, line.rstrip()) - print line + sys.stdout.write('%s\n' % line) +# print line See the attachment for the full patch. Regards, Christian Boltz -- the issue has been fixed and everybody moved on to breaking other stuff :) [Dominique Leuenberger in opensuse-factory]
=== modified file 'common/Make.rules' Index: common/Make.rules =================================================================== --- common/Make.rules.orig 2012-06-30 01:42:39.000000000 +0200 +++ common/Make.rules 2013-05-05 18:13:56.759020320 +0200 @@ -32,6 +32,10 @@ ifndef AWK $(error awk utility required for build but not available) endif +# Convenience functions +pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH))))) +map = $(foreach a,$(2),$(call $(1),$(a))) + # OVERRIDABLE variables # Set these variables before including Make.rules to change its behavior # SPECFILE - for packages that have a non-standard specfile name @@ -132,6 +136,17 @@ endif endif +ifndef PYTHON_VERSIONS +PYTHON_VERSIONS = $(call map, pathsearch, python2 python3) +endif + +ifndef PYTHON +PYTHON = $(firstword ${PYTHON_VERSIONS}) +endif + +#Helper function to be used with $(call pyalldo, run_test_with_all.py) +pyalldo=set -e; $(foreach py, $(PYTHON_VERSIONS), $(py) $(1);) + .PHONY: version .SILENT: version version: Index: libraries/libapparmor/m4/ac_python_devel.m4 =================================================================== --- libraries/libapparmor/m4/ac_python_devel.m4.orig 2012-04-25 21:15:19.000000000 +0200 +++ libraries/libapparmor/m4/ac_python_devel.m4 2013-05-05 18:13:56.759020320 +0200 @@ -17,9 +17,9 @@ AC_DEFUN([AC_PYTHON_DEVEL],[ # Check for a version of Python >= 2.1.0 # AC_MSG_CHECKING([for a version of Python >= '2.1.0']) - ac_supports_python_ver=`$PYTHON -c "import sys, string; \ - ver = string.split(sys.version)[[0]]; \ - print ver >= '2.1.0'"` + ac_supports_python_ver=`$PYTHON -c "import sys; \ + ver = sys.version.split()[[0]]; \ + sys.stdout.write(str(ver >= '2.1.0'))"` if test "$ac_supports_python_ver" != "True"; then if test -z "$PYTHON_NOVERSIONCHECK"; then AC_MSG_RESULT([no]) @@ -44,9 +44,9 @@ to something else than an empty string. # if test -n "$1"; then AC_MSG_CHECKING([for a version of Python $1]) - ac_supports_python_ver=`$PYTHON -c "import sys, string; \ - ver = string.split(sys.version)[[0]]; \ - print ver $1"` + ac_supports_python_ver=`$PYTHON -c "import sys; \ + ver = sys.version.split()[[0]]; \ + sys.stdout.write("%s\n" % (ver == $1))"` if test "$ac_supports_python_ver" = "True"; then AC_MSG_RESULT([yes]) else @@ -80,8 +80,8 @@ $ac_distutils_result]) # AC_MSG_CHECKING([for Python include path]) if test -z "$PYTHON_CPPFLAGS"; then - python_path=`$PYTHON -c "import distutils.sysconfig; \ - print distutils.sysconfig.get_python_inc();"` + python_path=`$PYTHON -c "import sys; import distutils.sysconfig;\ +sys.stdout.write('%s\n' % distutils.sysconfig.get_python_inc());"` if test -n "${python_path}"; then python_path="-I$python_path" fi @@ -97,22 +97,20 @@ $ac_distutils_result]) if test -z "$PYTHON_LDFLAGS"; then # (makes two attempts to ensure we've got a version number # from the interpreter) - py_version=`$PYTHON -c "from distutils.sysconfig import *; \ - from string import join; \ - print join(get_config_vars('VERSION'))"` + py_version=`$PYTHON -c "import sys; from distutils.sysconfig import *; \ +sys.stdout.write('%s\n' % ''.join(get_config_vars('VERSION')))"` if test "$py_version" == "[None]"; then if test -n "$PYTHON_VERSION"; then py_version=$PYTHON_VERSION else py_version=`$PYTHON -c "import sys; \ - print sys.version[[:3]]"` +sys.stdout.write("%s\n" % sys.version[[:3]])"` fi fi - PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \ - from string import join; \ - print '-L' + get_python_lib(0,1), \ - '-lpython';"`$py_version + PYTHON_LDFLAGS=`$PYTHON -c "import sys; from distutils.sysconfig import *; \ +sys.stdout.write('-L' + get_python_lib(0,1) + ' -lpython\n')"`$py_version`$PYTHON -c \ +"import sys; sys.stdout.write('%s' % getattr(sys,'abiflags',''))"` fi AC_MSG_RESULT([$PYTHON_LDFLAGS]) AC_SUBST([PYTHON_LDFLAGS]) @@ -122,8 +120,8 @@ $ac_distutils_result]) # AC_MSG_CHECKING([for Python site-packages path]) if test -z "$PYTHON_SITE_PKG"; then - PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \ - print distutils.sysconfig.get_python_lib(0,0);"` + PYTHON_SITE_PKG=`$PYTHON -c "import sys; import distutils.sysconfig; \ +sys.stdout.write('%s\n' % distutils.sysconfig.get_python_lib(0,0));"` fi AC_MSG_RESULT([$PYTHON_SITE_PKG]) AC_SUBST([PYTHON_SITE_PKG]) @@ -133,9 +131,9 @@ $ac_distutils_result]) # AC_MSG_CHECKING(python extra libraries) if test -z "$PYTHON_EXTRA_LIBS"; then - PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \ - conf = distutils.sysconfig.get_config_var; \ - print conf('LOCALMODLIBS'), conf('LIBS')"` + PYTHON_EXTRA_LIBS=`$PYTHON -c "import sys; import distutils.sysconfig; \ +conf = distutils.sysconfig.get_config_var; \ +sys.stdout.write('%s %s\n' % (conf('LOCALMODLIBS'), conf('LIBS')))"` fi AC_MSG_RESULT([$PYTHON_EXTRA_LIBS]) AC_SUBST(PYTHON_EXTRA_LIBS) @@ -145,9 +143,9 @@ $ac_distutils_result]) # AC_MSG_CHECKING(python extra linking flags) if test -z "$PYTHON_EXTRA_LDFLAGS"; then - PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \ - conf = distutils.sysconfig.get_config_var; \ - print conf('LINKFORSHARED')"` + PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import sys; import distutils.sysconfig; \ +conf = distutils.sysconfig.get_config_var; \ +sys.stdout.write('%s\n' % conf('LINKFORSHARED'))"` fi AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS]) AC_SUBST(PYTHON_EXTRA_LDFLAGS) Index: utils/Makefile =================================================================== --- utils/Makefile.orig 2012-05-08 07:37:48.000000000 +0200 +++ utils/Makefile 2013-05-05 18:13:56.760020260 +0200 @@ -65,7 +65,7 @@ install: ${MANPAGES} ${HTMLMANPAGES} $(MAKE) install_manpages DESTDIR=${DESTDIR} $(MAKE) -C vim install DESTDIR=${DESTDIR} ln -sf aa-status.8 ${DESTDIR}/${MANDIR}/man8/apparmor_status.8 - python ${PYSETUP} install --prefix=${PYPREFIX} --root=${DESTDIR} --version=${VERSION} + ${PYTHON} ${PYSETUP} install --prefix=${PYPREFIX} --root=${DESTDIR} --version=${VERSION} .PHONY: clean ifndef VERBOSE @@ -105,6 +105,4 @@ check: check_severity_db test -s $$tmpfile && cat $$tmpfile && rm -f $$tmpfile && exit 1; \ done || true; \ rm -f $$tmpfile - for i in test/* ; do \ - python $$i || exit 1; \ - done + $(foreach test, $(wildcard test/test-*.py), $(call pyalldo, $(test))) Index: utils/aa-easyprof =================================================================== --- utils/aa-easyprof.orig 2012-05-09 20:05:07.000000000 +0200 +++ utils/aa-easyprof 2013-05-05 18:13:56.760020260 +0200 @@ -35,7 +35,7 @@ if __name__ == "__main__": try: easyp = apparmor.easyprof.AppArmorEasyProfile(binary, opt) - except AppArmorException, e: + except AppArmorException as e: error(e.value) except Exception: raise @@ -61,5 +61,5 @@ if __name__ == "__main__": # if we made it here, generate a profile params = apparmor.easyprof.gen_policy_params(binary, opt) p = easyp.gen_policy(**params) - print p, + sys.stdout.write('%s\n' % p) Index: utils/apparmor/easyprof.py =================================================================== --- utils/apparmor/easyprof.py.orig 2012-05-08 07:37:48.000000000 +0200 +++ utils/apparmor/easyprof.py 2013-05-05 18:13:56.760020260 +0200 @@ -8,6 +8,8 @@ # # ------------------------------------------------------------------ +from __future__ import with_statement + import codecs import glob import optparse @@ -40,7 +42,7 @@ DEBUGGING = False def error(out, exit_code=1, do_exit=True): '''Print error message and exit''' try: - print >> sys.stderr, "ERROR: %s" % (out) + sys.stderr.write("ERROR: %s\n" % (out)) except IOError: pass @@ -51,7 +53,7 @@ def error(out, exit_code=1, do_exit=True def warn(out): '''Print warning message''' try: - print >> sys.stderr, "WARN: %s" % (out) + sys.stderr.write("WARN: %s\n" % (out)) except IOError: pass @@ -59,7 +61,7 @@ def warn(out): def msg(out, output=sys.stdout): '''Print message''' try: - print >> output, "%s" % (out) + sys.stdout.write("%s\n" % (out)) except IOError: pass @@ -70,7 +72,7 @@ def cmd(command): try: sp = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - except OSError, ex: + except OSError as ex: return [127, str(ex)] out = sp.communicate()[0] @@ -82,7 +84,7 @@ def cmd_pipe(command1, command2): try: sp1 = subprocess.Popen(command1, stdout=subprocess.PIPE) sp2 = subprocess.Popen(command2, stdin=sp1.stdout) - except OSError, ex: + except OSError as ex: return [127, str(ex)] out = sp2.communicate()[0] @@ -93,7 +95,7 @@ def debug(out): '''Print debug message''' if DEBUGGING: try: - print >> sys.stderr, "DEBUG: %s" % (out) + sys.stderr.write("DEBUG: %s\n" % (out)) except IOError: pass @@ -181,6 +183,8 @@ def verify_policy(policy): fn = policy else: f, fn = tempfile.mkstemp(prefix='aa-easyprof') + if not isinstance(policy, bytes): + policy = policy.encode('utf-8') os.write(f, policy) os.close(f) @@ -219,9 +223,9 @@ class AppArmorEasyProfile: if opt.policy_groups_dir and os.path.isdir(opt.policy_groups_dir): self.dirs['policygroups'] = os.path.abspath(opt.policy_groups_dir) - if not self.dirs.has_key('templates'): + if not 'templates' in self.dirs: raise AppArmorException("Could not find templates directory") - if not self.dirs.has_key('policygroups'): + if not 'policygroups' in self.dirs: raise AppArmorException("Could not find policygroups directory") self.aa_topdir = "/etc/apparmor.d" @@ -445,11 +449,12 @@ class AppArmorEasyProfile: def print_basefilenames(files): for i in files: - print "%s" % (os.path.basename(i)) + sys.stdout.write("%s\n" % (os.path.basename(i))) def print_files(files): for i in files: - print open(i).read() + with open(i) as f: + sys.stdout.write(f.read()+"\n") def parse_args(args=None): '''Parse arguments''' Index: utils/test/test-aa-easyprof.py =================================================================== --- utils/test/test-aa-easyprof.py.orig 2012-05-09 20:05:07.000000000 +0200 +++ utils/test/test-aa-easyprof.py 2013-05-05 18:13:56.761020200 +0200 @@ -101,6 +101,7 @@ TEMPLATES_DIR="%s/templates" def tearDown(self): '''Teardown for tests''' if os.path.exists(self.tmpdir): + sys.stdout.write("%s\n" % self.tmpdir) recursive_rm(self.tmpdir) # @@ -328,7 +329,7 @@ POLICYGROUPS_DIR="%s/templates" def test_binary_symlink(self): '''Test binary (symlink)''' exe = os.path.join(self.tmpdir, 'exe') - open(exe, 'wa').close() + open(exe, 'a').close() symlink = exe + ".lnk" os.symlink(exe, symlink) @@ -441,7 +442,7 @@ POLICYGROUPS_DIR="%s/templates" self.assertFalse(inv_s in p, "Found '%s' in :\n%s" % (inv_s, p)) if debugging: - print p + sys.stdout.write("%s\n" % p) return p @@ -859,7 +860,7 @@ if __name__ == '__main__': # Create the necessary files to import aa-easyprof init = os.path.join(os.path.dirname(absfn), '__init__.py') if not os.path.exists(init): - open(init, 'wa').close() + open(init, 'a').close() created.append(init) symlink = os.path.join(os.path.dirname(absfn), 'easyprof.py') Index: utils/vim/Makefile =================================================================== --- utils/vim/Makefile.orig 2012-03-23 17:02:20.000000000 +0100 +++ utils/vim/Makefile 2013-05-05 18:13:56.761020200 +0200 @@ -14,12 +14,15 @@ VIM_INSTALL_PATH=${DESTDIR}/usr/share/ap all: apparmor.vim apparmor.vim: apparmor.vim.in Makefile create-apparmor.vim.py - python create-apparmor.vim.py > $@ + ${PYTHON} create-apparmor.vim.py > apparmor.vim install: apparmor.vim install -d $(VIM_INSTALL_PATH) install -m 644 $< $(VIM_INSTALL_PATH) +test: apparmor.vim.in Makefile create-apparmor.vim.py + #Testing with all pythons + $(call pyalldo, create-apparmor.vim.py > /dev/null) clean: rm -f apparmor.vim common Index: utils/vim/create-apparmor.vim.py =================================================================== --- utils/vim/create-apparmor.vim.py.orig 2012-06-08 23:27:05.000000000 +0200 +++ utils/vim/create-apparmor.vim.py 2013-05-05 18:14:14.989926123 +0200 @@ -10,7 +10,6 @@ # Christian Boltz <appar...@cboltz.de> from __future__ import with_statement -import os import re import subprocess import sys @@ -30,9 +29,9 @@ def cmd(command, input = None, stderr = return a textual error if it failed.''' try: - sp = subprocess.Popen(command, stdin=stdin, stdout=stdout, stderr=stderr, close_fds=True) - except OSError, e: - return [127, str(e)] + sp = subprocess.Popen(command, stdin=stdin, stdout=stdout, stderr=stderr, close_fds=True, universal_newlines=True) + except OSError as ex: + return [127, str(ex)] out, outerr = sp.communicate(input) @@ -47,7 +46,7 @@ def cmd(command, input = None, stderr = # get capabilities list (rc, output) = cmd(['make', '-s', '--no-print-directory', 'list_capabilities']) if rc != 0: - print >>sys.stderr, ("make list_capabilities failed: " + output) + sys.stderr.write("make list_capabilities failed: " + output) exit(rc) capabilities = re.sub('CAP_', '', output.strip()).lower().split(" ") @@ -59,7 +58,7 @@ for cap in capabilities: # get network protos list (rc, output) = cmd(['make', '-s', '--no-print-directory', 'list_af_names']) if rc != 0: - print >>sys.stderr, ("make list_af_names failed: " + output) + sys.stderr.write("make list_af_names failed: " + output) exit(rc) af_names = [] @@ -105,7 +104,7 @@ aa_regex_map = { } def my_repl(matchobj): - #print matchobj.group(1) + matchobj.group(1) if matchobj.group(1) in aa_regex_map: return aa_regex_map[matchobj.group(1)] @@ -113,7 +112,8 @@ def my_repl(matchobj): regex = "@@(" + "|".join(aa_regex_map) + ")@@" -with file("apparmor.vim.in") as template: +with open("apparmor.vim.in") as template: for line in template: line = re.sub(regex, my_repl, line.rstrip()) - print line + sys.stdout.write('%s\n' % line) +# print line
-- AppArmor mailing list AppArmor@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor