← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-scripts-print-function into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-scripts-print-function into launchpad:master.

Commit message:
Port several scripts to print_function

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/393758
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-scripts-print-function into launchpad:master.
diff --git a/scripts/branch-rewrite.py b/scripts/branch-rewrite.py
index f69d61d..2583d0c 100755
--- a/scripts/branch-rewrite.py
+++ b/scripts/branch-rewrite.py
@@ -10,6 +10,8 @@ documentation of the very simple 'protocol' Apache uses to talk to us, and
 lp.codehosting.rewrite.BranchRewriter for the logic of the rewritemap.
 """
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 import _pythonpath
 
 import os
@@ -57,7 +59,7 @@ class BranchRewriteScript(LaunchpadScript):
                 transaction.abort()
                 # Mod-rewrite always gives us a newline terminated string.
                 if line:
-                    print rewriter.rewriteLine(line.strip())
+                    print(rewriter.rewriteLine(line.strip()))
                 else:
                     # Standard input has been closed, so die.
                     return
@@ -65,7 +67,7 @@ class BranchRewriteScript(LaunchpadScript):
                 sys.exit()
             except Exception:
                 self.logger.exception('Exception occurred:')
-                print "NULL"
+                print("NULL")
                 # The exception might have been a DisconnectionError or
                 # similar. Cleanup such as database reconnection will
                 # not happen until the transaction is rolled back.
diff --git a/scripts/get-stacked-on-branches.py b/scripts/get-stacked-on-branches.py
index 04103e6..439af1a 100755
--- a/scripts/get-stacked-on-branches.py
+++ b/scripts/get-stacked-on-branches.py
@@ -21,6 +21,8 @@ format:
 This script is intended to be used in conjunction with "update-stacked-on.py".
 """
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 __metaclass__ = type
 
 import _pythonpath
@@ -52,9 +54,9 @@ def main():
     execute_zcml_for_scripts()
     for db_branch in get_stacked_branches():
         stacked_on = db_branch.stacked_on
-        print '%s %s %s %s %s' % (
+        print('%s %s %s %s %s' % (
             db_branch.id, db_branch.branch_type.name, db_branch.unique_name,
-            stacked_on.id, stacked_on.unique_name)
+            stacked_on.id, stacked_on.unique_name))
 
 
 if __name__ == '__main__':
diff --git a/scripts/librarian-report.py b/scripts/librarian-report.py
index 3922425..10b801d 100755
--- a/scripts/librarian-report.py
+++ b/scripts/librarian-report.py
@@ -5,6 +5,8 @@
 
 """Report a breakdown of Librarian disk space usage."""
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 __metaclass__ = type
 __all__ = []
 
@@ -96,7 +98,7 @@ def main():
 
     for total_bytes, tab_name, formatted_size, num_files in sorted(
         totals, reverse=True):
-        print '%-10s %s in %d files' % (formatted_size, tab_name, num_files)
+        print('%-10s %s in %d files' % (formatted_size, tab_name, num_files))
 
     return 0
 
diff --git a/scripts/memcached-stats.py b/scripts/memcached-stats.py
index 86c765d..665c3dd 100755
--- a/scripts/memcached-stats.py
+++ b/scripts/memcached-stats.py
@@ -4,6 +4,8 @@
 
 """Output memcached statistics."""
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 __metaclass__ = type
 __all__ = []
 
@@ -42,29 +44,29 @@ def get_summary(all_raw_stats):
 
 def print_stats(stats):
     """Output human readable statistics."""
-    print dedent('''\
+    print(dedent('''\
             Sets:          %(cmd_set)s
             Hits:          %(get_hits)s
             Misses:        %(get_misses)s
             Evictions:     %(evictions)s
             Bytes read:    %(bytes_read)s
             Bytes written: %(bytes_written)s
-            ''' % stats)
+            ''' % stats))
 
 
 def print_summary(all_raw_stats):
     """Output the summary in a human readable format."""
     summary = get_summary(all_raw_stats)
