]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Convert contrib/mklog script to Python 3
authorJanne Blomqvist <jb@gcc.gnu.org>
Tue, 21 May 2019 06:59:16 +0000 (09:59 +0300)
committerJanne Blomqvist <jb@gcc.gnu.org>
Tue, 21 May 2019 06:59:16 +0000 (09:59 +0300)
Upstream will drop support for Python 2.x on January 1, 2020.  This
patch converts the contrib/mklog script to Python 3.  The process for
the conversion was as follows.

- Use the futurize tool (https://python-future.org ) to apply the
  print_with_import, except, and dict transformations.

- Remove the "from __future__ import print_function".

- Change the shebang line to search for python3 in the environment.

- Modify the run() function to return a str instead of bytes.

- Update the copyright year.

contrib/ChangeLog:

2019-05-21  Janne Blomqvist  <jb@gcc.gnu.org>

        * mklog: Convert to Python 3.

From-SVN: r271456

contrib/ChangeLog
contrib/mklog

index 09174eb80c27544f329e5e5e84461d42c0d1fd3c..2b6425b9ec20115e31e21472f2416318d2babb3b 100644 (file)
@@ -1,3 +1,7 @@
+2019-05-21  Janne Blomqvist  <jb@gcc.gnu.org>
+
+        * mklog: Convert to Python 3.
+
 2019-05-03  Jakub Jelinek  <jakub@redhat.com>
 
        * gennews (files): Add files for GCC 9.
index eb765edcbe2663cb4c47fafd49cf6a30f3e65362..125f52ef11ca9545518c68ae9f843dc4744b2b47 100755 (executable)
@@ -1,6 +1,6 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 
-# Copyright (C) 2017 Free Software Foundation, Inc.
+# Copyright (C) 2017-2019 Free Software Foundation, Inc.
 #
 # This file is part of GCC.
 #
@@ -67,7 +67,7 @@ class RegexCache(object):
 cache = RegexCache()
 
 def print_help_and_exit():
-    print """\
+    print("""\
 Usage: %s [-i | --inline] [PATCH]
 Generate ChangeLog template for PATCH.
 PATCH must be generated using diff(1)'s -up or -cp options
@@ -78,7 +78,7 @@ When PATCH is - or missing, read standard input.
 When -i is used, prepends ChangeLog to PATCH.
 If PATCH is not stdin, modifies PATCH in-place, otherwise writes
 to stdout.
-""" % me
+""" % me)
     sys.exit(1)
 
 def run(cmd, die_on_error):
@@ -87,7 +87,7 @@ def run(cmd, die_on_error):
   (out, err) = proc.communicate()
   if die_on_error and proc.returncode != 0:
     error("`%s` failed:\n" % (cmd, proc.stderr))
-  return proc.returncode, out, err
+  return proc.returncode, out.decode(), err
 
 def read_user_info():
   dot_mklog_format_msg = """\
@@ -153,9 +153,9 @@ class FileDiff:
     self.clname, self.relname = get_parent_changelog(filename);
 
   def dump(self):
-    print "Diff for %s:\n  ChangeLog = %s\n  rel name = %s\n" % (self.filename, self.clname, self.relname)
+    print("Diff for %s:\n  ChangeLog = %s\n  rel name = %s\n" % (self.filename, self.clname, self.relname))
     for i, h in enumerate(self.hunks):
-      print "Next hunk %d:" % i
+      print("Next hunk %d:" % i)
       h.dump()
 
 class Hunk:
@@ -167,8 +167,8 @@ class Hunk:
     self.ctx_diff = is_ctx_hunk_start(hdr)
 
   def dump(self):
-    print '%s' % self.hdr
-    print '%s' % '\n'.join(self.lines)
+    print('%s' % self.hdr)
+    print('%s' % '\n'.join(self.lines))
 
   def is_file_addition(self):
     """Does hunk describe addition of file?"""
@@ -358,7 +358,7 @@ def main():
 
   try:
     opts, args = getopt.getopt(sys.argv[1:], 'hiv', ['help', 'verbose', 'inline'])
-  except getopt.GetoptError, err:
+  except getopt.GetoptError as err:
     error(str(err))
 
   inline = False
@@ -388,7 +388,7 @@ def main():
   diffs = parse_patch(contents)
 
   if verbose:
-    print "Parse results:"
+    print("Parse results:")
     for d in diffs:
       d.dump()
 
@@ -449,7 +449,7 @@ def main():
 
   # Print log
   date = time.strftime('%Y-%m-%d')
-  for log_name, msg in sorted(logs.iteritems()):
+  for log_name, msg in sorted(logs.items()):
     out.write("""\
 %s: