Don't use print as a statement
authorGuido Günther <agx@sigxcpu.org>
Thu, 19 Feb 2015 10:29:43 +0000 (11:29 +0100)
committerGuido Günther <agx@sigxcpu.org>
Fri, 20 Feb 2015 11:39:00 +0000 (12:39 +0100)
via

    2to3-3.4 -w  -f print .

to work towards python3 support

Gbp-Dch: Ignore

examples/zeitgeist-git.py
gbp/deb/changelog.py
gbp/scripts/create_remote_repo.py
gbp/scripts/dch.py
gbp/scripts/import_dscs.py
gbp/scripts/supercommand.py
tests/09_test_write_tree.py

index 4edd94616365baecf412ac4bd42b8c354741772f..33114cdee349c48286802a6dc395bed8ccccb593 100755 (executable)
@@ -48,7 +48,7 @@ else:
     try:
         CLIENT = ZeitgeistClient()
     except RuntimeError as e:
-        print "Unable to connect to Zeitgeist, won't send events. Reason: '%s'" %e
+        print("Unable to connect to Zeitgeist, won't send events. Reason: '%s'" %e)
 
 
 def get_repo():
index b3c56efe8744e8dca52dd779409a616c2e282897..631b5a66d41ed922ff8f20dd313da248685e8b9e 100644 (file)
@@ -16,6 +16,8 @@
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 """A Debian Changelog"""
 
+from __future__ import print_function
+
 import email
 import os
 import subprocess
@@ -266,11 +268,11 @@ class ChangeLog(object):
             new_cl = open("debian/changelog.bak", "w")
             for line in old_cl:
                 if line == "  * [[[insert-git-dch-commit-message-here]]]\n":
-                    print >> new_cl, "  * " + msg[0]
+                    print("  * " + msg[0], file=new_cl)
                     for line in msg[1:]:
-                        print >> new_cl, "    " + line
+                        print("    " + line, file=new_cl)
                 else:
-                    print >> new_cl, line,
+                    print(line, file=new_cl)
             os.rename("debian/changelog.bak", "debian/changelog")
 
     def add_entry(self, msg, author=None, email=None, dch_options=[]):
index b4d43c95d0f4531d7c53feed56de24a40f3fbbfd..fd74dcaad8c0fe3b13331beb5f0399cb80344cf1 100644 (file)
@@ -18,6 +18,8 @@
 # Based on the aa-create-git-repo and dom-new-git-repo shell scripts
 """Create a remote Git repository based on the current one"""
 
+from __future__ import print_function
+
 import ConfigParser
 import sys
 import os, os.path
