From 9ae90f6ff9fffb4dab7c00fa72cdc28b64bbe87c Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Wed, 29 Dec 2021 14:58:19 -0800 Subject: Convert switcher4.py to python 3 Bug: 203436762 Test: m ds-docs-switched and making sure the resulting zip is the same as before Change-Id: Idabcffad186e4b07e47d495aa0d8ec5f48935487 --- Android.bp | 9 -------- switcher4.py | 72 ++++++++++++++++++++++++++++++------------------------------ 2 files changed, 36 insertions(+), 45 deletions(-) diff --git a/Android.bp b/Android.bp index 4f473a0..f1178af 100644 --- a/Android.bp +++ b/Android.bp @@ -19,13 +19,4 @@ package { python_binary_host { name: "switcher4", srcs: ["switcher4.py",], - - version: { - py2: { - enabled: true, - }, - py3: { - enabled: false, - }, - }, } diff --git a/switcher4.py b/switcher4.py index 6cd7739..58f1ba3 100644 --- a/switcher4.py +++ b/switcher4.py @@ -43,7 +43,7 @@ java_ref_root = os.getcwd() kotlin_ref_root = os.path.join(java_ref_root, "kotlin") root = os.path.split(java_ref_root)[1] if root != "reference": - print ("You must cd to the refocs reference/ root directoy") + print("You must cd to the refocs reference/ root directory") sys.exit() @@ -82,10 +82,10 @@ def insert_stub(doc, java, both): stubs = stubs+1 if verbose: - print "File: ", stubs, doc + print("File: ", stubs, doc) else: fn = os.path.split(doc) - print "File: ", stubs, fn[1], "\r", + print("File: ", stubs, fn[1], end="\r") if (java): java_stubs = java_stubs + 1 @@ -137,7 +137,7 @@ def scan_files(stem): solo = 0 both = 0 - print "*** PASS1 (Java) ***" + print("*** PASS1 (Java) ***") maxed_out = False for root, dirs, files in os.walk(java_source_abs_path): if maxed_out: @@ -147,7 +147,7 @@ def scan_files(stem): ext = ext[1] if not ext: # this catches package-lists with no extension - print "***", os.path.join(root, file_) + print("***", os.path.join(root, file_)) elif ext != ".html": # filter out png, yaml, etc continue @@ -167,23 +167,23 @@ def scan_files(stem): else: # no kotlin content if (show_solo): - print "solo: ", doc + print("solo: ", doc) insert_stub(doc, True, False) solo = solo+1 if max_stubs>0 and stubs>=max_stubs: - print - print "max java stubs: ", max_stubs + print() + print("max java stubs: ", max_stubs) maxed_out = True; break - print "Java+Kotlin:", both, "Only Java:", solo - print + print("Java+Kotlin:", both, "Only Java:", solo) + print() # PASS 2 # Loop over kotlin content, create stubs for Kotlin-only APIs - print "*** PASS2 (Kotlin) ***" + print("*** PASS2 (Kotlin) ***") solo = 0 both = 0 maxed_out = False @@ -196,7 +196,7 @@ def scan_files(stem): ext = ext[1] if not ext: # this catches package-lists with no extension - print "***", os.path.join(root, file_) + print("***", os.path.join(root, file_)) elif ext != ".html": # filter out png, yaml, etc continue @@ -217,20 +217,20 @@ def scan_files(stem): # no java content # create the kotlin stub file if (show_solo): - print "solo: ", doc + print("solo: ", doc) insert_stub(doc , False, False) solo = solo+1 if (max_stubs>0 and stubs>=max_stubs): - print - print "max koltin stubs: ", max_stubs + print() + print("max koltin stubs: ", max_stubs) maxed_out = True; break - print "Java+Kotlin:", both, "Only Kotlin:", solo - print - print "Java: ", java_stubs, " Kotlin: ", kotlin_stubs, "Total: ", java_stubs + kotlin_stubs + print("Java+Kotlin:", both, "Only Kotlin:", solo) + print() + print("Java: ", java_stubs, " Kotlin: ", kotlin_stubs, "Total: ", java_stubs + kotlin_stubs) def main(argv): @@ -243,56 +243,56 @@ def main(argv): try: opts, args = getopt.getopt(argv,"",["work","verbose","solo","max="]) except getopt.GetoptError: - print 'USAGE: switcher --work --verbose --solo --max= platform|androidx|support|chrome' + print('USAGE: switcher --work --verbose --solo --max= platform|androidx|support|chrome') sys.exit(2) for opt, arg in opts: if opt == '--work': work = True elif opt == "--verbose": - print "verbose" + print("verbose") verbose = True elif opt == "--solo": - print "verbose" + print("verbose") show_solo = True elif opt == "--max": max_stubs = int(arg) - print "max ", max_stubs + print("max ", max_stubs) if len(args)>0: source = args[0] if source == "platform": stem = "android" - print - print "*** PLATFORM PAGES ***" - print "======================" + print() + print("*** PLATFORM PAGES ***") + print("======================") # Insert the switchers at the top level first insert_platform_summaries() elif source == "androidx": stem = "androidx" - print - print "*** ANDROIDX SUPPORT LIBRARY PAGES ***" - print "======================================" + print() + print("*** ANDROIDX SUPPORT LIBRARY PAGES ***") + print("======================================") elif source == "support": stem = "android/support/v4/media" - print - print "*** ANDROIDX SUPPORT LIBRARY PAGES ***" - print "======================================" + print() + print("*** ANDROIDX SUPPORT LIBRARY PAGES ***") + print("======================================") elif source == "chrome": stem = "org/chromium/support_lib_boundary" - print - print "*** ANDROIDX CHROMIUM PAGES ***" - print "===============================" + print() + print("*** ANDROIDX CHROMIUM PAGES ***") + print("===============================") if (len(stem)>0): scan_files(stem) - print " *** DONE ***" + print(" *** DONE ***") else: - print 'You must specify one of: platform|androidx|support|chrome' + print('You must specify one of: platform|androidx|support|chrome') -- cgit v1.2.3