Convert switcher4.py to python 3 am: 9ae90f6ff9 am: cb0539b94d am: af28506348 am: 762c910ca1

Original change: https://android-review.googlesource.com/c/platform/tools/doc_generation/+/1935069

Change-Id: I7311d834ef1d4da65222c0dcd2a219c7f2eb9061
diff --git a/Android.bp b/Android.bp
index 4f473a0..f1178af 100644
--- a/Android.bp
+++ b/Android.bp
@@ -19,13 +19,4 @@
 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 @@
 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 @@
   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 @@
   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 @@
         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 @@
           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 @@
         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 @@
             # 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 @@
   try:
     opts, args = getopt.getopt(argv,"",["work","verbose","solo","max="])
   except getopt.GetoptError:
-    print 'USAGE: switcher --work --verbose --solo --max=<max_stubs> platform|androidx|support|chrome'
+    print('USAGE: switcher --work --verbose --solo --max=<max_stubs> 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')