Convert to python3 style print() syntax

Use __future__ imports to keep this working for python2
This commit is contained in:
Cole Robinson 2017-05-05 14:16:59 -04:00
parent 34c193108c
commit 55288c4551
7 changed files with 56 additions and 44 deletions

View File

@ -78,11 +78,11 @@ class my_build_i18n(distutils.command.build.build):
potpath = "po/POTFILES.in"
try:
print "Writing %s" % potpath
print("Writing %s" % potpath)
file(potpath, "w").write(potfiles)
self._run()
finally:
print "Removing %s" % potpath
print("Removing %s" % potpath)
os.unlink(potpath)
def _run(self):
@ -168,7 +168,7 @@ class my_build(distutils.command.build.build):
wrapper += "exec \"%s\" \"$@\"" % (sharepath)
newpath = os.path.abspath(os.path.join("build", app))
print "Generating %s" % newpath
print("Generating %s" % newpath)
file(newpath, "w").write(wrapper)
@ -179,7 +179,7 @@ class my_build(distutils.command.build.build):
newpath = os.path.join(os.path.dirname(path),
appname + ".1")
print "Generating %s" % newpath
print("Generating %s" % newpath)
ret = os.system('pod2man '
'--center "Virtual Machine Manager" '
'--release %s --name %s '
@ -235,11 +235,11 @@ class my_install(distutils.command.install.install):
def finalize_options(self):
if self.prefix is None:
if CLIConfig.prefix != sysprefix:
print "Using configured prefix=%s instead of sysprefix=%s" % (
CLIConfig.prefix, sysprefix)
print("Using configured prefix=%s instead of sysprefix=%s" % (
CLIConfig.prefix, sysprefix))
self.prefix = CLIConfig.prefix
else:
print "Using sysprefix=%s" % sysprefix
print("Using sysprefix=%s" % sysprefix)
self.prefix = sysprefix
elif self.prefix != CLIConfig.prefix:
@ -367,7 +367,7 @@ class configure(distutils.core.Command):
template += "default_hvs = %s\n" % self.default_hvs
file(CLIConfig.cfgpath, "w").write(template)
print "Generated %s" % CLIConfig.cfgpath
print("Generated %s" % CLIConfig.cfgpath)
class TestBaseCommand(distutils.core.Command):
@ -442,7 +442,7 @@ class TestBaseCommand(distutils.core.Command):
try:
unittest.installHandler()
except:
print "installHandler hack failed"
print("installHandler hack failed")
tests = unittest.TestLoader().loadTestsFromNames(self._testfiles)
if self.only:
@ -454,13 +454,13 @@ class TestBaseCommand(distutils.core.Command):
newtests.append(testcase)
if not newtests:
print "--only didn't find any tests"
print("--only didn't find any tests")
sys.exit(1)
tests = unittest.TestSuite(newtests)
print "Running only:"
print("Running only:")
for test in newtests:
print "%s" % test
print
print("%s" % test)
print()
t = unittest.TextTestRunner(verbosity=self.debug and 2 or 1)
@ -582,14 +582,14 @@ class CheckPylint(distutils.core.Command):
output_format = sys.stdout.isatty() and "colorized" or "text"
exclude = ["virtinst/progress.py"]
print "running pep8"
print("running pep8")
cmd = "pep8 "
cmd += "--config tests/pep8.cfg "
cmd += "--exclude %s " % ",".join(exclude)
cmd += " ".join(files)
os.system(cmd)
print "running pylint"
print("running pylint")
cmd = "pylint "
cmd += "--rcfile tests/pylint.cfg "
cmd += "--output-format=%s " % output_format

View File

@ -1,6 +1,8 @@
#!/usr/bin/env python2
# Copyright (C) 2013, 2014 Red Hat, Inc.
from __future__ import print_function
import atexit
import os
import sys
@ -78,7 +80,7 @@ atexit.register(exit_cleanup)
def _fetch_distro(distro):
print "Fetching distro=%s" % distro.name
print("Fetching distro=%s" % distro.name)
fetcher = urlfetcher.fetcherForURI(distro.url, "/tmp", meter)
origenv = os.environ.pop("VIRTINST_TEST_SUITE")
@ -91,7 +93,7 @@ def _fetch_distro(distro):
distro.kernel = kernel
distro.initrd = initrd
except Exception as e:
print "fetching distro=%s failed: %s" % (distro.name, e)
print("fetching distro=%s failed: %s" % (distro.name, e))
finally:
fetcher.cleanupLocation()
if origenv:
@ -100,17 +102,17 @@ def _fetch_distro(distro):
def _test_distro(distro):
os.system("clear")
print "\n"
print("\n")
if distro.warntype == WARN_RHEL4:
print "RHEL4: Makes its way to the text installer, then chokes "
print "on our bogus URI http://HEY-THIS-IS-OUR-BAD-KICKSTART-URL.com/"
print("RHEL4: Makes its way to the text installer, then chokes ")
print("on our bogus URI http://HEY-THIS-IS-OUR-BAD-KICKSTART-URL.com/")
elif distro.warntype == WARN_RHEL5:
print "RHEL5, RHEL6, Fedora < 17: You'll get an error about a "
print "bogus bootproto ITREADTHEKICKSTART. This means anaconda "
print "read our busted kickstart."
print("RHEL5, RHEL6, Fedora < 17: You'll get an error about a ")
print("bogus bootproto ITREADTHEKICKSTART. This means anaconda ")
print("read our busted kickstart.")
else:
print "RHEL7, Fedora >= 17: Chokes on the bogus URI in the early "
print "console screen when fetching the installer squashfs image."
print("RHEL7, Fedora >= 17: Chokes on the bogus URI in the early ")
print("console screen when fetching the installer squashfs image.")
originitrd = distro.initrd
kernel = distro.kernel
@ -128,7 +130,7 @@ def _test_distro(distro):
"-net bridge,br=virbr0 -net nic,model=%s "
"-kernel %s -initrd %s %s" %
(distro.name, nic, kernel, newinitrd, append))
print "\n\n" + cmd
print("\n\n" + cmd)
os.system(cmd)
@ -142,7 +144,7 @@ class FetchTests(unittest.TestCase):
global _printfetch
if _printfetch:
return
print """
print ("""
@ -152,7 +154,7 @@ First step is we need to go and fetch a bunch of distro kernel/initrd
from public trees. This is going to take a while. Let it run then come
back later and we will be waiting to continue.
"""
""")
prompt()
_printfetch = True
@ -163,7 +165,7 @@ class InjectTests(unittest.TestCase):
if _printinitrd:
return
print """
print("""
Okay, we have all the media. We are going to perform the initrd injection
@ -171,7 +173,7 @@ of some broken kickstarts, then manually launch a qemu instance to verify
the kickstart is detected. How you know it's working depends on the distro.
When each test launches, we will print the manual verification instructions.
"""
""")
prompt()
_printinitrd = True

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import os
import re
import time
@ -42,7 +44,7 @@ class _FuzzyPredicate(dogtail.predicate.Predicate):
return
return True
except Exception as e:
print "got predicate exception: %s" % e
print("got predicate exception: %s" % e)
@ -158,9 +160,9 @@ def print_nodes(root):
"""
def _walk(node):
try:
print node_string(node)
print(node_string(node))
except Exception as e:
print "got exception: %s" % e
print("got exception: %s" % e)
root.findChildren(_walk, isLambda=True)
@ -174,6 +176,6 @@ def focused_nodes(root):
if node.focused:
return node
except Exception as e:
print "got exception: %s" % e
print("got exception: %s" % e)
return root.findChildren(_walk, isLambda=True)

View File

@ -15,6 +15,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
from __future__ import print_function
import glob
import os
import StringIO
@ -33,7 +35,7 @@ class TestVirtConv(unittest.TestCase):
def _convert_helper(self, infile, outfile, in_type, disk_format):
outbuf = StringIO.StringIO()
def print_cb(msg):
print >> outbuf, msg
print(msg, file=outbuf)
converter = VirtConverter(conn, infile, print_cb=print_cb)

View File

@ -19,6 +19,8 @@
# MA 02110-1301 USA.
#
from __future__ import print_function
import argparse
import logging
import os
@ -44,7 +46,7 @@ warnings.simplefilter("ignore")
try:
gi.check_version("3.14.0")
except (ValueError, AttributeError):
print "pygobject3 3.14.0 or later is required."
print("pygobject3 3.14.0 or later is required.")
sys.exit(1)
@ -76,7 +78,7 @@ def _import_gtk(leftovers):
leftovers = sys.argv[1:]
if Gtk.check_version(3, 14, 0):
print "gtk3 3.14.0 or later is required."
print("gtk3 3.14.0 or later is required.")
sys.exit(1)
# This will error if Gtk wasn't correctly initialized
@ -94,7 +96,7 @@ def _import_gtk(leftovers):
if display:
msg += ": Could not open display: %s" % display
logging.debug("".join(traceback.format_exc()))
print msg
print(msg)
sys.exit(1)
finally:
sys.argv = origargv

View File

@ -19,6 +19,8 @@
# MA 02110-1301 USA.
#
from __future__ import print_function
from distutils.spawn import find_executable
import logging
import os
@ -202,7 +204,7 @@ class VirtConverter(object):
if print_cb == -1 or print_cb is None:
def cb(msg):
if print_cb == -1:
print msg
print(msg)
self.print_cb = cb
else:
self.print_cb = print_cb

View File

@ -19,6 +19,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
from __future__ import print_function
import argparse
import collections
import logging
@ -321,12 +323,12 @@ def fail(msg, do_exit=True):
def print_stdout(msg, do_force=False):
if do_force or not get_global_state().quiet:
print msg
print(msg)
def print_stderr(msg):
logging.debug(msg)
print >> sys.stderr, msg
print(msg, file=sys.stderr)
def _fail_exit():
@ -1101,10 +1103,10 @@ class VirtCLIParser(object):
"""
Print out all _param names, triggered via ex. --disk help
"""
print "--%s options:" % cls.cli_arg_name
print("--%s options:" % cls.cli_arg_name)
for arg in sorted(cls._virtargs, key=lambda p: p.cliname):
print " %s" % arg.cliname
print
print(" %s" % arg.cliname)
print()
def __init__(self, guest, optstr):