-    print "Totals\n======\n"
+    print("Totals\n======\n")
     print_stats(summary)
 
 
 def print_full(all_raw_stats):
     """Output stats for individual servers in a human readable format."""
     for server, stats in all_raw_stats:
-        print server
-        print "="*len(server)
-        print
+        print(server)
+        print("=" * len(server))
+        print()
         print_stats(stats)
 
 
@@ -73,15 +75,15 @@ def print_cricket(all_raw_stats):
     summary = get_summary(all_raw_stats)
     now = time.time()
     for key in INTERESTING_KEYS:
-        print 'memcached_total_%s:%s@%d' % (
-            key, summary[key], now)
+        print('memcached_total_%s:%s@%d' % (
+            key, summary[key], now))
     for server, stats in all_raw_stats:
         # Convert the '127.0.0.1:11217 (1)' style server string to a
         # cricket key.
         server = server.split()[0].replace(':','_').replace('.','_')
         for key in INTERESTING_KEYS:
-            print 'memcached_%s_%s:%s@%d' % (
-                server, key, stats[key], now)
+            print('memcached_%s_%s:%s@%d' % (
+                server, key, stats[key], now))
 
 
 def main():
diff --git a/scripts/migrate-librarian-content-md5.py b/scripts/migrate-librarian-content-md5.py
index 6dd3b9a..0a1b7c8 100755
--- a/scripts/migrate-librarian-content-md5.py
+++ b/scripts/migrate-librarian-content-md5.py
@@ -5,6 +5,8 @@
 
 """Script to generate SQL to add MD5 sums for existing librarian files."""
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 __metaclass__ = type
 
 import _pythonpath
@@ -44,4 +46,4 @@ if __name__ == '__main__':
     else:
         minimumID = 0
     for databaseID, md5sum in main(sys.argv[1], minimumID):
-        print SQL % (md5sum, databaseID)
+        print(SQL % (md5sum, databaseID))
diff --git a/scripts/script-monitor-nagios.py b/scripts/script-monitor-nagios.py
index f87a6f2..68e6307 100755
--- a/scripts/script-monitor-nagios.py
+++ b/scripts/script-monitor-nagios.py
@@ -18,6 +18,8 @@ As such, it was felt more appropriate to separate out the scripts,
 even though there is some code duplication.
 """
 
+from __future__ import absolute_import, print_function, unicode_literals
+
 __metaclass__ = type
 __all__ = ['check_script']
 
@@ -54,8 +56,7 @@ def main():
     (options, args) = parser.parse_args()
 
     if len(args) < 2:
-        print "Must specify time in minutes and " \
-            "at least one host and script"
+        print("Must specify time in minutes and at least one host and script")
         return 3
 
     # First argument is the number of minutes into the past
@@ -73,12 +74,11 @@ def main():
             try:
                 hostname, scriptname = arg.split(':')
             except TypeError:
-                print "%r is not in the format 'host:scriptname'" % arg
+                print("%r is not in the format 'host:scriptname'" % arg)
                 return 3
             hosts_scripts.append((hostname, scriptname))
     except ValueError:
-        print "Must specify time in minutes and " \
-            "at least one host and script"
+        print("Must specify time in minutes and at least one host and script")
         return 3
 
     log = logger(options)
@@ -96,16 +96,16 @@ def main():
                 error_found = True
         if error_found:
             # Construct our return message
-            print "Scripts failed to run: %s" % ', '.join(msg)
+            print("Scripts failed to run: %s" % ', '.join(msg))
             return 2
         else:
             # Construct our return message
-            print "All scripts ran as expected"
+            print("All scripts ran as expected")
             return 0
     except Exception as e:
         # Squeeze the exception type and stringification of the exception
         # value on to one line.
-        print "Unhandled exception: %s %r" % (e.__class__.__name__, str(e))
+        print("Unhandled exception: %s %r" % (e.__class__.__name__, str(e)))
         return 3
 
 if __name__ == '__main__':