From patchwork Wed Jan 1 06:50:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 37152 Received: (qmail 21715 invoked by alias); 1 Jan 2020 06:50:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 21646 invoked by uid 89); 1 Jan 2020 06:50:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 01 Jan 2020 06:50:55 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id B8077117070; Wed, 1 Jan 2020 01:50:53 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id xjRQ5qzL0UU6; Wed, 1 Jan 2020 01:50:53 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 4E530117068; Wed, 1 Jan 2020 01:50:53 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 0E5B8838B8; Wed, 1 Jan 2020 10:50:49 +0400 (+04) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: [PATCH 4/6] gdb/copyright.py: Convert to Python 3 Date: Wed, 1 Jan 2020 10:50:31 +0400 Message-Id: <20200101065033.24334-5-brobecker@adacore.com> In-Reply-To: <20200101065033.24334-1-brobecker@adacore.com> References: <20200101065033.24334-1-brobecker@adacore.com> gdb/ChangeLog: * copyright.py: Convert to Python 3. (cherry picked from commit 5f4def5cbd12e77075f64a6854fb002f34be8a01) --- gdb/ChangeLog | 4 ++++ gdb/copyright.py | 36 ++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c91da6a23bd..3023daca561 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2020-01-01 Joel Brobecker + + * copyright.py: Convert to Python 3. + 2020-01-01 Joel Brobecker * 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) ############################################################################ #