[Piuparts-commits] [piuparts] 03/05: make print statements py3 compatible

Holger Levsen holger at moszumanska.debian.org
Mon Apr 27 15:12:48 UTC 2015


This is an automated email from the git hooks/post-receive script.

holger pushed a commit to branch develop
in repository piuparts.

commit e285deaf44009790fe12d5aef6a81a22d8d89230
Author: Börni <boerni at gmail.com>
Date:   Sun Apr 19 16:36:25 2015 +0200

    make print statements py3 compatible
---
 piuparts-analyze.py       | 18 +++++++++---------
 piuparts-slave.py         | 22 +++++++++++-----------
 piuparts.py               | 12 +++++++-----
 piupartslib/pkgsummary.py |  2 +-
 4 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/piuparts-analyze.py b/piuparts-analyze.py
index a7afa7b..953e9df 100644
--- a/piuparts-analyze.py
+++ b/piuparts-analyze.py
@@ -151,7 +151,7 @@ def write_bug_file(failed_log, bugs):
 
 
 def move_to_bugged(failed_log, bugged="bugged", bug=None):
-    print("Moving %s to %s (#%s)" % (failed_log, bugged, bug))
+    print(("Moving %s to %s (#%s)" % (failed_log, bugged, bug)))
     os.rename(failed_log, os.path.join(bugged, os.path.basename(failed_log)))
     if bug is not None:
         write_bug_file(os.path.join(bugged, os.path.basename(failed_log)), [bug])
@@ -170,7 +170,7 @@ def mark_bugged_version(failed_log, bugged_log):
 def bts_update_found(bugnr, newversion):
     if "DEBEMAIL" in os.environ and os.environ["DEBEMAIL"]:
         # subprocess.check_call(('bts', 'found', bugnr, newversion))
-        print(' '.join(('bts', 'found', str(bugnr), newversion)))
+        print((' '.join(('bts', 'found', str(bugnr), newversion))))
 
 
 def mark_logs_with_reported_bugs():
@@ -199,8 +199,8 @@ def mark_logs_with_reported_bugs():
                 if apt_pkg.version_compare(pversion, bug_version) > 0:  # pversion > bug_version
                     bugged_logs = find_bugged_logs(failed_log)
                     if not bugged_logs and not moved:
-                        print('%s/%s: Maybe the bug was filed earlier: https://bugs.debian.org/%d against %s/%s'
-                              % (pname, pversion, bug, pname, bug_version))
+                        print(('%s/%s: Maybe the bug was filed earlier: https://bugs.debian.org/%d against %s/%s'
+                              % (pname, pversion, bug, pname, bug_version)))
                         break
                     for bugged_log in bugged_logs:
                         old_pversion = package_source_version(bugged_log)
@@ -228,18 +228,18 @@ def report_packages_with_many_logs():
     for package, failed_logs in packages.iteritems():
         printed = False
         if len(failed_logs) > 1:
-            print "Many failures:"
+            print("Many failures:")
             for failed_log in failed_logs:
-                print "  ", failed_log
+                print("  ", failed_log)
             printed = True
         bugged_logs = find_bugged_logs(failed_logs[0])
         if bugged_logs:
-            print "Already bugged?"
+            print("Already bugged?")
             for failed_log in failed_logs + bugged_logs:
-                print "  ", failed_log
+                print("  ", failed_log)
             printed = True
         if printed:
-            print
+            print()
 
 
 piuparts_usertags_cache = None
diff --git a/piuparts-slave.py b/piuparts-slave.py
index ec2d76c..5536ba5 100644
--- a/piuparts-slave.py
+++ b/piuparts-slave.py
@@ -113,15 +113,15 @@ def alarm_handler(signum, frame):
 def sigint_handler(signum, frame):
     global interrupted
     interrupted = True
-    print '\nSlave interrupted by the user, waiting for the current test to finish.'
-    print 'Press Ctrl-C again to abort now.'
+    print('\nSlave interrupted by the user, waiting for the current test to finish.')
+    print('Press Ctrl-C again to abort now.')
     signal(SIGINT, old_sigint_handler)
 
 
 def sighup_handler(signum, frame):
     global got_sighup
     got_sighup = True
-    print 'SIGHUP: Will flush finished logs.'
+    print('SIGHUP: Will flush finished logs.')
 
 
 class MasterIsBusy(Exception):
@@ -773,7 +773,7 @@ def run_test_with_timeout(cmd, maxwait, kill_all=True):
             stdout, stderr = ps.communicate()
             pids.extend([int(pid) for pid in stdout.split()])
         if p.poll() is None:
