public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: [PATCH 6/7] gdb/copyright.py: Convert to Python 3
Date: Wed, 01 Jan 2020 06:28:00 -0000	[thread overview]
Message-ID: <20200101062827.8787-7-brobecker@adacore.com> (raw)
In-Reply-To: <20200101062827.8787-1-brobecker@adacore.com>

gdb/ChangeLog:

        * copyright.py: Convert to Python 3.
---
 gdb/ChangeLog    |  4 ++++
 gdb/copyright.py | 36 ++++++++++++++++++++----------------
 2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 02dff2b35a2..a570039a88f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2020-01-01  Joel Brobecker  <brobecker@adacore.com>
+
+	* copyright.py: Convert to Python 3.
+
 2020-01-01  Joel Brobecker  <brobecker@adacore.com>
 
 	* copyright.py: Adapt after move of gnulib directory from gdb
diff --git a/gdb/copyright.py b/gdb/copyright.py
index e6feb376a92..2f468441ae9 100644
--- a/gdb/copyright.py
+++ b/gdb/copyright.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 
 # Copyright (C) 2011-2019 Free Software Foundation, Inc.
 #
@@ -31,6 +31,7 @@ This removes the bulk of the changes which are most likely to be correct.
 """
 
 import datetime
+import locale
 import os
 import os.path
 import subprocess
@@ -84,7 +85,8 @@ def update_files(update_list):
     update_cmd += update_list
 
     p = subprocess.Popen(update_cmd, stdout=subprocess.PIPE,
-                         stderr=subprocess.STDOUT)
+                         stderr=subprocess.STDOUT,
+                         encoding=locale.getpreferredencoding())
     update_out = p.communicate()[0]
 
     # Process the output.  Typically, a lot of files do not have
@@ -95,20 +97,18 @@ def update_files(update_list):
     # the line out from the output, since there is nothing more to do,
     # short of looking at each file and seeing which notice is appropriate.
     # Too much work! (~4,000 files listed as of 2012-01-03).
-    update_out = update_out.splitlines()
+    update_out = update_out.splitlines(keepends=False)
     warning_string = ': warning: copyright statement not found'
     warning_len = len(warning_string)
 
     for line in update_out:
-        if line.endswith('\n'):
-            line = line[:-1]
         if line.endswith(warning_string):
             filename = line[:-warning_len]
             if may_have_copyright_notice(filename):
-                print line
+                print(line)
         else:
             # Unrecognized file format. !?!
-            print "*** " + line
+            print("*** " + line)
 
 
 def may_have_copyright_notice(filename):
@@ -128,11 +128,15 @@ def may_have_copyright_notice(filename):
     # 50 lines...
     MAX_LINES = 50
 
-    fd = open(filename)
+    # We don't really know what encoding each file might be following,
+    # so just open the file as a byte stream. We only need to search
+    # for a pattern that should be the same regardless of encoding,
+    # so that should be good enough.
+    fd = open(filename, 'rb')
 
     lineno = 1
     for line in fd:
-        if 'Copyright' in line:
+        if b'Copyright' in line:
             return True
         lineno += 1
         if lineno > 50:
@@ -147,7 +151,7 @@ def main ():
 
     if not (os.path.isdir('gdb') and
             os.path.isfile("gnulib/import/extra/update-copyright")):
-        print "Error: This script must be called from the gdb directory."
+        print("Error: This script must be called from the gdb directory.")
         sys.exit(1)
 
     update_list = get_update_list()
@@ -156,19 +160,19 @@ def main ():
     # Remind the user that some files need to be updated by HAND...
 
     if MULTIPLE_COPYRIGHT_HEADERS:
-        print
+        print()
         print("\033[31m"
               "REMINDER: Multiple copyright headers must be updated by hand:"
               "\033[0m")
         for filename in MULTIPLE_COPYRIGHT_HEADERS:
-            print "  ", filename
+            print("  ", filename)
 
     if BY_HAND:
-        print
-        print "\033[31mREMINDER: The following files must be updated by hand." \
-              "\033[0m"
+        print()
+        print("\033[31mREMINDER: The following files must be updated by hand." \
+              "\033[0m")
         for filename in BY_HAND:
-            print "  ", filename
+            print("  ", filename)
 
 ############################################################################
 #
-- 
2.17.1

  parent reply	other threads:[~2020-01-01  6:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-01  6:28 FYI: Start of New Year updates performed (and copyright.py switch to Python3) Joel Brobecker
2020-01-01  6:28 ` [PATCH 1/7] Automatic date update in version.in Joel Brobecker
2020-01-01  6:28 ` [PATCH 4/7] gdb/copyright.py: Exit if run from the wrong directory Joel Brobecker
2020-01-01  6:28 ` [PATCH 5/7] gdb/copyright.py: Adapt after move of gnulib from gdb to toplevel Joel Brobecker
2020-01-01  6:28 ` Joel Brobecker [this message]
2020-01-01  6:28 ` [PATCH 3/7] update copyright year in version output of gdb, gdbserver and gdbreplay Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200101062827.8787-7-brobecker@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).