From 2fd9eb9d3f7a8dd7a0ec37f15f35ad2eca5770ee Mon Sep 17 00:00:00 2001 From: Robin Garner <130519286+rgarner-vivcourt@users.noreply.github.com> Date: Wed, 20 Mar 2024 02:56:26 +1100 Subject: [PATCH] Python3 compatibility (#4) * Python3 compatibility * Use python3 directly in the shebang * Python3 syntax fix * Fix name of string class --- src/python/solar_capture/cli.py | 2 +- src/python/solar_capture/tabulate.py | 1 + src/solar_balancer | 4 ++-- src/solar_css_tunnel_bridge | 2 +- src/solar_replay | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/python/solar_capture/cli.py b/src/python/solar_capture/cli.py index cc88df45..aa4fe99c 100644 --- a/src/python/solar_capture/cli.py +++ b/src/python/solar_capture/cli.py @@ -147,7 +147,7 @@ def help_all(args): def read_arg_file(f, known_args): repeatable_keys = [x.name for x in known_args.values() if x.repeatable] - data = file(f).read() + data = open(f).read() args = [] arg_indexes = {} # key -> index into args for line in data.split('\n'): diff --git a/src/python/solar_capture/tabulate.py b/src/python/solar_capture/tabulate.py index d6d70c5f..f3c4598b 100644 --- a/src/python/solar_capture/tabulate.py +++ b/src/python/solar_capture/tabulate.py @@ -21,6 +21,7 @@ def is_int(str): def auto_justify_col(col, width): if min(map(is_int, col[1:])): # All fields (possibly excepting first) are integers. + return [f.rjust(width) for f in col] else: return [f.ljust(width) for f in col] diff --git a/src/solar_balancer b/src/solar_balancer index 0264b830..177b4123 100644 --- a/src/solar_balancer +++ b/src/solar_balancer @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python3 ''' SPDX-License-Identifier: MIT X-SPDX-Copyright-Text: Copyright (C) 2022, Advanced Micro Devices, Inc. @@ -239,7 +239,7 @@ def main(args): if __name__ == '__main__': try: main(sys.argv[1:]) - except (sc.SCError, ValueError), e: + except (sc.SCError, ValueError) as e: s = str(e) if 'ERROR:' not in s: s = 'ERROR: ' + s diff --git a/src/solar_css_tunnel_bridge b/src/solar_css_tunnel_bridge index 133766db..eb979691 100644 --- a/src/solar_css_tunnel_bridge +++ b/src/solar_css_tunnel_bridge @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python3 ''' SPDX-License-Identifier: MIT X-SPDX-Copyright-Text: Copyright (C) 2022, Advanced Micro Devices, Inc. diff --git a/src/solar_replay b/src/solar_replay index f0147129..bcbc80cd 100644 --- a/src/solar_replay +++ b/src/solar_replay @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python3 ''' SPDX-License-Identifier: MIT X-SPDX-Copyright-Text: Copyright (C) 2022, Advanced Micro Devices, Inc. @@ -402,7 +402,7 @@ def main(args): if __name__ == '__main__': try: main(sys.argv[1:]) - except (sc.SCError, ValueError), e: + except (sc.SCError, ValueError) as e: s = str(e) if 'ERROR:' not in s: s = 'ERROR: ' + s