[Fuego] [PATCH 1/2] python2to3: Convert the print statement to the print() function
[email protected] Wed, 15 Dec 2021 20:48:03 +0530
| Newsgroups | dev.linux.lists.fuego |
|---|---|
| Message-ID | <[email protected]> |
From: Shivanand Kunijadar <[email protected]> Put parentheses around all print statements in all python scripts. It is compatible with both python2 and python3 interpreters. Signed-off-by: Shivanand Kunijadar <[email protected]> --- scripts/deorphan-runs.py | 8 ++++---- scripts/functions.sh | 2 +- scripts/gen-page.py | 2 +- scripts/loggen/gentexml.py | 2 +- scripts/loggen/loggen.py | 12 ++++++------ scripts/ovgen.py | 8 ++++---- scripts/parser/common.py | 14 +++++++------- scripts/parser/fuego_parser_results.py | 2 +- scripts/parser/fuego_parser_utils.py | 6 +++--- tests/Functional.LTP/ltp_process.py | 10 +++++----- tests/Functional.LTP/parser.py | 18 +++++++++--------- tests/Functional.autopkgtest/parser.py | 6 +++--- 12 files changed, 45 insertions(+), 45 deletions(-) diff --git a/scripts/deorphan-runs.py b/scripts/deorphan-runs.py index 70da980..1148d4d 100755 --- a/scripts/deorphan-runs.py +++ b/scripts/deorphan-runs.py @@ -28,7 +28,7 @@ JENKINS_HOME="/var/lib/jenkins" server = None def usage(): - print """Usage: deorphan-runs.py [-h] [-j] [-b] [<pattern>] + print("""Usage: deorphan-runs.py [-h] [-j] [-b] [<pattern>] This program finds Fuego test runs that do not have corresponding Jenkins builds (so-called 'orphan runs'). It can be used create Jenkins jobs and builds for this orphan runs. @@ -53,7 +53,7 @@ Examples: deorphan-run.py -j -b hello_world.*docker Create any needed jobs and builds for the indicated orphan runs. -""" +""") sys.exit(0) class data_class: @@ -297,7 +297,7 @@ def create_build(run): get_ok = run.get_run_data_from_json_file() if not get_ok: - print "Error: Cannot create enkins build.xml file" + print("Error: Cannot create enkins build.xml file") return # update nextBuildNumber @@ -314,7 +314,7 @@ def create_build(run): with open(nb_filename, "w+") as fd: fd.write(next_build_number+'\n') except: - print "Error: problem writing to file %s" % nb_filename + print("Error: problem writing to file %s" % nb_filename) # create jenkins directory for this run build_dir = run.builddir diff --git a/scripts/functions.sh b/scripts/functions.sh index 34f3713..44a8fdb 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -504,7 +504,7 @@ function build { call_if_present test_build ret=$? build_end_time=$(date +"%s.%N") - build_duration=$(python -c "print $build_end_time - $build_start_time") + build_duration=$(python -c "print($build_end_time - $build_start_time)") # test_build may change the current dir # get back to root of build dir, before 'touch' diff --git a/scripts/gen-page.py b/scripts/gen-page.py index 0e0b21a..4eb1ae3 100755 --- a/scripts/gen-page.py +++ b/scripts/gen-page.py @@ -101,7 +101,7 @@ def get_macro_value(macro, test_name, test_set, test_case): """ msg = "ERROR: Unknown Macro '%s'" % macro - print msg + print(msg) return msg def main(): diff --git a/scripts/loggen/gentexml.py b/scripts/loggen/gentexml.py index 4000d08..8e0a3d9 100644 --- a/scripts/loggen/gentexml.py +++ b/scripts/loggen/gentexml.py @@ -34,7 +34,7 @@ log_lvl = 1 def debug_print(string, lev=1): if lev <= log_lvl: - print "log: " + string + print("log: " + string) def load_logrun(path): diff --git a/scripts/loggen/loggen.py b/scripts/loggen/loggen.py index b0f55b1..1445bd7 100644 --- a/scripts/loggen/loggen.py +++ b/scripts/loggen/loggen.py @@ -36,7 +36,7 @@ log_lvl = 1 def debug_print(string, lev=1): if lev <= log_lvl: - print "log: " + string + print("log: " + string) def append_logfile(logrun, logfile, testName): with open(logrun, "r+") as f: @@ -89,33 +89,33 @@ def run(test_args=None): if args.debug: if args.debug < 1 or args.debug > 3: - print "Error: wrong debug lvl: %s" % (args.debug) + print("Error: wrong debug lvl: %s" % (args.debug)) sys.exit global log_lvl log_lvl = args.debug if args.append_logfile: if (args.logrun_file == None) or (args.testname == None): - print "--append-logfile needs logrun-file and testname arguments are specified\n" + print("--append-logfile needs logrun-file and testname arguments are specified\n") sys.exit(1) append_logfile(args.logrun_file, args.append_logfile, args.testname) elif args.append_funcres: if (args.logrun_file == None) or (args.testname == None): - print "--append-funcres needs logrun-file and testname arguments are specified\n" + print("--append-funcres needs logrun-file and testname arguments are specified\n") sys.exit(1) append_funcres(args.logrun_file, args.append_funcres, args.testname) elif args.create_logrun: if (args.testplan == None) or (args.board == None) or (args.run_num == None): - print "--create-logrun needs board, run-num and testplan arguments\n" + print("--create-logrun needs board, run-num and testplan arguments\n") sys.exit(1) create_logrun_file(args.create_logrun, args.testplan, args.board, args.run_num) else: - print "Unkown command line: %s" % (args) + print("Unkown command line: %s" % (args)) sys.exit(1) diff --git a/scripts/ovgen.py b/scripts/ovgen.py index de49873..faabc62 100755 --- a/scripts/ovgen.py +++ b/scripts/ovgen.py @@ -108,7 +108,7 @@ class SpecException(Exception): def debug_print(string, lev=1): if lev <= log_lvl: - print "log: " + string + print("log: " + string) # parse Overlay Framework variables definitions def parseOFVars(line, ofc): @@ -265,7 +265,7 @@ def parseLayerFuncOverride(line, layer, inhclass, f): rv = parseFunctionBody(name, f) if rv: if name not in inhclass.funcs: - print "%s funcs: %s" % (inhclass.name, inhclass.funcs) + print("%s funcs: %s" % (inhclass.name, inhclass.funcs)) raise OFVarNotFoundException("function %s is not found in %s class" % (name, inhclass.name)) body = "function " + name + " " + rest + "\n" + rv @@ -342,7 +342,7 @@ def parseOverrideFile(overrideFile, layer, ofcls): break; if inheritClass == None: - print "%s does not contain inherit directive" % (overrideFile) + print("%s does not contain inherit directive" % (overrideFile)) exit debug_print("All classes: %s" % (classes)) @@ -503,7 +503,7 @@ def run(test_args=None): if args.debug: if args.debug < 1 or args.debug > 3: - print "Error: wrong debug lvl: %s" % (args.debug) + print("Error: wrong debug lvl: %s" % (args.debug)) sys.exit global log_lvl log_lvl = args.debug diff --git a/scripts/parser/common.py b/scripts/parser/common.py index 0bfb6cb..19bbcb0 100644 --- a/scripts/parser/common.py +++ b/scripts/parser/common.py @@ -551,23 +551,23 @@ def name_compare(a, b): def dump_ordered_data(data, indent=""): if type(data)==type({}): - print "%s{" % indent + print("%s{" % indent) keylist = data.keys() keylist.sort() for key in keylist: - print '%s "%s":' % (indent+" ", key), - dump_ordered_data(data[key],indent+" ") - print "%s}" % indent + print('%s "%s":' % (indent+" ", key), + dump_ordered_data(data[key],indent+" ")) + print("%s}" % indent) return if type(data)==type([]): - print "%s[" % indent + print("%s[" % indent) item_list = data[:] item_list.sort(name_compare) for item in item_list: dump_ordered_data(item,indent+" ") - print "%s]" % indent + print("%s]" % indent) return - print "%s%s" % (indent, data) + print("%s%s" % (indent, data)) def dprint_data(label, data): if loglevel == "debug": diff --git a/scripts/parser/fuego_parser_results.py b/scripts/parser/fuego_parser_results.py index 152994e..f8dc63f 100644 --- a/scripts/parser/fuego_parser_results.py +++ b/scripts/parser/fuego_parser_results.py @@ -50,7 +50,7 @@ def update_results_json(test_logdir, TESTDIR, REF_JSON): ref = json.load(ref_file, object_pairs_hook=collections.OrderedDict) ref_test_case_ids = extract_test_case_ids(ref) except: - print "reference.json not available" + print("reference.json not available") ref_test_case_ids = None # look for run.json files on each build folder diff --git a/scripts/parser/fuego_parser_utils.py b/scripts/parser/fuego_parser_utils.py index 6c6fd2f..6bbc915 100644 --- a/scripts/parser/fuego_parser_utils.py +++ b/scripts/parser/fuego_parser_utils.py @@ -33,9 +33,9 @@ def hls(string,type_char): else: type_string = "ERROR" - print "########################### " + type_string + " ###############################" - print string - print "-----" + print("########################### " + type_string + " ###############################") + print(string) + print("-----") def split_test_id(test_case_id): if "." in test_case_id: diff --git a/tests/Functional.LTP/ltp_process.py b/tests/Functional.LTP/ltp_process.py index a8dfb07..8a29830 100644 --- a/tests/Functional.LTP/ltp_process.py +++ b/tests/Functional.LTP/ltp_process.py @@ -19,7 +19,7 @@ def split_output_per_testcase (test_category): try: output_all = open("%s/output.log" % test_category) except IOError: - print '"%s/result.log" cannot be opened.' % test_category + print('"%s/result.log" cannot be opened.' % test_category) sys.exit(1) lines = output_all.readlines() @@ -32,7 +32,7 @@ def split_output_per_testcase (test_category): try: output_each = open("%s/outputs/tmp.log" % test_category, "w") except IOError: - print '"%s/outputs/tmp.log" cannot be opened.' % test_category + print('"%s/outputs/tmp.log" cannot be opened.' % test_category) sys.exit(1) m = re.compile("^tag=([^ ]*)").match(line) @@ -55,7 +55,7 @@ def read_cmdline (test_category, test_case): try: output_each = open("%s/outputs/%s.log" % (test_category, test_case)) except IOError: - print '"%s/outputs/%s.log"" cannot be opened.' % (test_category, test_case) + print('"%s/outputs/%s.log"" cannot be opened.' % (test_category, test_case)) sys.exit(1) output = output_each.read() @@ -73,7 +73,7 @@ def read_output (test_category, test_case): try: output_each = open("%s/outputs/%s.log" % (test_category, test_case)) except IOError: - print '"%s/outputs/%s.log"" cannot be opened.' % (test_category, test_case) + print('"%s/outputs/%s.log"" cannot be opened.' % (test_category, test_case)) sys.exit(1) output = output_each.read() @@ -129,7 +129,7 @@ for test_category in tests: try: f = open("%s/result.log" % test_category) except IOError: - print '"%s/result.log" cannot be opened.' % test_category + print('"%s/result.log" cannot be opened.' % test_category) continue # Add a new sheet diff --git a/tests/Functional.LTP/parser.py b/tests/Functional.LTP/parser.py index f9c8e32..9ad7659 100755 --- a/tests/Functional.LTP/parser.py +++ b/tests/Functional.LTP/parser.py @@ -7,7 +7,7 @@ SAVEDIR=os.getcwd() LOGDIR=os.environ["LOGDIR"] def abort(msg): - print msg + print(msg) os.chdir(SAVEDIR) sys.exit(1) @@ -85,7 +85,7 @@ def read_output (test_category, test_case): try: os.chdir(LOGDIR+"/result") except: - print "WARNING: no result directory (probably a build only test)." + print("WARNING: no result directory (probably a build only test).") sys.exit(3) # there are three types of results - regular, posix and realtime @@ -105,7 +105,7 @@ for test_category in tests: try: f = open("%s/result.log" % test_category) except IOError: - print '"%s/result.log" cannot be opened.' % test_category + print('"%s/result.log" cannot be opened.' % test_category) continue lines = f.readlines() @@ -159,13 +159,13 @@ for test_category in tests: status = "FAIL" if status == "PASS": - print "%s:%s passed" % (test_category, test_case) + print("%s:%s passed" % (test_category, test_case)) elif status == "SKIP": - print "%s:%s skipped" % (test_category, test_case) + print("%s:%s skipped" % (test_category, test_case)) elif status == "FAIL": - print "%s:%s failed" % (test_category, test_case) + print("%s:%s failed" % (test_category, test_case)) else: - print "%s:%s had an error" % (test_category, test_case) + print("%s:%s had an error" % (test_category, test_case)) # FIXTHIS: show errtype # FIXTHIS: add sub-test data @@ -173,7 +173,7 @@ for test_category in tests: # put test output to console log output = read_output(test_category, test_case) - print output + print(output) # now process posix results - from pts.log file posix_results = {} @@ -185,7 +185,7 @@ if os.path.exists(pts_logfile): lines = f.readlines() f.close() except IOError: - print '"%s" cannot be opened.' % pts_logfile + print('"%s" cannot be opened.' % pts_logfile) regc = re.compile(r"^conformance/([^/]*)/([^/]*)/([^/]*): execution: (.*)") for line in lines: diff --git a/tests/Functional.autopkgtest/parser.py b/tests/Functional.autopkgtest/parser.py index 0ab56fa..ba3dea1 100755 --- a/tests/Functional.autopkgtest/parser.py +++ b/tests/Functional.autopkgtest/parser.py @@ -5,17 +5,17 @@ import common as plib AUTOPKGTST_SUMMARY = plib.LOGDIR + "/summary.txt" -print "Parsing: " + AUTOPKGTST_SUMMARY +print("Parsing: " + AUTOPKGTST_SUMMARY) results = {} with open(AUTOPKGTST_SUMMARY) as f: for line in f: - print line.strip() + print(line.strip()) if line.startswith("Fuego test_set:"): test_set = line.split()[2] continue if line.strip(): - print line.strip() + print(line.strip()) fields = line.split() test_case = fields[0] results[test_set+'.'+test_case] = "PASS" if fields[1] == 'PASS' else "FAIL" -- 2.20.1