Use Python 3 print function

This is updated in all files for consistency, even the modules that will
never be ported to Py 3 completely due to dependency on Yum.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2017-08-23 09:39:17 +02:00
parent c14c28a157
commit ec39514fba
6 changed files with 35 additions and 24 deletions

View File

@ -11,6 +11,8 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <https://gnu.org/licenses/>.
from __future__ import print_function
import os
import selinux
import sys
@ -38,18 +40,18 @@ def main():
# You must be this high to ride if you're going to do root tasks
if os.geteuid() != 0 and (opts.do_all or opts.do_buildinstall):
print >> sys.stderr, "You must run pungi as root"
print("You must run pungi as root", file=sys.stderr)
return 1
if opts.do_all or opts.do_buildinstall:
try:
enforcing = selinux.security_getenforce()
except:
print >> sys.stdout, "INFO: selinux disabled"
print("INFO: selinux disabled")
enforcing = False
if enforcing:
print >> sys.stdout, "WARNING: SELinux is enforcing. This may lead to a compose with selinux disabled."
print >> sys.stdout, "Consider running with setenforce 0."
print("WARNING: SELinux is enforcing. This may lead to a compose with selinux disabled.")
print("Consider running with setenforce 0.")
# Set up the kickstart parser and pass in the kickstart file we were handed
ksparser = pungi.ks.get_ksparser(ks_path=opts.config)
@ -70,19 +72,21 @@ def main():
try:
os.makedirs(config.get('pungi', 'destdir'))
except OSError:
print >> sys.stderr, "Error: Cannot create destination dir %s" % config.get('pungi', 'destdir')
print("Error: Cannot create destination dir %s" % config.get('pungi', 'destdir'),
file=sys.stderr)
sys.exit(1)
else:
print >> sys.stdout, "Warning: Reusing existing destination directory."
print("Warning: Reusing existing destination directory.")
if not os.path.exists(config.get('pungi', 'workdirbase')):
try:
os.makedirs(config.get('pungi', 'workdirbase'))
except OSError:
print >> sys.stderr, "Error: Cannot create working base dir %s" % config.get('pungi', 'workdirbase')
print("Error: Cannot create working base dir %s" % config.get('pungi', 'workdirbase'),
file=sys.stderr)
sys.exit(1)
else:
print >> sys.stdout, "Warning: Reusing existing working base directory."
print("Warning: Reusing existing working base directory.")
cachedir = config.get('pungi', 'cachedir')
@ -90,7 +94,7 @@ def main():
try:
os.makedirs(cachedir)
except OSError:
print >> sys.stderr, "Error: Cannot create cache dir %s" % cachedir
print("Error: Cannot create cache dir %s" % cachedir, file=sys.stderr)
sys.exit(1)
# Set debuginfo flag
@ -172,11 +176,11 @@ def main():
else:
mypungi.downloadSRPMs()
print "RPM size: %s MiB" % (mypungi.size_packages() / 1024 ** 2)
print("RPM size: %s MiB" % (mypungi.size_packages() / 1024 ** 2))
if not opts.nodebuginfo:
print "DEBUGINFO size: %s MiB" % (mypungi.size_debuginfo() / 1024 ** 2)
print("DEBUGINFO size: %s MiB" % (mypungi.size_debuginfo() / 1024 ** 2))
if not opts.nosource:
print "SRPM size: %s MiB" % (mypungi.size_srpms() / 1024 ** 2)
print("SRPM size: %s MiB" % (mypungi.size_srpms() / 1024 ** 2))
# Furthermore (but without the yumlock...)
if not opts.sourceisos:
@ -202,7 +206,7 @@ def main():
if opts.do_all or opts.do_createiso:
mypungi.doCreateIsos()
print "All done!"
print("All done!")
if __name__ == '__main__':
from argparse import ArgumentParser, Action

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import argparse
@ -159,13 +160,13 @@ def _get_url(pkg):
def print_rpms(gather_obj):
for pkg in sorted(gather_obj.result_binary_packages):
print "RPM%s: %s" % (_get_flags(gather_obj, pkg), _get_url(pkg))
print("RPM%s: %s" % (_get_flags(gather_obj, pkg), _get_url(pkg)))
for pkg in sorted(gather_obj.result_debug_packages):
print "DEBUGINFO%s: %s" % (_get_flags(gather_obj, pkg), _get_url(pkg))
print("DEBUGINFO%s: %s" % (_get_flags(gather_obj, pkg), _get_url(pkg)))
for pkg in sorted(gather_obj.result_source_packages):
print "SRPM%s: %s" % (_get_flags(gather_obj, pkg), _get_url(pkg))
print("SRPM%s: %s" % (_get_flags(gather_obj, pkg), _get_url(pkg)))
if __name__ == "__main__":

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
@ -213,10 +214,10 @@ def main():
pungi.checks.check_umask(logger)
errors, warnings = pungi.checks.validate(conf)
for warning in warnings:
print >>sys.stderr, warning
print(warning, file=sys.stderr)
if errors:
for error in errors:
print >>sys.stderr, error
print(error, file=sys.stderr)
fail_to_start('Config validation failed', errors=errors)
sys.exit(1)

View File

@ -20,6 +20,8 @@
# Author: David Cantrell <dcantrell@redhat.com>
# Author: Brian C. Lane <bcl@redhat.com>
from __future__ import print_function
import subprocess
import textwrap
from argparse import ArgumentParser
@ -93,7 +95,7 @@ def main():
args = parser.parse_args()
cl = ChangeLog(args.name, args.version)
print cl.formatLog()
print(cl.formatLog())
if __name__ == "__main__":
main()

View File

@ -35,6 +35,8 @@ When a new config option is added, the schema must be updated (see the
``CONFIG_DEPS`` mapping.
"""
from __future__ import print_function
import contextlib
import os.path
import platform
@ -63,9 +65,8 @@ def is_isohybrid_needed(conf):
if runroot and not _will_productimg_run(conf):
return False
if platform.machine() not in ('x86_64', 'i686', 'i386'):
msg = ('Not checking for /usr/bin/isohybrid due to current architecture. '
'Expect failures in productimg phase.')
print msg
print('Not checking for /usr/bin/isohybrid due to current architecture. '
'Expect failures in productimg phase.')
return False
return True

View File

@ -36,6 +36,8 @@ To print profiling data, run:
Profiler.print_results()
"""
from __future__ import print_function
import functools
import time
@ -65,8 +67,8 @@ class Profiler(object):
@classmethod
def print_results(cls):
print "Profiling results:"
print("Profiling results:")
results = cls._data.items()
results.sort(lambda x, y: cmp(x[1]["time"], y[1]["time"]), reverse=True)
for name, data in results:
print " %6.2f %5d %s" % (data["time"], data["calls"], name)
print(" %6.2f %5d %s" % (data["time"], data["calls"], name))