#!/usr/bin/env python # # Copyright 2019 - The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### # This script adds a HTML snippet to the generated reference docs located at # developer.android.com/reference. The snippet renders HTML that adds links to # toggle between the Java and Kotlin versions of the page. ############################################################################### import getopt import os import sys # GLOBAL FLAGS global stubs global java_stubs, kotlin_stubs global work, verbose, show_solo, max_stubs global java_source_abs_path global kotlin_source_abs_path verbose = False # set True to list all files as they are stubbed (--verbose) work = False # set True to insert stubs, False to do a dry run for stats (--work) show_solo = False # set True to list files that only appear in one language, rather than both (--solo) max_stubs = 0 # set positive to create a limited number of stubs (--max 12) # You must run the script from the refodcs reference/ root directory 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 directory") sys.exit() # This method uses switcher2, which assumes the refdocs stay in their current # asymmetrical dirs (ref/android and ref/kotlin/android) # And just puts the switcher in the existing docs def insert_stub(doc, java, both): global stubs global java_stubs, kotlin_stubs global verbose, work, show_solo global java_source_abs_path global kotlin_source_abs_path stubs = stubs+1 if verbose: # Print everything. print("File: ", stubs, doc) else: # Print just the file name on the current line. fn = os.path.split(doc) print("File: ", stubs, fn[1], end="\r") if (java): java_stubs = java_stubs + 1 else: kotlin_stubs = kotlin_stubs + 1 if (work): if (java): file_path = doc[len(java_ref_root)+1:] stub = doc.replace(java_source_abs_path, kotlin_source_abs_path) # Always add the switcher for java files, switch to the package summary if # the page itself doesn't exist in kotlin slug1 = "sed -i 's/