@@ -51,17 +53,17 @@ def print_config(remote, branches):
             merge = refs/heads/bar
     """
 
-    print """[remote "%(name)s"]
+    print("""[remote "%(name)s"]
         url = %(url)s
-        fetch = +refs/heads/*:refs/remotes/%(name)s/*""" % remote
+        fetch = +refs/heads/*:refs/remotes/%(name)s/*""" % remote)
 
     for branch in branches:
-        print "        push = %s" % branch
+        print("        push = %s" % branch)
 
     for branch in branches:
-        print """[branch "%s"]
+        print("""[branch "%s"]
         remote = %s
-        merge = refs/heads/%s""" % (branch, remote['name'], branch)
+        merge = refs/heads/%s""" % (branch, remote['name'], branch))
 
 def sort_dict(d):
     """Return a sorted list of (key, value) tuples"""
@@ -306,7 +308,7 @@ def main(argv):
     try:
         options, args = parse_args(argv)
     except Exception as e:
-        print >>sys.stderr, "%s" % e
+        print("%s" % e, file=sys.stderr)
         return 1
 
     gbp.log.setup(options.color, options.verbose, options.color_scheme)
@@ -350,11 +352,11 @@ def main(argv):
 
         remote_script = build_remote_script(remote, branches[0])
         if options.verbose:
-            print remote_script
+            print(remote_script)
 
         cmd = build_cmd(remote)
         if options.verbose:
-            print cmd
+            print(cmd)
 
         proc = subprocess.Popen(cmd, stdin=subprocess.PIPE)
         proc.communicate(remote_script)
index e725bb15f201c8aaa6814c210917e41369ac5e19..b6c77b1a65727019aba766ab46bffc52d9ad797f 100644 (file)
@@ -17,6 +17,8 @@
 #
 """Generate Debian changelog entries from Git commit messages"""
 
+from __future__ import print_function
+
 import ConfigParser
 import os.path
 import re
@@ -137,8 +139,8 @@ def mangle_changelog(changelog, cp, snapshot=''):
         cw = open(tmpfile, 'w')
         cr = open(changelog, 'r')
 
-        print >>cw, ("%(Source)s (%(MangledVersion)s) "
-                     "%(Distribution)s; urgency=%(urgency)s\n" % cp)
+        print("%(Source)s (%(MangledVersion)s) "
+                    "%(Distribution)s; urgency=%(urgency)s\n" % cp, file=cw)
 
         cr.readline() # skip version and empty line
         cr.readline()
@@ -148,10 +150,10 @@ def mangle_changelog(changelog, cp, snapshot=''):
             line = ''
 
         if snapshot:
-            print >>cw, "  ** SNAPSHOT build @%s **\n" % snapshot
+            print("  ** SNAPSHOT build @%s **\n" % snapshot, file=cw)
 
         if line:
-            print >>cw, line.rstrip()
+            print(line.rstrip(), file=cw)
         shutil.copyfileobj(cr, cw)
         cw.close()
         cr.close()
index 9219ba07d55a90296759c5eb72db8aa8d87fd8c8..440cec2c7020f2ee622aaad0e08dceebc2a98c83 100644 (file)
@@ -79,13 +79,13 @@ def set_gbp_conf_files():
     gbp.log.debug("Setting GBP_CONF_FILES to '%s'" % gbp_conf_files)
 
 def print_help():
-    print """Usage: gbp import-dscs [options] [gbp-import-dsc options] /path/to/dsc1 [/path/to/dsc2] ...
+    print("""Usage: gbp import-dscs [options] [gbp-import-dsc options] /path/to/dsc1 [/path/to/dsc2] ...
        gbp import-dscs --debsnap [options] [gbp-import-dsc options] package
 
 Options:
 
     --ignore-repo-config: ignore gbp.conf in git repo
-"""
+""")
 
 
 def main(argv):
index 83c8446b93cd20ec315ff27d7f94543b3499dcf6..a120ae5cae079739362b6b682579726889c493cd 100644 (file)
@@ -17,6 +17,8 @@
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 """Supercommand for all gbp commands"""
 
+from __future__ import print_function
+
 import glob
 import os
 import re
@@ -34,7 +36,7 @@ def sanitize(cmd):
     return cmd.replace('-', '_')
 
 def usage():
-    print """
+    print("""
 Usage:
     gbp <command> [<args>]
 
@@ -46,7 +48,7 @@ The most commonly used commands are:
     import-dscs  - import multiple Debian source packages
 
 Use '--list-cmds' to list all available commands.
-"""
+""")
 
 def version(prog):
     try:
@@ -125,10 +127,10 @@ def supercommand(argv=None):
     try:
         module = import_command(cmd)
     except ImportError as e:
-        print >>sys.stderr, "'%s' is not a valid command." % cmd
+        print("'%s' is not a valid command." % cmd, file=sys.stderr)
         usage()
         if '--verbose' in args:
-            print >>sys.stderr, e
+            print(e, file=sys.stderr)
         return 2
 
     return module.main(args)
index 7147da500e4b8d5a05355f8b837cb2f3ab0b2bfb..314d76f71eab0acdc149f127f429bc563672a609 100644 (file)
@@ -2,6 +2,8 @@
 
 """Test  L{GitRepository}'s write_tree method"""
 
+from __future__ import print_function
+
 from . import context
 
 import os
@@ -20,7 +22,7 @@ class TestWriteTree(testutils.DebianGitTestRepo):
         for i in range(4):
             path = os.path.join(self.repo.path, 'testfile%d' % i)
             with open(path, 'w') as f:
-                print >>f, "testdata %d" % i
+                print("testdata %d" % i, file=f)
             paths.append(path)
         return paths