From 73994f9b738d0ffeb22be64e7d069a7781e526ef Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 2 Oct 2011 11:36:56 +0100 Subject: [PATCH] Converted print statements to functions --- 0alias | 42 +++++++++++----------- 0store | 28 ++++++++------- 0store-secure-add | 5 ++- tests/server.py | 7 ++-- tests/testall.py | 7 ++-- tests/testlaunch.py | 5 ++- tests/testunpack.py | 7 ++-- zeroinstall/0launch-gui/browser.py | 4 ++- zeroinstall/0launch-gui/bugs.py | 4 ++- zeroinstall/0launch-gui/main.py | 12 ++++--- zeroinstall/cmd/__init__.py | 14 ++++---- zeroinstall/cmd/add_feed.py | 24 +++++++------ zeroinstall/cmd/config.py | 6 ++-- zeroinstall/cmd/digest.py | 4 ++- zeroinstall/cmd/list.py | 4 ++- zeroinstall/cmd/list_feeds.py | 6 ++-- zeroinstall/cmd/select.py | 10 +++--- zeroinstall/cmd/update.py | 10 +++--- zeroinstall/gtkui/cache.py | 10 +++--- zeroinstall/gtkui/desktop.py | 10 +++--- zeroinstall/injector/cli.py | 16 +++++---- zeroinstall/injector/handler.py | 30 ++++++++-------- zeroinstall/injector/run.py | 4 ++- zeroinstall/injector/sat.py | 4 ++- zeroinstall/zerostore/cli.py | 72 ++++++++++++++++++++------------------ 25 files changed, 200 insertions(+), 145 deletions(-) diff --git a/0alias b/0alias index a161c29..bb0ed76 100755 --- a/0alias +++ b/0alias @@ -2,6 +2,8 @@ # Copyright (C) 2010, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + import locale from logging import warn try: @@ -64,13 +66,13 @@ parser.add_option("-d", "--dir", help="install in DIR", dest="user_path", metava if options.version: import zeroinstall - print "0alias (zero-install) " + zeroinstall.version - print "Copyright (C) 2010 Thomas Leonard" - print "This program comes with ABSOLUTELY NO WARRANTY," - print "to the extent permitted by law." - print "You may redistribute copies of this program" - print "under the terms of the GNU Lesser General Public License." - print "For more information about these matters, see the file named COPYING." + print("0alias (zero-install) " + zeroinstall.version) + print("Copyright (C) 2010 Thomas Leonard") + print("This program comes with ABSOLUTELY NO WARRANTY,") + print("to the extent permitted by law.") + print("You may redistribute copies of this program") + print("under the terms of the GNU Lesser General Public License.") + print("For more information about these matters, see the file named COPYING.") sys.exit(0) if options.manpage: @@ -94,7 +96,7 @@ if options.user_path: if interface_uri is None: if options.command: - print >>sys.stderr, "Can't use --command when editing an existing alias" + print("Can't use --command when editing an existing alias", file=sys.stderr) sys.exit(1) try: if not os.path.isabs(alias_prog): @@ -111,13 +113,13 @@ if interface_uri is None: except alias.NotAnAliasScript as ex: if options.manpage: os.execlp('man', 'man', *args) - print >>sys.stderr, str(ex) + print(str(ex), file=sys.stderr) sys.exit(1) interface_uri = model.canonical_iface_uri(interface_uri) if options.resolve: - print interface_uri + print(interface_uri) sys.exit(0) if options.manpage: @@ -129,7 +131,7 @@ if options.manpage: if sels.commands: selected_command = sels.commands[0] else: - print >>sys.stderr, "No in selections!" + print("No in selections!", file=sys.stderr) selected_impl = sels.selections[interface_uri] from zeroinstall.injector.iface_cache import iface_cache @@ -138,7 +140,7 @@ if options.manpage: if main is None: main = selected_command.path if main is None: - print >>sys.stderr, "No main program for interface '%s'" % interface_uri + print("No main program for interface '%s'" % interface_uri, file=sys.stderr) sys.exit(1) prog_name = os.path.basename(main) @@ -175,15 +177,15 @@ if options.manpage: else: manpages.append((root, f)) - print "No matching manpage was found for '%s' (%s)" % (alias_name, interface_uri) + print("No matching manpage was found for '%s' (%s)" % (alias_name, interface_uri)) if manpages: - print "These non-matching man-pages were found, however:" + print("These non-matching man-pages were found, however:") for root, file in manpages: - print os.path.join(root, file) + print(os.path.join(root, file)) sys.exit(1) if not os.path.isdir(first_path): - print "(creating directory %s)" % first_path + print("(creating directory %s)" % first_path) os.makedirs(first_path) if len(args) == 1: @@ -193,7 +195,7 @@ if len(args) == 1: try: interface = model.Interface(interface_uri) if not reader.update_from_cache(interface): - print >>sys.stderr, "Interface '%s' not currently in cache. Fetching..." % interface_uri + print("Interface '%s' not currently in cache. Fetching..." % interface_uri, file=sys.stderr) if os.spawnlp(os.P_WAIT, '0launch', '0launch', '-d', interface_uri): raise model.SafeException("0launch failed") if not reader.update_from_cache(interface): @@ -204,7 +206,7 @@ try: raise model.SafeException("File '%s' already exists. Delete it first." % script) sys.exit(1) except model.SafeException as ex: - print >>sys.stderr, ex + print(ex, file=sys.stderr) sys.exit(1) wrapper = file(script, 'w') @@ -219,8 +221,8 @@ wrapper.close() if options.user_path: pass # Assume user knows what they're doing elif not in_path: - print >>sys.stderr, 'Warning: %s is not in $PATH. Add it with:\n%s' % (first_path, export('PATH', first_path + ':$PATH')) + print('Warning: %s is not in $PATH. Add it with:\n%s' % (first_path, export('PATH', first_path + ':$PATH')), file=sys.stderr) else: shell = os.environ.get('SHELL', '?') if not (shell.endswith('/zsh') or shell.endswith('/bash')): - print "(note: some shells require you to type 'rehash' now)" + print("(note: some shells require you to type 'rehash' now)") diff --git a/0store b/0store index 5809841..47faee3 100755 --- a/0store +++ b/0store @@ -1,5 +1,7 @@ #!/usr/bin/env python +from __future__ import print_function + import locale from logging import warn try: @@ -38,13 +40,13 @@ if options.verbose: if options.version: import zeroinstall - print "0store (zero-install) " + zeroinstall.version - print "Copyright (C) 2009 Thomas Leonard" - print "This program comes with ABSOLUTELY NO WARRANTY," - print "to the extent permitted by law." - print "You may redistribute copies of this program" - print "under the terms of the GNU Lesser General Public License." - print "For more information about these matters, see the file named COPYING." + print("0store (zero-install) " + zeroinstall.version) + print("Copyright (C) 2009 Thomas Leonard") + print("This program comes with ABSOLUTELY NO WARRANTY,") + print("to the extent permitted by law.") + print("You may redistribute copies of this program") + print("under the terms of the GNU Lesser General Public License.") + print("For more information about these matters, see the file named COPYING.") sys.exit(0) if len(args) < 1: @@ -64,21 +66,21 @@ try: (pattern, '\n'.join(['- ' + x.__name__[3:] for x in matches]))) matches[0](args[1:]) except KeyboardInterrupt as ex: - print >>sys.stderr, "Interrupted" + print("Interrupted", file=sys.stderr) sys.exit(1) except OSError as ex: if options.verbose: raise - print >>sys.stderr, str(ex) + print(str(ex), file=sys.stderr) sys.exit(1) except IOError as ex: if options.verbose: raise - print >>sys.stderr, str(ex) + print(str(ex), file=sys.stderr) sys.exit(1) except cli.UsageError as ex: - print >>sys.stderr, str(ex) - print >>sys.stderr, "usage: " + sys.argv[0] + " " + matches[0].__doc__ + print(str(ex), file=sys.stderr) + print("usage: " + sys.argv[0] + " " + matches[0].__doc__, file=sys.stderr) sys.exit(1) except SafeException as ex: if options.verbose: raise - print >>sys.stderr, str(ex) + print(str(ex), file=sys.stderr) sys.exit(1) diff --git a/0store-secure-add b/0store-secure-add index 3792e7a..d6db188 100755 --- a/0store-secure-add +++ b/0store-secure-add @@ -1,4 +1,7 @@ #!/usr/bin/env python + +from __future__ import print_function + import sys, os from zeroinstall import zerostore, SafeException from zeroinstall.zerostore import cli, manifest @@ -26,5 +29,5 @@ try: manifest.copy_tree_with_verify('.', '/var/cache/0install.net/implementations', manifest_data, required_digest) except (IOError, SafeException) as ex: - print >>sys.stderr, ex + print(ex, file=sys.stderr) sys.exit(1) diff --git a/tests/server.py b/tests/server.py index 1a22ed5..9536433 100644 --- a/tests/server.py +++ b/tests/server.py @@ -1,4 +1,7 @@ #!/usr/bin/env python + +from __future__ import print_function + import os, sys, urlparse import BaseHTTPServer import traceback @@ -56,13 +59,13 @@ def handle_requests(*script): try: sys.stderr = sys.stdout #sys.stdout = sys.stderr - print "Waiting for request" + print("Waiting for request") global next_step for next_step in script: if type(next_step) != tuple: next_step = (next_step,) for x in next_step: httpd.handle_request() - print "Done" + print("Done") os._exit(0) except: traceback.print_exc() diff --git a/tests/testall.py b/tests/testall.py index 4301973..b4d027f 100755 --- a/tests/testall.py +++ b/tests/testall.py @@ -1,4 +1,7 @@ #!/usr/bin/env python + +from __future__ import print_function + import unittest, os, sys # Catch silly mistakes... @@ -34,9 +37,9 @@ a = unittest.TextTestRunner(verbosity=2).run(alltests) if coverage: coverage.stop() else: - print "Coverage module not found. Skipping coverage report." + print("Coverage module not found. Skipping coverage report.") -print "\nResult", a +print("\nResult", a) if not a.wasSuccessful(): sys.exit(1) diff --git a/tests/testlaunch.py b/tests/testlaunch.py index 7f50d28..382e46d 100755 --- a/tests/testlaunch.py +++ b/tests/testlaunch.py @@ -1,4 +1,7 @@ #!/usr/bin/env python + +from __future__ import print_function + from basetest import BaseTest import sys, tempfile, os from StringIO import StringIO @@ -30,7 +33,7 @@ class TestLaunch(BaseTest): ex = None try: cli.main(args) - print "Finished" + print("Finished") except NameError: raise except SystemExit: diff --git a/tests/testunpack.py b/tests/testunpack.py index b35c20a..5731f4e 100755 --- a/tests/testunpack.py +++ b/tests/testunpack.py @@ -1,4 +1,7 @@ #!/usr/bin/env python + +from __future__ import print_function + from basetest import BaseTest import sys, tempfile, os import unittest, logging @@ -11,7 +14,7 @@ from zeroinstall.support import find_in_path def skipIf(condition, reason): def wrapped(underlying): if condition: - print "Skipped %s: %s" % (underlying.func_name, reason) + print("Skipped %s: %s" % (underlying.func_name, reason)) def run(self): pass return run else: @@ -165,7 +168,7 @@ class TestUnpackGNU(AbstractTestUnpack, BaseTest): self.assert_manifest('sha1new=290eb133e146635fe37713fd58174324a16d595f') if not unpack._gnu_tar(): - print "No GNU tar: SKIPPING tests" + print("No GNU tar: SKIPPING tests") del globals()['TestUnpackGNU'] if __name__ == '__main__': diff --git a/zeroinstall/0launch-gui/browser.py b/zeroinstall/0launch-gui/browser.py index a930cd7..e85c7f7 100644 --- a/zeroinstall/0launch-gui/browser.py +++ b/zeroinstall/0launch-gui/browser.py @@ -1,6 +1,8 @@ # Copyright (C) 2009, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + import os, sys def open_in_browser(link): @@ -12,6 +14,6 @@ def open_in_browser(link): os.spawnlp(os.P_NOWAIT, browser, browser, link) os._exit(0) except Exception as ex: - print >>sys.stderr, "Error", ex + print("Error", ex, file=sys.stderr) os._exit(1) os.waitpid(child, 0) diff --git a/zeroinstall/0launch-gui/bugs.py b/zeroinstall/0launch-gui/bugs.py index f4e80d9..994f8fc 100644 --- a/zeroinstall/0launch-gui/bugs.py +++ b/zeroinstall/0launch-gui/bugs.py @@ -1,6 +1,8 @@ # Copyright (C) 2009, Thomas Leonard # See http://0install.net/0compile.html +from __future__ import print_function + import sys, os import gtk, pango import dialog @@ -236,5 +238,5 @@ class BugReporter(dialog.Dialog): stream.close() except: # Write to stderr in the hope that it doesn't get lost - print >>sys.stderr, "Error sending bug report: %s\n\n%s" % (title, text) + print("Error sending bug report: %s\n\n%s" % (title, text), file=sys.stderr) raise diff --git a/zeroinstall/0launch-gui/main.py b/zeroinstall/0launch-gui/main.py index aba9bd0..a21c38e 100644 --- a/zeroinstall/0launch-gui/main.py +++ b/zeroinstall/0launch-gui/main.py @@ -1,6 +1,8 @@ # Copyright (C) 2009, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + import os, sys from optparse import OptionParser @@ -52,18 +54,18 @@ def run_gui(args): import gui if options.version: - print "0launch-gui (zero-install) " + gui.version - print "Copyright (C) 2010 Thomas Leonard" - print _("This program comes with ABSOLUTELY NO WARRANTY," + print("0launch-gui (zero-install) " + gui.version) + print("Copyright (C) 2010 Thomas Leonard") + print(_("This program comes with ABSOLUTELY NO WARRANTY," "\nto the extent permitted by law." "\nYou may redistribute copies of this program" "\nunder the terms of the GNU Lesser General Public License." - "\nFor more information about these matters, see the file named COPYING.") + "\nFor more information about these matters, see the file named COPYING.")) sys.exit(0) import gtk if gtk.gdk.get_display() is None: - print >>sys.stderr, "Failed to connect to display. Aborting." + print("Failed to connect to display. Aborting.", file=sys.stderr) sys.exit(1) handler = gui.GUIHandler() diff --git a/zeroinstall/cmd/__init__.py b/zeroinstall/cmd/__init__.py index 91cf00f..c3be334 100644 --- a/zeroinstall/cmd/__init__.py +++ b/zeroinstall/cmd/__init__.py @@ -5,6 +5,8 @@ The B{0install} command-line interface. # Copyright (C) 2011, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + from zeroinstall import _ import os, sys from optparse import OptionParser @@ -38,13 +40,13 @@ def _no_command(command_args): (options, args) = parser.parse_args(command_args) if options.version: import zeroinstall - print "0install (zero-install) " + zeroinstall.version - print "Copyright (C) 2011 Thomas Leonard" - print _("This program comes with ABSOLUTELY NO WARRANTY," + print("0install (zero-install) " + zeroinstall.version) + print("Copyright (C) 2011 Thomas Leonard") + print(_("This program comes with ABSOLUTELY NO WARRANTY," "\nto the extent permitted by law." "\nYou may redistribute copies of this program" "\nunder the terms of the GNU Lesser General Public License." - "\nFor more information about these matters, see the file named COPYING.") + "\nFor more information about these matters, see the file named COPYING.")) sys.exit(0) parser.print_help() sys.exit(2) @@ -116,8 +118,8 @@ def main(command_args, config = None): except SafeException as ex: if verbose: raise try: - print >>sys.stderr, unicode(ex) + print(unicode(ex), file=sys.stderr) except: - print >>sys.stderr, repr(ex) + print(repr(ex), file=sys.stderr) sys.exit(1) return diff --git a/zeroinstall/cmd/add_feed.py b/zeroinstall/cmd/add_feed.py index 0b4cd1f..fd26ce3 100644 --- a/zeroinstall/cmd/add_feed.py +++ b/zeroinstall/cmd/add_feed.py @@ -5,6 +5,8 @@ The B{0install add-feed} command-line interface. # Copyright (C) 2011, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + from zeroinstall import SafeException, _ from zeroinstall.support import tasks from zeroinstall.cmd import UsageError @@ -27,7 +29,7 @@ def handle(config, options, args, add_ok = True, remove_ok = False): x = args[0] - print _("Feed '%s':") % x + '\n' + print(_("Feed '%s':") % x + '\n') x = model.canonical_iface_uri(x) policy = Policy(x, config = config) if options.offline: @@ -36,9 +38,9 @@ def handle(config, options, args, add_ok = True, remove_ok = False): feed = config.iface_cache.get_feed(x) if policy.network_use != model.network_offline and policy.is_stale(feed): blocker = policy.fetcher.download_and_import_feed(x, config.iface_cache) - print _("Downloading feed; please wait...") + print(_("Downloading feed; please wait...")) tasks.wait_for_blocker(blocker) - print _("Done") + print(_("Done")) candidate_interfaces = policy.get_feed_targets(x) assert candidate_interfaces @@ -47,11 +49,11 @@ def handle(config, options, args, add_ok = True, remove_ok = False): iface = candidate_interfaces[i] if find_feed_import(iface, x): if remove_ok: - print _("%(index)d) Remove as feed for '%(uri)s'") % {'index': i + 1, 'uri': iface.uri} + print(_("%(index)d) Remove as feed for '%(uri)s'") % {'index': i + 1, 'uri': iface.uri}) interfaces.append(iface) else: if add_ok: - print _("%(index)d) Add as feed for '%(uri)s'") % {'index': i + 1, 'uri': iface.uri} + print(_("%(index)d) Add as feed for '%(uri)s'") % {'index': i + 1, 'uri': iface.uri}) interfaces.append(iface) if not interfaces: if remove_ok: @@ -60,12 +62,12 @@ def handle(config, options, args, add_ok = True, remove_ok = False): else: raise SafeException(_("%(feed)s already registered as a feed for %(interface)s") % {'feed': x, 'interface': candidate_interfaces[0]}) - print + print() while True: try: i = raw_input(_('Enter a number, or CTRL-C to cancel [1]: ')).strip() except KeyboardInterrupt: - print + print() raise SafeException(_("Aborted at user request.")) if i == '': i = 1 @@ -76,7 +78,7 @@ def handle(config, options, args, add_ok = True, remove_ok = False): i = 0 if i > 0 and i <= len(interfaces): break - print _("Invalid number. Try again. (1 to %d)") % len(interfaces) + print(_("Invalid number. Try again. (1 to %d)") % len(interfaces)) iface = interfaces[i - 1] feed_import = find_feed_import(iface, x) if feed_import: @@ -84,9 +86,9 @@ def handle(config, options, args, add_ok = True, remove_ok = False): else: iface.extra_feeds.append(model.Feed(x, arch = None, user_override = True)) writer.save_interface(iface) - print '\n' + _("Feed list for interface '%s' is now:") % iface.get_name() + print('\n' + _("Feed list for interface '%s' is now:") % iface.get_name()) if iface.extra_feeds: for f in iface.extra_feeds: - print "- " + f.uri + print("- " + f.uri) else: - print _("(no feeds)") + print(_("(no feeds)")) diff --git a/zeroinstall/cmd/config.py b/zeroinstall/cmd/config.py index f8c1e7e..3de00cd 100644 --- a/zeroinstall/cmd/config.py +++ b/zeroinstall/cmd/config.py @@ -5,6 +5,8 @@ The B{0install config} command-line interface. # Copyright (C) 2011, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + import os from zeroinstall import SafeException, _ @@ -93,7 +95,7 @@ def handle(config, options, args): else: for key, setting_type in settings.iteritems(): value = getattr(config, key) - print key, "=", setting_type.format(value) + print(key, "=", setting_type.format(value)) return elif len(args) > 2: raise UsageError() @@ -104,7 +106,7 @@ def handle(config, options, args): if len(args) == 1: value = getattr(config, option) - print settings[option].format(value) + print(settings[option].format(value)) else: value = settings[option].parse(args[1]) if option == 'network_use' and value not in model.network_levels: diff --git a/zeroinstall/cmd/digest.py b/zeroinstall/cmd/digest.py index 22fe057..6618430 100644 --- a/zeroinstall/cmd/digest.py +++ b/zeroinstall/cmd/digest.py @@ -5,6 +5,8 @@ The B{0install digest} command-line interface. # Copyright (C) 2011, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + import os, tempfile from zeroinstall import SafeException, _ @@ -36,7 +38,7 @@ def handle(config, options, args): digest = alg.new_digest() for line in alg.generate_manifest(d): digest.update(line + '\n') - print alg.getID(digest) + print(alg.getID(digest)) if os.path.isdir(source): if extract is not None: diff --git a/zeroinstall/cmd/list.py b/zeroinstall/cmd/list.py index 6d3a970..834f424 100644 --- a/zeroinstall/cmd/list.py +++ b/zeroinstall/cmd/list.py @@ -5,6 +5,8 @@ The B{0install list} command-line interface. # Copyright (C) 2011, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + from zeroinstall.cmd import UsageError syntax = "PATTERN" @@ -23,4 +25,4 @@ def handle(config, options, args): matches.sort() for i in matches: - print i + print(i) diff --git a/zeroinstall/cmd/list_feeds.py b/zeroinstall/cmd/list_feeds.py index 615e2c1..8e2e0ed 100644 --- a/zeroinstall/cmd/list_feeds.py +++ b/zeroinstall/cmd/list_feeds.py @@ -5,6 +5,8 @@ The B{0install list-feeds} command-line interface. # Copyright (C) 2011, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + from zeroinstall import _ from zeroinstall.cmd import UsageError from zeroinstall.injector import model @@ -21,6 +23,6 @@ def handle(config, options, args): if iface.extra_feeds: for f in iface.extra_feeds: - print f.uri + print(f.uri) else: - print _("(no feeds)") + print(_("(no feeds)")) diff --git a/zeroinstall/cmd/select.py b/zeroinstall/cmd/select.py index 229c610..bd5fa8d 100644 --- a/zeroinstall/cmd/select.py +++ b/zeroinstall/cmd/select.py @@ -5,6 +5,8 @@ The B{0install select} command-line interface. # Copyright (C) 2011, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + import os, sys import logging @@ -162,9 +164,9 @@ def show_human(sels, stores): if uri in done: return done.add(uri) impl = sels.selections.get(uri, None) - print indent + "- URI:", uri + print(indent + "- URI:", uri) if impl: - print indent + " Version:", impl.version + print(indent + " Version:", impl.version) #print indent + " Command:", command try: if impl.id.startswith('package:'): @@ -173,7 +175,7 @@ def show_human(sels, stores): path = impl.local_path or stores.lookup_any(impl.digests) except zerostore.NotStored: path = "(not cached)" - print indent + " Path:", path + print(indent + " Path:", path) indent += " " deps = impl.dependencies @@ -182,7 +184,7 @@ def show_human(sels, stores): for child in deps: print_node(child.interface, child.get_required_commands(), indent) else: - print indent + " No selected version" + print(indent + " No selected version") if sels.command: diff --git a/zeroinstall/cmd/update.py b/zeroinstall/cmd/update.py index 7033317..553f9c0 100644 --- a/zeroinstall/cmd/update.py +++ b/zeroinstall/cmd/update.py @@ -5,6 +5,8 @@ The B{0install download} command-line interface. # Copyright (C) 2011, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + import sys from zeroinstall import SafeException, _ @@ -57,16 +59,16 @@ def handle(config, options, args): for iface, old_sel in old_selections.iteritems(): new_sel = sels.selections.get(iface, None) if new_sel is None: - print _("No longer used: %s") % iface + print(_("No longer used: %s") % iface) changes = True elif old_sel.version != new_sel.version: - print _("%s: %s -> %s") % (iface, old_sel.version, new_sel.version) + print(_("%s: %s -> %s") % (iface, old_sel.version, new_sel.version)) changes = True for iface, new_sel in sels.selections.iteritems(): if iface not in old_selections: - print _("%s: new -> %s") % (iface, new_sel.version) + print(_("%s: new -> %s") % (iface, new_sel.version)) changes = True if not changes: - print _("No updates found.") + print(_("No updates found.")) diff --git a/zeroinstall/gtkui/cache.py b/zeroinstall/gtkui/cache.py index 1d4c636..0a98728 100644 --- a/zeroinstall/gtkui/cache.py +++ b/zeroinstall/gtkui/cache.py @@ -2,6 +2,8 @@ # Copyright (C) 2009, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + from zeroinstall import _ import os import gtk @@ -211,7 +213,7 @@ class CachedFeed(object): 'interfaces', model.escape(self.uri)) if cached_iface: if SAFE_MODE: - print "Delete", cached_iface + print("Delete", cached_iface) else: os.unlink(cached_iface) user_overrides = basedir.load_first_config(namespaces.config_site, @@ -219,7 +221,7 @@ class CachedFeed(object): 'interfaces', model._pretty_escape(self.uri)) if user_overrides: if SAFE_MODE: - print "Delete", user_overrides + print("Delete", user_overrides) else: os.unlink(user_overrides) @@ -322,7 +324,7 @@ class CachedImplementation: def delete(self): if SAFE_MODE: - print "Delete", self.impl_path + print("Delete", self.impl_path) else: support.ro_rmtree(self.impl_path) @@ -382,7 +384,7 @@ class KnownImplementation(CachedImplementation): def delete(self): if SAFE_MODE: - print "Delete", self.impl + print("Delete", self.impl) else: CachedImplementation.delete(self) self.cached_iface.in_cache.remove(self) diff --git a/zeroinstall/gtkui/desktop.py b/zeroinstall/gtkui/desktop.py index b0627e5..4c1dab3 100644 --- a/zeroinstall/gtkui/desktop.py +++ b/zeroinstall/gtkui/desktop.py @@ -3,6 +3,8 @@ # Copyright (C) 2009, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + from zeroinstall import _ import sys from optparse import OptionParser @@ -31,13 +33,13 @@ def main(command_args): if options.version: import zeroinstall - print "0desktop (zero-install) " + zeroinstall.version - print "Copyright (C) 2009 Thomas Leonard" - print _("This program comes with ABSOLUTELY NO WARRANTY," + print("0desktop (zero-install) " + zeroinstall.version) + print("Copyright (C) 2009 Thomas Leonard") + print(_("This program comes with ABSOLUTELY NO WARRANTY," "\nto the extent permitted by law." "\nYou may redistribute copies of this program" "\nunder the terms of the GNU Lesser General Public License." - "\nFor more information about these matters, see the file named COPYING.") + "\nFor more information about these matters, see the file named COPYING.")) sys.exit(0) if not args: diff --git a/zeroinstall/injector/cli.py b/zeroinstall/injector/cli.py index 646902a..6ba7f67 100644 --- a/zeroinstall/injector/cli.py +++ b/zeroinstall/injector/cli.py @@ -5,6 +5,8 @@ This code is here, rather than in B{0launch} itself, simply so that it gets byte install time. """ +from __future__ import print_function + from zeroinstall import _ import os, sys from optparse import OptionParser @@ -98,13 +100,13 @@ def main(command_args, config = None): list.handle(config, options, args) elif options.version: import zeroinstall - print "0launch (zero-install) " + zeroinstall.version - print "Copyright (C) 2010 Thomas Leonard" - print _("This program comes with ABSOLUTELY NO WARRANTY," + print("0launch (zero-install) " + zeroinstall.version) + print("Copyright (C) 2010 Thomas Leonard") + print(_("This program comes with ABSOLUTELY NO WARRANTY," "\nto the extent permitted by law." "\nYou may redistribute copies of this program" "\nunder the terms of the GNU Lesser General Public License." - "\nFor more information about these matters, see the file named COPYING.") + "\nFor more information about these matters, see the file named COPYING.")) elif getattr(options, 'import'): # (import is a keyword) cmd = __import__('zeroinstall.cmd.import', globals(), locals(), ["import"], 0) @@ -132,14 +134,14 @@ def main(command_args, config = None): run.handle(config, options, args) except NeedDownload as ex: # This only happens for dry runs - print ex + print(ex) except UsageError: parser.print_help() sys.exit(1) except SafeException as ex: if options.verbose: raise try: - print >>sys.stderr, unicode(ex) + print(unicode(ex), file=sys.stderr) except: - print >>sys.stderr, repr(ex) + print(repr(ex), file=sys.stderr) sys.exit(1) diff --git a/zeroinstall/injector/handler.py b/zeroinstall/injector/handler.py index 60a7145..81b7c4f 100644 --- a/zeroinstall/injector/handler.py +++ b/zeroinstall/injector/handler.py @@ -10,6 +10,8 @@ To do this, you supply a L{Handler} to the L{policy}. # Copyright (C) 2009, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + from zeroinstall import _ import sys from logging import warn, info @@ -122,10 +124,10 @@ class Handler(object): domain = trust.domain_from_url(pending.url) # Ask on stderr, because we may be writing XML to stdout - print >>sys.stderr, _("Feed: %s") % pending.url - print >>sys.stderr, _("The feed is correctly signed with the following keys:") + print(_("Feed: %s") % pending.url, file=sys.stderr) + print(_("The feed is correctly signed with the following keys:"), file=sys.stderr) for x in valid_sigs: - print >>sys.stderr, "-", x + print("-", x, file=sys.stderr) def text(parent): text = "" @@ -143,14 +145,14 @@ class Handler(object): infos = set(kf.info) - shown if infos: if len(valid_sigs) > 1: - print "%s: " % kf.fingerprint + print("%s: " % kf.fingerprint) for key_info in infos: - print >>sys.stderr, "-", text(key_info) + print("-", text(key_info), file=sys.stderr) shown.add(key_info) if kf.blocker: key_info_fetchers.append(kf) if key_info_fetchers: - for kf in key_info_fetchers: print >>sys.stderr, kf.status + for kf in key_info_fetchers: print(kf.status, file=sys.stderr) stdin = tasks.InputBlocker(0, 'console') blockers = [kf.blocker for kf in key_info_fetchers] + [stdin] yield blockers @@ -160,17 +162,17 @@ class Handler(object): except Exception as ex: warn(_("Failed to get key info: %s"), ex) if stdin.happened: - print >>sys.stderr, _("Skipping remaining key lookups due to input from user") + print(_("Skipping remaining key lookups due to input from user"), file=sys.stderr) break if not shown: - print >>sys.stderr, _("Warning: Nothing known about this key!") + print(_("Warning: Nothing known about this key!"), file=sys.stderr) if len(valid_sigs) == 1: - print >>sys.stderr, _("Do you want to trust this key to sign feeds from '%s'?") % domain + print(_("Do you want to trust this key to sign feeds from '%s'?") % domain, file=sys.stderr) else: - print >>sys.stderr, _("Do you want to trust all of these keys to sign feeds from '%s'?") % domain + print(_("Do you want to trust all of these keys to sign feeds from '%s'?") % domain, file=sys.stderr) while True: - print >>sys.stderr, _("Trust [Y/N] "), + print(_("Trust [Y/N] "), end=' ', file=sys.stderr) i = raw_input() if not i: continue if i in 'Nn': @@ -178,7 +180,7 @@ class Handler(object): if i in 'Yy': break for key in valid_sigs: - print >>sys.stderr, _("Trusting %(key_fingerprint)s for %(domain)s") % {'key_fingerprint': key.fingerprint, 'domain': domain} + print(_("Trusting %(key_fingerprint)s for %(domain)s") % {'key_fingerprint': key.fingerprint, 'domain': domain}, file=sys.stderr) trust.trust_db.trust_key(key.fingerprint, domain) @tasks.async @@ -186,7 +188,7 @@ class Handler(object): """We need to check something with the user before continuing with the install. @raise download.DownloadAborted: if the user cancels""" yield - print >>sys.stderr, msg + print(msg, file=sys.stderr) while True: sys.stderr.write(_("Install [Y/N] ")) i = raw_input() @@ -231,7 +233,7 @@ class ConsoleHandler(Handler): if self.update: gobject.source_remove(self.update) self.update = None - print + print() self.last_msg_len = None def show_progress(self): diff --git a/zeroinstall/injector/run.py b/zeroinstall/injector/run.py index 6f10e91..2b01287 100644 --- a/zeroinstall/injector/run.py +++ b/zeroinstall/injector/run.py @@ -5,6 +5,8 @@ Executes a set of implementations as a program. # Copyright (C) 2009, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + from zeroinstall import _ import os, sys from logging import info @@ -320,7 +322,7 @@ def execute_selections(selections, prog_args, dry_run = False, main = None, wrap prog_args = ['/bin/sh', '-c', wrapper + ' "$@"', '-'] + list(prog_args) if dry_run: - print _("Would execute: %s") % ' '.join(prog_args) + print(_("Would execute: %s") % ' '.join(prog_args)) else: info(_("Executing: %s"), prog_args) sys.stdout.flush() diff --git a/zeroinstall/injector/sat.py b/zeroinstall/injector/sat.py index 1f9ff25..9dbce04 100644 --- a/zeroinstall/injector/sat.py +++ b/zeroinstall/injector/sat.py @@ -3,6 +3,8 @@ Internal implementation of a SAT solver, used by L{solver.SATSolver}. This is not part of the public API. """ +from __future__ import print_function + # Copyright (C) 2010, Thomas Leonard # See the README file for details, or visit http://0install.net. @@ -20,7 +22,7 @@ This is not part of the public API. def debug(msg, *args): return - print "SAT:", msg % args + print("SAT:", msg % args) # variables are numbered from 0 # literals have the same number as the corresponding variable, diff --git a/zeroinstall/zerostore/cli.py b/zeroinstall/zerostore/cli.py index 88e3358..8b877e9 100644 --- a/zeroinstall/zerostore/cli.py +++ b/zeroinstall/zerostore/cli.py @@ -3,6 +3,8 @@ # Copyright (C) 2009, Thomas Leonard # See the README file for details, or visit http://0install.net. +from __future__ import print_function + from zeroinstall import _ import sys, os, errno from zeroinstall.zerostore.manifest import verify, get_algorithm, copy_tree_with_verify @@ -32,21 +34,21 @@ def do_manifest(args): alg = get_algorithm('sha1new') digest = alg.new_digest() for line in alg.generate_manifest(args[0]): - print line + print(line) digest.update(line + '\n') - print alg.getID(digest) + print(alg.getID(digest)) sys.exit(0) def do_find(args): """find DIGEST""" if len(args) != 1: raise UsageError(_("Wrong number of arguments")) try: - print stores.lookup(args[0]) + print(stores.lookup(args[0])) sys.exit(0) except zerostore.BadDigest as ex: - print >>sys.stderr, ex + print(ex, file=sys.stderr) except zerostore.NotStored as ex: - print >>sys.stderr, ex + print(ex, file=sys.stderr) sys.exit(1) def do_add(args): @@ -97,19 +99,19 @@ def do_optimise(args): raise UsageError(_("Cache directory should be named 'implementations', not\n" "'%(name)s' (in '%(cache_dir)s')") % {'name': impl_name, 'cache_dir': cache_dir}) - print _("Optimising"), cache_dir + print(_("Optimising"), cache_dir) from . import optimise uniq_size, dup_size, already_linked, man_size = optimise.optimise(cache_dir) - print _("Original size : %(size)s (excluding the %(manifest_size)s of manifests)") % {'size': support.pretty_size(uniq_size + dup_size), 'manifest_size': support.pretty_size(man_size)} - print _("Already saved : %s") % support.pretty_size(already_linked) + print(_("Original size : %(size)s (excluding the %(manifest_size)s of manifests)") % {'size': support.pretty_size(uniq_size + dup_size), 'manifest_size': support.pretty_size(man_size)}) + print(_("Already saved : %s") % support.pretty_size(already_linked)) if dup_size == 0: - print _("No duplicates found; no changes made.") + print(_("No duplicates found; no changes made.")) else: - print _("Optimised size : %s") % support.pretty_size(uniq_size) + print(_("Optimised size : %s") % support.pretty_size(uniq_size)) perc = (100 * float(dup_size)) / (uniq_size + dup_size) - print _("Space freed up : %(size)s (%(percentage).2f%%)") % {'size': support.pretty_size(dup_size), 'percentage': perc} - print _("Optimisation complete.") + print(_("Space freed up : %(size)s (%(percentage).2f%%)") % {'size': support.pretty_size(dup_size), 'percentage': perc}) + print(_("Optimisation complete.")) def do_verify(args): """verify (DIGEST | (DIRECTORY [DIGEST])""" @@ -122,15 +124,15 @@ def do_verify(args): else: raise UsageError(_("Missing DIGEST or DIRECTORY")) - print _("Verifying"), root + print(_("Verifying"), root) try: verify(root, required_digest) - print _("OK") + print(_("OK")) except zerostore.BadDigest as ex: - print str(ex) + print(str(ex)) if ex.detail: - print - print ex.detail + print() + print(ex.detail) sys.exit(1) def do_audit(args): @@ -154,46 +156,46 @@ def do_audit(args): failures = [] i = 0 for root, impls in audit_ls: - print _("Scanning %s") % root + print(_("Scanning %s") % root) for required_digest in impls: i += 1 path = os.path.join(root, required_digest) if '=' not in required_digest: - print _("Skipping non-implementation directory %s") % path + print(_("Skipping non-implementation directory %s") % path) continue try: msg = _("[%(done)d / %(total)d] Verifying %(digest)s") % {'done': i, 'total': total, 'digest': required_digest} - print msg, + print(msg, end=' ') sys.stdout.flush() verify(path, required_digest) - print "\r" + (" " * len(msg)) + "\r", + print("\r" + (" " * len(msg)) + "\r", end=' ') verified += 1 except zerostore.BadDigest as ex: - print + print() failures.append(path) - print str(ex) + print(str(ex)) if ex.detail: - print - print ex.detail + print() + print(ex.detail) if failures: - print '\n' + _("List of corrupted or modified implementations:") + print('\n' + _("List of corrupted or modified implementations:")) for x in failures: - print x - print - print _("Checked %d items") % i - print _("Successfully verified implementations: %d") % verified - print _("Corrupted or modified implementations: %d") % len(failures) + print(x) + print() + print(_("Checked %d items") % i) + print(_("Successfully verified implementations: %d") % verified) + print(_("Corrupted or modified implementations: %d") % len(failures)) if failures: sys.exit(1) def do_list(args): """list""" if args: raise UsageError(_("List takes no arguments")) - print _("User store (writable) : %s") % stores.stores[0].dir + print(_("User store (writable) : %s") % stores.stores[0].dir) for s in stores.stores[1:]: - print _("System store : %s") % s.dir + print(_("System store : %s") % s.dir) if len(stores.stores) < 2: - print _("No system stores.") + print(_("No system stores.")) def get_stored(dir_or_digest): if os.path.isdir(dir_or_digest): @@ -202,7 +204,7 @@ def get_stored(dir_or_digest): try: return stores.lookup(dir_or_digest) except zerostore.NotStored as ex: - print >>sys.stderr, ex + print(ex, file=sys.stderr) sys.exit(1) def do_copy(args): -- 2.11.4.GIT