-            print 'Sending SIGINT...'
+            print('Sending SIGINT...')
             try:
                 os.killpg(os.getpgid(p.pid), SIGINT)
             except OSError:
@@ -784,7 +784,7 @@ def run_test_with_timeout(cmd, maxwait, kill_all=True):
                 if p.poll() is not None:
                     break
         if p.poll() is None:
-            print 'Sending SIGTERM...'
+            print('Sending SIGTERM...')
             p.terminate()
             # piuparts has 5 seconds to clean up after SIGTERM
             for i in range(10):
@@ -792,13 +792,13 @@ def run_test_with_timeout(cmd, maxwait, kill_all=True):
                 if p.poll() is not None:
                     break
         if p.poll() is None:
-            print 'Sending SIGKILL...'
+            print('Sending SIGKILL...')
             p.kill()
         for pid in pids:
             if pid > 0:
                 try:
                     os.kill(pid, SIGKILL)
-                    print "Killed %d" % pid
+                    print("Killed %d" % pid)
                 except OSError:
                     pass
 
@@ -817,11 +817,11 @@ def run_test_with_timeout(cmd, maxwait, kill_all=True):
         terminate_subprocess(p, kill_all)
         return -1, stdout
     except KeyboardInterrupt:
-        print '\nSlave interrupted by the user, cleaning up...'
+        print('\nSlave interrupted by the user, cleaning up...')
         try:
             terminate_subprocess(p, kill_all)
         except KeyboardInterrupt:
-            print '\nTerminating piuparts was interrupted... manual cleanup still neccessary.'
+            print('\nTerminating piuparts was interrupted... manual cleanup still neccessary.')
             raise
         raise
 
@@ -950,8 +950,8 @@ if __name__ == "__main__":
     try:
         main()
     except KeyboardInterrupt:
-        print ''
-        print 'Slave interrupted by the user, exiting...'
+        print('')
+        print('Slave interrupted by the user, exiting...')
         sys.exit(1)
 
 # vi:set et ts=4 sw=4 :
diff --git a/piuparts.py b/piuparts.py
index 450d09d..6b6720b 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -31,6 +31,8 @@ more usage information.
 Lars Wirzenius <liw at iki.fi>
 """
 
+from __future__ import print_function
+
 
 VERSION = "__PIUPARTS_VERSION__"
 
@@ -1690,7 +1692,7 @@ class VirtServ(Chroot):
                 return urllib.quote(a)
             cmd = ' '.join(map(maybe_quote, cmd))
         logging.debug('adt-virt >> %s', cmd)
-        print >>self._vs.stdin, cmd
+        print(cmd, file=self._vs.stdin)
         return cmd.split(' ')[0]
 
     def _command(self, cmd):
@@ -1804,7 +1806,7 @@ class VirtServ(Chroot):
         cmdl = ['sh', '-ec', 'cd /\n' + ' '.join(command)]
         (es, stdout, stderr) = self._execute(cmdl, tolerate_errors=True)
         stdout_data = self._getfilecontents(stdout)
-        print >>sys.stderr, "VirtServ run", repr(command), repr(cmdl), '==>', repr(es), repr(stdout), repr(stderr), '|', stdout_data
+        print("VirtServ run", repr(command), repr(cmdl), '==>', repr(es), repr(stdout), repr(stderr), '|', stdout_data, file=sys.stderr)
         if es == 0 or ignore_errors:
             return (es, stdout_data)
         stderr_data = self._getfilecontents(stderr)
@@ -3081,7 +3083,7 @@ def main():
 
     # check if user has root privileges
     if os.getuid():
-        print 'You need to be root to use piuparts.'
+        print('You need to be root to use piuparts.')
         sys.exit(1)
 
     logging.info("-" * 78)
@@ -3129,8 +3131,8 @@ if __name__ == "__main__":
     try:
         main()
     except KeyboardInterrupt:
-        print ''
-        print 'Piuparts interrupted by the user, exiting...'
+        print('')
+        print('Piuparts interrupted by the user, exiting...')
         panic(1)
         sys.exit(1)
 
diff --git a/piupartslib/pkgsummary.py b/piupartslib/pkgsummary.py
index 1c45fe9..6e4ac2d 100644
--- a/piupartslib/pkgsummary.py
+++ b/piupartslib/pkgsummary.py
@@ -240,4 +240,4 @@ if __name__ == '__main__':
     for pkg in summary['packages']:
         flag, blocked, url = summary['packages'][pkg][DEFSEC]
 
-        print pkg, flag, url, tooltip(summary, pkg)
+        print(pkg, flag, url, tooltip(summary, pkg))

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/piuparts/piuparts.git



More information about the Piuparts-commits mailing list