summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorJanne Blomqvist <jb@gcc.gnu.org>2019-05-21 09:59:16 +0300
committerJanne Blomqvist <jb@gcc.gnu.org>2019-05-21 09:59:16 +0300
commiteaa6a39d4288fef9c322e8fe6c45e621b22cdf3f (patch)
tree0863773e2fa9f516c38664c52e7803704edec7a2 /contrib
parentcb7ac91b12cc424680e47a65c05cecb6bb21ac7b (diff)
Convert contrib/mklog script to Python 3
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
Diffstat (limited to 'contrib')
-rw-r--r--contrib/ChangeLog4
-rwxr-xr-xcontrib/mklog24
2 files changed, 16 insertions, 12 deletions
diff --git a/contrib/ChangeLog b/contrib/ChangeLog
index 09174eb80c2..2b6425b9ec2 100644
--- a/contrib/ChangeLog
+++ b/contrib/ChangeLog
@@ -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.
diff --git a/contrib/mklog b/contrib/mklog
index eb765edcbe2..125f52ef11c 100755
--- a/contrib/mklog
+++ b/contrib/mklog
@@ -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: