From 6d0b0aef6286fd49ae3f7b29797695686ba6084b Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 3 Oct 2018 17:06:04 -0400 Subject: [PATCH] update code to be python3-compatible This mostly fixes print statements and some pep8 issues. Change-Id: Ie4fb0ac8955759954d882988d698fb4aace61de1 Signed-off-by: Doug Hellmann --- tools/checktests.py | 52 +++++++++++++++------------- tools/jsonToRst.py | 2 +- working_materials/tabulate_scores.py | 8 +++-- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/tools/checktests.py b/tools/checktests.py index c82d3459..944300ad 100644 --- a/tools/checktests.py +++ b/tools/checktests.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import print_function + import ast import argparse import importlib @@ -152,41 +154,41 @@ def run(): exit_code = 0 if len(missing_uuids) > 0: exit_code = 1 - print "### Idempotent ID Errors Detected. To resolve these errors, " \ - "fix the uuid name (format id-) in the guideline to " \ - "match the id in the test suite:" + print("### Idempotent ID Errors Detected. To resolve these errors, " + "fix the uuid name (format id-) in the guideline to " + "match the id in the test suite:") for test in missing_uuids: - print "Idempotent ID in guideline '%s' does not appear in test " \ - "library '%s'\n" \ - " idempotent_id:\n" \ - " %s\n" \ - " names: " % (args.guideline_file, args.testlib, test[0]) + print("Idempotent ID in guideline '%s' does not appear in test " + "library '%s'\n" + " idempotent_id:\n" + " %s\n" + " names: " % (args.guideline_file, args.testlib, test[0])) for testname in test[1]: - print " %s" % (testname) - print "" + print(" %s" % (testname)) + print("") if len(missing_tests) > 0: exit_code = 1 - print "### Test Name Errors Detected. " \ - "To resolve these errors, update " \ - "the Interop guideline with the missing " \ - "test names:" + print("### Test Name Errors Detected. " + "To resolve these errors, update " + "the Interop guideline with the missing " + "test names:") for uuid in missing_tests: - print "Test found in test library '%s'\n" \ - " idempotent_id:\n" \ - " %s\n" \ - " name:\n" \ - " %s\n" \ - "Entry in guideline '%s'\n" \ - " idempotent_id:\n" \ - " %s\n" \ + print("Test found in test library '%s'\n" + " idempotent_id:\n" + " %s\n" + " name:\n" + " %s\n" + "Entry in guideline '%s'\n" + " idempotent_id:\n" + " %s\n" " names: " % (args.testlib, uuid, tests[uuid], args.guideline_file, - missing_tests[uuid][0]) + missing_tests[uuid][0])) for testname in missing_tests[uuid][1]: - print " %s" % (testname) - print "" + print(" %s" % (testname)) + print("") sys.exit(exit_code) diff --git a/tools/jsonToRst.py b/tools/jsonToRst.py index 081e07fe..4b78e3d2 100755 --- a/tools/jsonToRst.py +++ b/tools/jsonToRst.py @@ -57,7 +57,7 @@ if not isinstance(data, dict): outFileName = 'doc/source/guidelines/' + inFileName.replace("json", "rst") -print ("Writing to: " + outFileName) +print("Writing to: " + outFileName) # intro diff --git a/working_materials/tabulate_scores.py b/working_materials/tabulate_scores.py index 5dbcc316..7b6975ea 100755 --- a/working_materials/tabulate_scores.py +++ b/working_materials/tabulate_scores.py @@ -14,6 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import print_function + import re import json import argparse @@ -194,7 +196,7 @@ with open(args.score_file_name) as filehandle: # And stdout is useful for folks who are experimenting with # the effect of changing a score. - print "%s: %d%s" % (cap_name, total, meets_criteria) + print("%s: %d%s" % (cap_name, total, meets_criteria)) # Now we can write the text output file. with open(args.text_outfile_name, 'w') as outfile: @@ -202,5 +204,5 @@ with open(args.text_outfile_name, 'w') as outfile: outfile.write(line) outfile.close() -print "\n\nText output has been written to %s" % args.text_outfile_name -print "CSV output has been written to %s" % args.csv_outfile_name +print("\n\nText output has been written to %s" % args.text_outfile_name) +print("CSV output has been written to %s" % args.csv_outfile_name)