From f9e9e41c7b45067116768b584cc9f31a837f699a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konsta=20H=C3=B6ltt=C3=A4?= Date: Thu, 26 Mar 2020 09:57:26 +0200 Subject: [PATCH] scripts: rfr: convert to python 3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Python 2 is no longer maintained. Use python 3 to be up to date and to make it easier to work with utf-8 text. Change-Id: I341f558730caaa9106e8eef4304d67af747c7373 Signed-off-by: Konsta Hölttä Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2318760 Reviewed-by: automaticguardword Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions GVS: Gerrit_Virtual_Submit --- scripts/rfr | 14 +++++++------- scripts/rfr_addrbook.py | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/rfr b/scripts/rfr index 115bb7420..50786a5ea 100755 --- a/scripts/rfr +++ b/scripts/rfr @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # # Copyright (c) 2018-2020, NVIDIA CORPORATION. All Rights Reserved. # @@ -239,7 +239,7 @@ def get_user_message(start_msg): editor = os.environ.get('EDITOR', 'vim') with tempfile.NamedTemporaryFile(suffix=".tmp") as filp: - filp.write(start_msg) + filp.write(start_msg.encode('utf-8')) filp.flush() edit_cmd = editor + ' ' + filp.name @@ -253,7 +253,7 @@ def get_user_message(start_msg): filp.seek(0) lines = filp.readlines() - return ''.join(filter(lambda l: not l.startswith('#'), lines)) + return ''.join([l.decode('utf-8') for l in lines if not l.startswith(b'#')]) def indent_lines(text, ind): """ @@ -300,7 +300,7 @@ Thanks! # note: x['deletions'] is negative (or zero) files = c['currentPatchSet']['files'] file_widths = [ - len(x['file']) for x in files if x['file'] != u'/COMMIT_MSG'] + len(x['file']) for x in files if x['file'] != '/COMMIT_MSG'] # For merge commits there are no files in the commit itself. So this # causes the below max() operation to choke. Given that there are no @@ -316,7 +316,7 @@ Thanks! sum=x['insertions'] - x['deletions'], adds=x['insertions'], dels=-x['deletions']) - for x in files if x['file'] != u'/COMMIT_MSG' + for x in files if x['file'] != '/COMMIT_MSG' ] else: files_changed_desc = '' @@ -407,7 +407,7 @@ def email_commits(commits_info, sender, subject, args): text = get_user_message(body) if not text or text.strip() == '': - print 'Empty user message: aborting!' + print('Empty user message: aborting!') return msg = MIMEText(text) @@ -458,7 +458,7 @@ def main(): # Oops: no commits? if not arg_parser.commits or len(arg_parser.commits) == 0: - print 'No commits!' + print('No commits!') exit(-1) # Builds a dictionary of Gerrit Change-Ids. From the Change-Ids we can then diff --git a/scripts/rfr_addrbook.py b/scripts/rfr_addrbook.py index 6026811d4..f5f70ee1c 100644 --- a/scripts/rfr_addrbook.py +++ b/scripts/rfr_addrbook.py @@ -73,7 +73,7 @@ def __rfr_load_ab(path, silent=False): except Exception as err: success = False if not silent: - print 'Error: %s' % err + print('Error: %s' % err) # It's not a very helpful error message I suppose. Eh. We will get more # detail from the __rfr_parse_addrbook() call itself. @@ -151,7 +151,7 @@ def rfr_ab_lookup_single(addr): """ # If there's no address book, just pass the addr through. - if len(__rfr_address_book.keys()) == 0: + if len(list(__rfr_address_book.keys())) == 0: return addr lc_addr = addr.lower() @@ -159,7 +159,7 @@ def rfr_ab_lookup_single(addr): if lc_addr in __rfr_address_book: return __rfr_address_book[lc_addr] - if lc_addr in __rfr_address_book.values(): + if lc_addr in list(__rfr_address_book.values()): # Return the orignal, un-lowercased. return addr