[elbe-devel] [PATCH 18/25] py3: use print("x") function instead of print "x"
Torben Hohn
torben.hohn at linutronix.de
Mon Dec 18 10:08:27 CET 2017
On Mon, Dec 11, 2017 at 10:11:12AM +0100, Manuel Traut wrote:
> print is a function in python3 and a statement in python2.
> Convert the code to use the print function.
>
> To be python2 compatible a __future__ import is used.
>
> Signed-off-by: Manuel Traut <manut at linutronix.de>
> try:
> xml = ElbeXML ( args[0] )
> except Exception as e:
> - print "Error reading xml file: %s" % str(e)
> + print(("Error reading xml file: %s" % str(e)))
why 2 (( ?
> sys.exit(20)
>
> for a in args[1:]:
> try:
> xml.add_target_package( a )
> except Exception as e:
> - print "Error adding package %s: %s" % (a, str(e))
> + print(("Error adding package %s: %s" % (a, str(e))))
why 2 (( ?
> try:
> project = ElbeProject( opt.target, args[0], opt.output, opt.name,
> opt.buildtype, opt.skip_validation )
> except ValidationError as e:
> - print str(e)
> - print "xml validation failed. Bailing out"
> + print((str(e)))
why 2 (( ?
> + print("xml validation failed. Bailing out")
> sys.exit(20)
>
> try:
> @@ -109,12 +111,12 @@ def run_command( argv ):
> opt.build_sources, opt.cdrom_size, opt.debug, opt.skip_pkglist,
> opt.skip_pbuild )
> except CommandError as ce:
> - print "command in project build failed:", ce.cmd
> + print(("command in project build failed: %s" % ce.cmd))
why 2 (( ?
> @@ -53,16 +55,16 @@ def run_command( argv ):
> if str(o) == str(d):
> if getattr(opt,o) == True:
> active = True
> - print "enable", str(d)
> + print(("enable %s" % str(d)))
why 2 (( ?
> module = "elbepack.daemons." + str(d)
> mod = __import__(module)
> cmdmod = sys.modules[module]
> cherrypy.tree.graft(cmdmod.get_app(cherrypy.engine), "/"+str(d))
> if not active:
> - print 'no daemon activated, use'
> + print("no daemon activated, use")
> for d in daemons:
> - print ' --'+d
> - print 'to activate at least one daemon'
> + print((" --%s" % d))
why 2 (( ?
>
> - print "statistics:"
> - print 'num:%d mr:%d hr:%d err_pkg:%d' % (num_pkg, mr, hr, err_pkg)
> + print("statistics:")
> + print(("num:%d mr:%d hr:%d err_pkg:%d" % (num_pkg, mr, hr, err_pkg)))
why 2 (( ?
>
>
>
> diff --git a/elbepack/commands/pin_versions.py b/elbepack/commands/pin_versions.py
> index 2b4b83b6..f8a28ca8 100644
> --- a/elbepack/commands/pin_versions.py
> +++ b/elbepack/commands/pin_versions.py
> @@ -18,6 +18,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> import sys
>
> from elbepack.treeutils import etree
> @@ -35,26 +37,26 @@ def run_command( argv ):
> (opt,args) = oparser.parse_args(argv)
>
> if len(args) != 1:
> - print "Wrong number of arguments"
> + print("Wrong number of arguments")
> oparser.print_help()
> sys.exit(20)
>
> if not opt.skip_validation:
> validation = validate_xml (args[0])
> if len (validation) != 0:
> - print "xml validation failed. Bailing out"
> + print("xml validation failed. Bailing out")
> for i in validation:
> - print i
> + print(i)
> sys.exit(20)
>
> try:
> xml = etree( args[0] )
> except:
> - print "Error reading xml file!"
> + print("Error reading xml file!")
> sys.exit(20)
>
> if not xml.has ("fullpkgs"):
> - print "xml file does not have fullpkgs node"
> + print("xml file does not have fullpkgs node")
> sys.exit(20)
>
> plist = xml.ensure_child("/target/pkg-list")
> @@ -74,6 +76,6 @@ def run_command( argv ):
> try:
> xml.write( args[0] )
> except:
> - print "Unable to write new xml file"
> + print("Unable to write new xml file")
> sys.exit(20)
>
> diff --git a/elbepack/commands/pkgdiff.py b/elbepack/commands/pkgdiff.py
> index 0cc27465..9e05966d 100644
> --- a/elbepack/commands/pkgdiff.py
> +++ b/elbepack/commands/pkgdiff.py
> @@ -16,6 +16,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> import os
> import sys
>
> @@ -34,7 +36,7 @@ def run_command( argv ):
> (opt,args) = oparser.parse_args(argv)
>
> if len(args) != 2:
> - print "Wrong number of arguments"
> + print("Wrong number of arguments")
> oparser.print_help()
> sys.exit(20)
>
> @@ -79,12 +81,12 @@ def run_command( argv ):
>
> for p in list(fix_pkgs.keys()):
> if not p in list(gen_pkgs.keys()):
> - print "+<pkg>%s</pkg>" % p
> + print("+<pkg>%s</pkg>" % p)
>
> for p in list(gen_pkgs.keys()):
> if not p in list(fix_pkgs.keys()):
> - print "-<pkg>%s</pkg>" % p
> + print("-<pkg>%s</pkg>" % p)
>
> for p in list(fix_pkgs.keys()):
> if p in list(gen_pkgs.keys()) and fix_pkgs[p] != gen_pkgs[p]:
> - print "%s: Version mismatch %s != %s" % (p, fix_pkgs[p], gen_pkgs[p])
> + print("%s: Version mismatch %s != %s" % (p, fix_pkgs[p], gen_pkgs[p]))
> diff --git a/elbepack/commands/remove_sign.py b/elbepack/commands/remove_sign.py
> index b2b58eee..4dd06f33 100644
> --- a/elbepack/commands/remove_sign.py
> +++ b/elbepack/commands/remove_sign.py
> @@ -20,16 +20,18 @@
> # with has to have ultimate trust level, otherwise you'll only get
> # VALID (Untrusted)!
>
> +from __future__ import print_function
> +
> from elbepack.gpg import unsign_file
>
> def run_command( argv ):
> if(len(argv) != 1):
> - print 'Wrong number of arguments.'
> - print 'Please pass the name of the file to unsign.'
> + print("Wrong number of arguments.")
> + print("Please pass the name of the file to unsign.")
> return
>
> fname = unsign_file( argv[0] )
> if fname:
> - print "unsigned file:", fname
> + print("unsigned file: %s" % fname)
> else:
> - print "removing signature failed"
> + print("removing signature failed")
> diff --git a/elbepack/commands/setsel.py b/elbepack/commands/setsel.py
> index 799116db..26f17507 100644
> --- a/elbepack/commands/setsel.py
> +++ b/elbepack/commands/setsel.py
> @@ -18,8 +18,9 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> -import sys
> +from __future__ import print_function
>
> +import sys
>
> from elbepack.treeutils import etree
> from optparse import OptionParser
> @@ -38,12 +39,12 @@ def parse_selections( fname ):
> sp = l.split()
>
>
> - print sp[0], sp[1]
> + print("%s %s" % (sp[0], sp[1]))
>
> if sp[1] == 'install':
> sels.append(sp[0])
>
> - print sels
> + print(sels)
> return sels
>
>
> @@ -53,7 +54,7 @@ def run_command( argv ):
> (opt,args) = oparser.parse_args(argv)
>
> if len(args) != 2:
> - print "Wrong number of arguments"
> + print("Wrong number of arguments")
> oparser.print_help()
> sys.exit(20)
>
> diff --git a/elbepack/commands/show.py b/elbepack/commands/show.py
> index 1a02155b..00df63ff 100644
> --- a/elbepack/commands/show.py
> +++ b/elbepack/commands/show.py
> @@ -18,6 +18,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> import sys
>
> from elbepack.treeutils import etree
> @@ -39,12 +41,12 @@ def run_command( argv ):
> (opt,args) = oparser.parse_args(argv)
>
> if len(args) == 0:
> - print "No Filename specified"
> + print("No Filename specified")
> oparser.print_help()
> sys.exit(20)
>
> if len(args) > 1:
> - print "too many filenames specified"
> + print("too many filenames specified")
> oparser.print_help()
> sys.exit(20)
>
> @@ -52,39 +54,39 @@ def run_command( argv ):
> if not opt.skip_validation:
> validation = validate_xml (args[0])
> if len (validation) != 0:
> - print "xml validation failed. Bailing out"
> + print("xml validation failed. Bailing out")
> for i in validation:
> - print i
> + print(i)
> sys.exit(20)
>
> xml = etree( args[0] )
> except:
> - print "Unable to open xml File. Bailing out"
> + print("Unable to open xml File. Bailing out")
> sys.exit(20)
>
> if not xml.has("./project"):
> - print "no project description available"
> + print("no project description available")
> sys.exit(20)
>
> - print '== %s ==' %(args[0])
> - print 'Debian suite: %s' % (xml.text("./project/suite"))
> + print("== %s ==" %(args[0]))
> + print("Debian suite: %s" % (xml.text("./project/suite")))
> for s in xml.text("./project/description").splitlines():
> - print '%s' % s.strip()
> + print("%s" % s.strip())
> if opt.verbose:
> - print 'root password: %s' % xml.text("./target/passwd")
> - print 'primary_mirror: %s://%s%s' %(
> + print("root password: %s" % xml.text("./target/passwd"))
> + print("primary_mirror: %s://%s%s" % (
> xml.text("./project/mirror/primary_proto"),
> xml.text("./project/mirror/primary_host"),
> - xml.text("./project/mirror/primary_path"))
> + xml.text("./project/mirror/primary_path")))
> if xml.has("./project/mirror/url-list"):
> - print 'additional mirrors:'
> + print("additional mirrors:")
> for url in xml.node("./project/mirror/url-list"):
> if url.has("binary"):
> - print ' deb %s' % url.text("binary").strip()
> + print(" deb %s" % url.text("binary").strip())
> if url.has("source"):
> - print ' deb-src %s' % url.text("source").strip()
> - print 'packages:'
> + print(" deb-src %s" % url.text("source").strip())
> + print("packages:")
> for pkg in xml.node("./target/pkg-list"):
> - print ' %s' % pkg.et.text
> - print 'skip package validation: %s' % xml.has("./project/noauth")
> - print 'archive embedded? %s' % xml.has("./archive")
> + print(" %s" % pkg.et.text)
> + print("skip package validation: %s" % xml.has("./project/noauth"))
> + print("archive embedded? %s" % xml.has("./archive"))
> diff --git a/elbepack/commands/sign.py b/elbepack/commands/sign.py
> index b87c9849..4047352b 100644
> --- a/elbepack/commands/sign.py
> +++ b/elbepack/commands/sign.py
> @@ -16,12 +16,14 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> from elbepack.gpg import sign_file
>
> def run_command( argv ):
> if(len(argv) != 2):
> - print 'Wrong number of arguments.'
> - print 'Please pass the name of the file to sign and a valid gnupg fingerprint.'
> + print("Wrong number of arguments.")
> + print("Please pass the name of the file to sign and a valid gnupg fingerprint.")
> return
> else:
> sign_file( argv[0], argv[1])
> diff --git a/elbepack/commands/validate.py b/elbepack/commands/validate.py
> index 340eb506..9ab37f44 100644
> --- a/elbepack/commands/validate.py
> +++ b/elbepack/commands/validate.py
> @@ -16,6 +16,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> import sys
> import os
> from optparse import OptionParser
> @@ -41,16 +43,16 @@ def run_command( argv ):
>
> validation = validate_xml (args[0])
> if len (validation):
> - print "validation failed"
> + print("validation failed")
> for i in validation:
> - print i
> + print(i)
> sys.exit(20)
>
> if opt.validate_urls:
> try:
> xml = ElbeXML(args[0], url_validation=ValidationMode.CHECK_ALL)
> except ValidationError as e:
> - print e
> + print(e)
> sys.exit(20)
>
> sys.exit (0)
> diff --git a/elbepack/commands/xsdtoasciidoc.py b/elbepack/commands/xsdtoasciidoc.py
> index c64e11c4..ec3e172e 100644
> --- a/elbepack/commands/xsdtoasciidoc.py
> +++ b/elbepack/commands/xsdtoasciidoc.py
> @@ -18,6 +18,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> import sys
>
> from elbepack.treeutils import etree
> @@ -36,14 +38,14 @@ def run_command( argv ):
> (opt,args) = oparser.parse_args(argv)
>
> if len(args) != 1:
> - print "Wrong number of arguments"
> + print("Wrong number of arguments")
> oparser.print_help()
> sys.exit(20)
>
> xml = etree( args[0] )
>
> if not opt.out:
> - print 'output is mandatory'
> + print("--output is mandatory")
> sys.exit(20)
>
> d = {"opt": opt,
> diff --git a/elbepack/db.py b/elbepack/db.py
> index fa322a2e..6edfd0a1 100644
> --- a/elbepack/db.py
> +++ b/elbepack/db.py
> @@ -18,6 +18,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> try:
> from urllib.parse import quote
> except ImportError:
> @@ -977,7 +979,7 @@ class ElbeDB(object):
> try:
> os.makedirs (cls.db_path)
> except OSError as e:
> - print e
> + print(str(e))
> return
>
> db = ElbeDB()
> @@ -985,7 +987,7 @@ class ElbeDB(object):
> try:
> db.add_user(name, fullname, password, email, admin)
> except ElbeDBError as e:
> - print e
> + print(str(e))
>
>
> class User(Base):
> diff --git a/elbepack/dbaction.py b/elbepack/dbaction.py
> index 92515c17..52dee742 100644
> --- a/elbepack/dbaction.py
> +++ b/elbepack/dbaction.py
> @@ -18,6 +18,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> import sys
>
> from optparse import OptionParser
> @@ -35,9 +37,9 @@ class DbAction(object):
>
> @classmethod
> def print_actions(cls):
> - print 'available actions are:'
> + print("available actions are:")
> for a in cls.actiondict:
> - print ' ' + a
> + print(" %s" % a)
>
> def __new__(cls, node):
> action = cls.actiondict[node]
> @@ -85,7 +87,7 @@ class AddUserAction(DbAction):
> (opt, arg) = oparser.parse_args (args)
>
> if len(arg) != 1:
> - print "wrong number of arguments"
> + print("wrong number of arguments")
> oparser.print_help()
> return
>
> @@ -115,13 +117,13 @@ class DelUserAction(DbAction):
> (opt, arg) = oparser.parse_args (args)
>
> if len(arg) != 1:
> - print "usage: elbe db del_user <userid>"
> + print("usage: elbe db del_user <userid>")
> return
>
> try:
> userid = int(arg[0])
> except:
> - print "userid must be an integer"
> + print("userid must be an integer")
> return
>
> db = ElbeDB()
> @@ -131,18 +133,18 @@ class DelUserAction(DbAction):
> if projects:
> if not opt.quiet:
> if opt.delete_projects:
> - print "removing projects owned by the deleted user:"
> + print("removing projects owned by the deleted user:")
> else:
> - print "keeping projects owned by the deleted user:"
> + print("keeping projects owned by the deleted user:")
>
> for p in projects:
> if not opt.quiet:
> - print p.builddir + ":", p.name, "[", p.version, "]", p.edit
> + print("%s: %s [%s] %s" % (p.builddir, p.name, p.version, p.edit))
> if opt.delete_projects:
> try:
> db.del_project( p.builddir )
> except ElbeDBError as e:
> - print " ==> ", e
> + print(" ==> %s " % str(e))
>
> DbAction.register(DelUserAction)
>
> @@ -158,7 +160,7 @@ class ListProjectsAction(DbAction):
> projects = db.list_projects ()
>
> for p in projects:
> - print p.builddir+":", p.name, "[", p.version, "]", p.edit
> + print("%s: %s [%s] %s" % (p.builddir, p.name, p.version, p.edit))
>
> DbAction.register(ListProjectsAction)
>
> @@ -174,7 +176,7 @@ class ListUsersAction(DbAction):
> users = db.list_users ()
>
> for u in users:
> - print u.name+":", u.fullname, "<"+u.email+">"
> + print("%s: %s <%s>" % (u.name, u.fullname, u.email))
>
> DbAction.register(ListUsersAction)
>
> @@ -211,7 +213,7 @@ class DeleteProjectAction(DbAction):
>
> def execute(self, args):
> if len (args) != 1:
> - print "usage: elbe db del_project <project_dir>"
> + print("usage: elbe db del_project <project_dir>")
> return
>
> db = ElbeDB()
> @@ -228,7 +230,7 @@ class SetXmlAction(DbAction):
>
> def execute(self, args):
> if len (args) != 2:
> - print "usage: elbe db set_xml <project_dir> <xml>"
> + print("usage: elbe db set_xml <project_dir> <xml>")
> return
>
> db = ElbeDB()
> @@ -246,7 +248,7 @@ class BuildAction(DbAction):
>
> def execute(self, args):
> if len (args) != 1:
> - print "usage: elbe db build <project_dir>"
> + print("usage: elbe db build <project_dir>")
> return
>
> db = ElbeDB()
> @@ -259,7 +261,7 @@ class BuildAction(DbAction):
> except Exception as e:
> db.update_project_files( ep )
> db.reset_busy( args[0], "build_failed" )
> - print e
> + print(str(e))
> return
> db.reset_busy( args[0], "build_done" )
>
> @@ -275,16 +277,16 @@ class GetFilesAction(DbAction):
>
> def execute(self, args):
> if len (args) != 1:
> - print "usage: elbe db get_files <project_dir>"
> + print("usage: elbe db get_files <project_dir>")
> return
>
> db = ElbeDB()
> files = db.get_project_files (args[0])
> for f in files:
> if f.description:
> - print "%-40s %s" % (f.name, f.description)
> + print("%-40s %s" % (f.name, f.description))
> else:
> - print f.name
> + print(f.name)
>
> DbAction.register(GetFilesAction)
>
> @@ -305,7 +307,7 @@ class ResetProjectAction(DbAction):
> (opt, arg) = oparser.parse_args (args)
>
> if len(arg) != 1:
> - print "wrong number of arguments"
> + print("wrong number of arguments")
> oparser.print_help()
> return
>
> @@ -324,7 +326,7 @@ class SetProjectVersionAction(DbAction):
>
> def execute(self, args):
> if len(args) != 2:
> - print "usage: elbe db set_project_version <project_dir> <version>"
> + print("usage: elbe db set_project_version <project_dir> <version>")
> return
>
> db = ElbeDB()
> @@ -342,7 +344,7 @@ class ListVersionsAction(DbAction):
>
> def execute(self, args):
> if len(args) != 1:
> - print "usage: elbe db list_versions <project_dir>"
> + print("usage: elbe db list_versions <project_dir>")
> return
>
> db = ElbeDB()
> @@ -350,9 +352,9 @@ class ListVersionsAction(DbAction):
>
> for v in versions:
> if v.description:
> - print v.version + ": " + v.description
> + print("%s: %s" % (v.version, v.description))
> else:
> - print v.version
> + print(v.version)
>
> DbAction.register(ListVersionsAction)
>
> @@ -371,7 +373,7 @@ class SaveVersionAction(DbAction):
> (opt, arg) = oparser.parse_args (args)
>
> if len(arg) != 1:
> - print "wrong number of arguments"
> + print("wrong number of arguments")
> oparser.print_help()
> return
>
> @@ -390,7 +392,7 @@ class DelVersionAction(DbAction):
>
> def execute(self, args):
> if len(args) != 2:
> - print "usage: elbe db del_version <project_dir> <version>"
> + print("usage: elbe db del_version <project_dir> <version>")
> return
>
> db = ElbeDB()
> @@ -408,7 +410,7 @@ class PrintVersionXMLAction(DbAction):
>
> def execute(self, args):
> if len(args) != 2:
> - print "usage: elbe db print_version_xml <project_dir> <version>"
> + print("usage: elbe db print_version_xml <project_dir> <version>")
> return
>
> db = ElbeDB()
> diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
> index 64bfec81..8166dd32 100644
> --- a/elbepack/finetuning.py
> +++ b/elbepack/finetuning.py
> @@ -16,6 +16,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> import os
> import gpgme
>
> @@ -397,6 +399,6 @@ def do_finetuning(xml, log, buildenv, target):
> action = FinetuningAction( i )
> action.execute(log, buildenv, target)
> except KeyError:
> - print "Unimplemented finetuning action " + i.et.tag
> + print("Unimplemented finetuning action '%s'" % (i.et.tag))
> except CommandError:
> log.printo( "Finetuning Error, trying to continue anyways" )
> diff --git a/elbepack/gpg.py b/elbepack/gpg.py
> index 89b9077f..0ea42be9 100644
> --- a/elbepack/gpg.py
> +++ b/elbepack/gpg.py
> @@ -18,6 +18,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> import gpgme
> import os
>
> @@ -67,46 +69,46 @@ def check_signature(ctx, sig):
> status = OverallStatus()
>
> if sig.summary & gpgme.SIGSUM_KEY_MISSING:
> - print 'Signature with unknown key: %s' % sig.fpr
> + print("Signature with unknown key: %s" % sig.fpr)
> status.key_missing = True
> return status
>
> # there should be a key
> key = ctx.get_key(sig.fpr)
> - print '%s <%s> (%s):' % (key.uids[0].name, key.uids[0].email, sig.fpr),
> + print("%s <%s> (%s):" % (key.uids[0].name, key.uids[0].email, sig.fpr))
> if sig.summary & gpgme.SIGSUM_VALID == gpgme.SIGSUM_VALID:
> # signature fully valid and trusted
> - print 'VALID (Trusted)'
> + print("VALID (Trusted)")
> return status
>
> # print detailed status in case it's not fully valid and trusted
> if sig.summary == 0:
> # Signature is valid, but the key is not ultimately trusted,
> # see: http://www.gossamer-threads.com/lists/gnupg/users/52350
> - print 'VALID (Untrusted).',
> + print("VALID (Untrusted).")
> if sig.summary & gpgme.SIGSUM_SIG_EXPIRED == gpgme.SIGSUM_SIG_EXPIRED:
> - print 'SIGNATURE EXPIRED!',
> + print("SIGNATURE EXPIRED!")
> status.sig_expired = True
> if sig.summary & gpgme.SIGSUM_KEY_EXPIRED == gpgme.SIGSUM_KEY_EXPIRED:
> - print 'KEY EXPIRED!',
> + print("KEY EXPIRED!")
> status.key_expired = True
> if sig.summary & gpgme.SIGSUM_KEY_REVOKED == gpgme.SIGSUM_KEY_REVOKED:
> - print 'KEY REVOKED!',
> + print("KEY REVOKED!")
> status.key_revoked = True
> if sig.summary & gpgme.SIGSUM_RED == gpgme.SIGSUM_RED:
> - print 'INVALID SIGNATURE!',
> + print("INVALID SIGNATURE!")
> status.invalid = True
> if sig.summary & gpgme.SIGSUM_CRL_MISSING == gpgme.SIGSUM_CRL_MISSING:
> - print 'CRL MISSING!',
> + print("CRL MISSING!")
> status.gpgme_error = True
> if sig.summary & gpgme.SIGSUM_CRL_TOO_OLD == gpgme.SIGSUM_CRL_TOO_OLD:
> - print 'CRL TOO OLD!',
> + print("CRL TOO OLD!")
> status.gpgme_error = True
> if sig.summary & gpgme.SIGSUM_BAD_POLICY == gpgme.SIGSUM_BAD_POLICY:
> - print 'UNMET POLICY REQUIREMENT!',
> + print("UNMET POLICY REQUIREMENT!")
> status.gpgme_error = True
> if sig.summary & gpgme.SIGSUM_SYS_ERROR == gpgme.SIGSUM_SYS_ERROR:
> - print 'SYSTEM ERROR!',
> + print("SYSTEM ERROR!'")
> status.gpgme_error = True
>
> return status
> @@ -115,7 +117,7 @@ def check_signature(ctx, sig):
> def unsign_file(fname):
> # check for .gpg extension and create an output filename without it
> if len(fname) <= 4 or fname[len(fname)-4:] != '.gpg':
> - print 'The input file needs a .gpg extension'
> + print("The input file needs a .gpg extension")
> return None
>
> outfilename = fname[:len(fname)-4]
> @@ -143,9 +145,9 @@ def unsign_file(fname):
> return outfilename
>
> except IOError as ex:
> - print ex.message
> + print(ex.message)
> except Exception as ex:
> - print 'Error checking the file %s: %s' % (fname, ex.message)
> + print("Error checking the file %s: %s" % (fname, ex.message))
>
> return None
>
> @@ -158,7 +160,7 @@ def sign (infile, outfile, fingerprint):
> try:
> key = ctx.get_key(fingerprint)
> except gpgme.GpgmeError as ex:
> - print 'no key with fingerprint %s: %s' % (fingerprint, ex.message)
> + print("no key with fingerprint %s: %s" % (fingerprint, ex.message))
> pass
>
> ctx.signers = [key]
> @@ -167,7 +169,7 @@ def sign (infile, outfile, fingerprint):
> try:
> ctx.sign(infile, outfile, gpgme.SIG_MODE_NORMAL)
> except Exception as ex:
> - print 'Error signing file %s' % ex.message
> + print("Error signing file %s" % ex.message)
> pass
>
>
> @@ -179,7 +181,7 @@ def sign_file(fname, fingerprint):
> with open(outfilename, 'w') as outfile:
> sign (infile, outfile, fingerprint)
> except Exception as ex:
> - print 'Error signing file %s' % ex.message
> + print("Error signing file %s" % ex.message)
> pass
>
>
> @@ -208,6 +210,6 @@ def export_key (fingerprint, outfile):
> try:
> ctx.export(fingerprint, outfile)
> except Exception as ex:
> - print 'Error exporting key %s' % (fingerprint)
> + print("Error exporting key %s" % (fingerprint))
>
> return '/var/cache/elbe/gnupg/pubring.gpg'
> diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
> index 872b0ded..aca04208 100644
> --- a/elbepack/hdimg.py
> +++ b/elbepack/hdimg.py
> @@ -16,6 +16,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> import os
> from string import digits
>
> @@ -177,7 +179,7 @@ class grubinstaller_base( object ):
> self.boot = None
>
> def set_boot_entry( self, entry ):
> - print "setting boot entry"
> + print("setting boot entry")
> self.boot = entry
>
> def set_root_entry( self, entry ):
> @@ -431,7 +433,7 @@ def add_binary_blob( outf, hd, target ):
> # use file from target/ dir if binary path starts with /
> if (binary.et.text[0] == '/'):
> bf = os.path.join(target, 'target', binary.et.text[1:])
> - print bf
> + print(bf)
> # else use file from /var/cache/elbe/<uuid> project dir
> else:
> bf = os.path.join(target, binary.et.text)
> diff --git a/elbepack/pkgutils.py b/elbepack/pkgutils.py
> index e8288941..88c7c8b7 100644
> --- a/elbepack/pkgutils.py
> +++ b/elbepack/pkgutils.py
> @@ -16,13 +16,20 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
>
> +# different module names in python 2 and 3
> +try:
> + import urllib.request
> + urlopen = urllib.request.urlopen
> +except ImportError:
> + import urllib2
> + urlopen = urllib2.urlopen
>
> import os
> +import hashlib
>
> from tempfile import mkdtemp
> -import urllib2
> -import hashlib
>
> from elbepack.shellhelper import CommandError, system
>
> @@ -31,10 +38,10 @@ try:
> from apt_pkg import TagFile
> virtapt_imported = True
> except ImportError:
> - print "WARNING - python-apt not available: if there are multiple versions of"
> - print " elbe-bootstrap packages on the mirror(s) elbe selects the first package it"
> - print " has found. There is no guarantee that the latest package is used."
> - print " To ensure this, the python-apt package needs to be installed."
> + print("WARNING - python-apt not available: if there are multiple versions of")
> + print(" elbe-bootstrap packages on the mirror(s) elbe selects the first package it")
> + print(" has found. There is no guarantee that the latest package is used.")
> + print(" To ensure this, the python-apt package needs to be installed.")
> virtapt_imported = False
>
>
> @@ -213,10 +220,10 @@ def copy_kinitrd( prj, target_dir, defs, arch="default" ):
> if m.hexdigest() != sha1:
> raise NoKinitrdException ('elbe-bootstrap failed to verify !!!')
> else:
> - print "-----------------------------------------------------"
> - print "WARNING:"
> - print "Using untrusted elbe-bootstrap"
> - print "-----------------------------------------------------"
> + print("-----------------------------------------------------")
> + print("WARNING:")
> + print("Using untrusted elbe-bootstrap")
> + print("-----------------------------------------------------")
>
>
> try:
> diff --git a/elbepack/templates.py b/elbepack/templates.py
> index 9bbca711..1e552058 100644
> --- a/elbepack/templates.py
> +++ b/elbepack/templates.py
> @@ -16,6 +16,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> import os
>
> from elbepack.treeutils import etree
> @@ -34,7 +36,7 @@ def template(fname, d, linebreak=False):
> else:
> return Template(filename=fname).render(**d)
> except:
> - print exceptions.text_error_template().render()
> + print(exceptions.text_error_template().render())
> raise
>
> def write_template( outname, fname, d, linebreak=False ):
> diff --git a/elbepack/updated.py b/elbepack/updated.py
> index 5e5dc9c2..d984595d 100644
> --- a/elbepack/updated.py
> +++ b/elbepack/updated.py
> @@ -19,6 +19,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> import apt
> import apt_pkg
> import errno
> @@ -92,15 +94,15 @@ class UpdateStatus:
> try:
> self.monitor.service.msg (msg)
> except:
> - print "logging to monitor failed, removing monitor connection"
> + print("logging to monitor failed, removing monitor connection")
> self.monitor = None
> - print msg
> + print(msg)
> try:
> syslog (msg)
> except:
> - print msg
> + print(msg)
> if self.verbose:
> - print msg
> + print(msg)
>
> class UpdateApplication (Application):
> def __init__(self, *args, **kargs):
> @@ -133,8 +135,8 @@ class UpdateService (ServiceBase):
>
> try:
> apply_update (fname, self.app.status)
> - print Exception, err
> except Exception as err:
> + print("%s" % str(err))
> self.app.status.set_finished ('error')
> return "apply snapshot %s failed" % version
>
> diff --git a/elbepack/updatepkg.py b/elbepack/updatepkg.py
> index 409c3959..cb3afeba 100644
> --- a/elbepack/updatepkg.py
> +++ b/elbepack/updatepkg.py
> @@ -18,6 +18,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> import os
>
> from shutil import rmtree, copyfile, copytree
> @@ -78,7 +80,7 @@ def gen_update_pkg (project, xml_filename, upd_filename,
> xmlindex[name] = p
>
> if not name in instindex:
> - print "package removed: " + name
> + print("package removed: %s" % name)
> continue
>
> ipkg = instindex[name]
> @@ -87,22 +89,22 @@ def gen_update_pkg (project, xml_filename, upd_filename,
> pfname = ipkg.installed_deb
>
> if comp == 0:
> - print "package ok: " + name + "-" + ipkg.installed_version
> + print("package ok: %s-%s" % (name, ipkg.installed_version))
> if debug:
> fnamelist.append( pfname )
> continue
>
> if comp > 0:
> - print "package upgrade: " + pfname
> + print("package upgrade: %s" % pfname)
> fnamelist.append( pfname )
> else:
> - print "package downgrade: " + name + "-" + ipkg.installed_version
> + print("package downgrade: %s-%s" % (name, ipkg.installed_version))
>
> for p in instpkgs:
> if p.name in xmlindex:
> continue
>
> - print "package new installed " + p.name
> + print("package %s newly installed" % p.name)
> pfname = p.installed_deb
> fnamelist.append( pfname )
>
> diff --git a/elbepack/virtapt.py b/elbepack/virtapt.py
> index 53607ad7..62d9c725 100644
> --- a/elbepack/virtapt.py
> +++ b/elbepack/virtapt.py
> @@ -16,6 +16,8 @@
> # You should have received a copy of the GNU General Public License
> # along with ELBE. If not, see <http://www.gnu.org/licenses/>.
>
> +from __future__ import print_function
> +
> import apt_pkg
> import os
> import sys
> @@ -83,7 +85,6 @@ class VirtApt:
> pass
>
> def pulse (self, obj):
> - #print "updating in progress", obj
> return True
>
> def mkdir_p (self, newdir, mode=0o755):
> @@ -121,8 +122,8 @@ class VirtApt:
> def setup_gpg (self):
> ring_path = self.projectpath + "/etc/apt/trusted.gpg"
> if not os.path.isdir ("/etc/apt/trusted.gpg.d"):
> - print ("/etc/apt/trusted.gpg.d doesn't exist")
> - print ("apt-get install debian-archive-keyring may fix this problem")
> + print("/etc/apt/trusted.gpg.d doesn't exist")
> + print("apt-get install debian-archive-keyring may fix this problem")
> sys.exit (20)
>
> system ('cp /etc/apt/trusted.gpg "%s"' % ring_path )
> @@ -137,13 +138,13 @@ class VirtApt:
>
> trustkeys = os.listdir("/etc/apt/trusted.gpg.d")
> for key in trustkeys:
> - print "Import %s: " % key
> + print("Import %s: " % key)
> try:
> system ('gpg %s --import "%s"' % (
> gpg_options,
> os.path.join ("/etc/apt/trusted.gpg.d", key)))
> except CommandError as e:
> - print "adding elbe-pubkey to keyring failed"
> + print("adding elbe-pubkey to keyring failed")
>
> def add_pubkey_url (self, url):
> ring_path = self.projectpath + "/etc/apt/trusted.gpg"
> diff --git a/elbepack/xmldefaults.py b/elbepack/xmldefaults.py
> index 56a1f95a..6857169d 100644
> --- a/elbepack/xmldefaults.py
> +++ b/elbepack/xmldefaults.py
> @@ -1,4 +1,6 @@
>
> +from __future__ import print_function
> +
> import random
> import string
> import sys
> @@ -186,9 +188,12 @@ class ElbeDefaults(object):
> def __init__(self, build_type):
>
> if build_type not in defaults:
> - print "Please specify a valid buildtype."
> - print "Valid buildtypes:"
> - print defaults.keys()
> + print("Please specify a valid buildtype.")
> + print("Valid buildtypes:")
> + print(defaults.keys())
> + print("Please specify a valid buildtype.")
> + print("Valid buildtypes:")
> + print(list(defaults.keys()))
> sys.exit(20)
>
> self.defaults = defaults[build_type]
> diff --git a/test/modify_rfs.py b/test/modify_rfs.py
> index a1934863..d94121d3 100644
> --- a/test/modify_rfs.py
> +++ b/test/modify_rfs.py
> @@ -1,3 +1,5 @@
> +from __future__ import print_function
> +
> from elbepack import rfs
> from elbepack import elbexml
> from elbepack import filesystem
> @@ -10,7 +12,7 @@ class AsyncStatus:
> def __init__ (self):
> pass
> def status (self, msg):
> - print "current status: " + msg
> + print("current status: " + msg)
>
> xml = elbexml.ElbeXML('source.xml')
> log = asciidoclog.ASCIIDocLog( "update.log" )
> @@ -22,11 +24,11 @@ from elbepack.rpcaptcache import get_rpcaptcache
> # Use "with br" to mount the necessary bind mounts
> with br:
> cc = get_rpcaptcache(br.rfs, "aptcache.log", "armel", notifier=status)
> - print "SECTIONS: ", cc.get_sections()
> + print("SECTIONS: ", cc.get_sections())
> time.sleep (2)
> - print "SHELLS: ", cc.get_pkglist('shells')
> + print("SHELLS: ", cc.get_pkglist('shells'))
> time.sleep (2)
> - print "QUICKPLOT: ", cc.get_dependencies('quickplot')
> + print("QUICKPLOT: ", cc.get_dependencies('quickplot'))
> time.sleep (2)
> cc.mark_install('quickplot','2')
> cc.commit()
> diff --git a/test/updated.py b/test/updated.py
> index 2a132182..692b1cc9 100755
> --- a/test/updated.py
> +++ b/test/updated.py
> @@ -1,5 +1,7 @@
> #!/usr/bin/env python2
>
> +from __future__ import print_function
> +
> import soaplib
> import sys
> import threading
> @@ -16,7 +18,7 @@ from wsgiref.simple_server import make_server
> class MonitorService (ServiceBase):
> @rpc (String)
> def msg (self, m):
> - print m
> + print(m)
>
> class MonitorThread (threading.Thread):
> def __init__ (self, port):
> @@ -25,7 +27,7 @@ class MonitorThread (threading.Thread):
> self.server = None
>
> def run (self):
> - print "monitor ready :%s" % (self.port)
> + print("monitor ready :%s" % (self.port))
> application = Application([MonitorService], 'monitor',
> in_protocol=Soap11(validator='lxml'),
> out_protocol=Soap11())
> @@ -89,7 +91,7 @@ wsdl = "http://" + target + ":" + port + "/?wsdl"
> try:
> control = Client (wsdl)
> except:
> - print wsdl, "not reachable"
> + print(wsdl, "not reachable")
> sys.exit (1)
>
> monitor = MonitorThread (monitorport)
> @@ -101,7 +103,7 @@ try:
> monitor_wsdl = "http://" + host + ":" + monitorport + "/?wsdl"
> control.service.register_monitor (monitor_wsdl)
> except:
> - print "monitor couldn't be registered (port already in use?)"
> + print("monitor couldn't be registered (port already in use?)")
> shutdown (monitor)
>
> while 1:
> @@ -110,20 +112,20 @@ while 1:
> try:
> snapshots = s.split (',')
>
> - print "select snapshot:"
> + print("select snapshot:")
> i = 0
> for s in snapshots:
> if s:
> - print " [%d] %s" % (i, s)
> + print(" [%d] %s" % (i, s))
> i = i + 1
> except:
> - print "no snapshots available"
> + print("no snapshots available")
>
> sys.stdout.write ("% ")
> sys.stdout.flush ()
>
> try:
> n = int (input ())
> - print control.service.apply_snapshot (snapshots [n])
> + print(control.service.apply_snapshot (snapshots [n]))
> except:
> shutdown (monitor)
> --
> 2.15.1
>
>
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel
--
Mit freundlichen Grüßen
Torben Hohn
Linutronix GmbH
Standort: Bremen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99
Firmensitz / Registered Office: D-88690 Uhldingen, Bahnhofstr. 3
Registergericht / Local District Court: Amtsgericht Freiburg i. Br.; HRB
Nr. / Trade register no.: 700 806
Geschäftsführer / Managing Directors: Heinz Egger, Thomas Gleixner
Eine Bitte von uns: Sollten Sie diese E-Mail irrtümlich erhalten haben,
benachrichtigen Sie uns in diesem Falle bitte sobald wie es Ihnen
möglich ist, durch Antwort-Mail. Vielen Dank!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.linutronix.de/pipermail/elbe-devel/attachments/20171218/a00b67a4/attachment-0001.sig>
More information about the elbe-devel
mailing list