This is an automated email from the ASF dual-hosted git repository.

victoria pushed a commit to branch script-update
in repository https://gitbox.apache.org/repos/asf/druid-website-src.git

commit 9768a4270a4a0d0874905d247ddef6d978fc5cb4
Author: Victoria Lim <[email protected]>
AuthorDate: Tue Jul 25 13:17:05 2023 -0700

    update script for source dir
---
 scripts/copy_druid_docs.py | 98 +++++++++++++++++++++++++++++-----------------
 scripts/do_all_things.py   | 11 ++++--
 2 files changed, 68 insertions(+), 41 deletions(-)

diff --git a/scripts/copy_druid_docs.py b/scripts/copy_druid_docs.py
index 8d3e119b..8ca75f14 100755
--- a/scripts/copy_druid_docs.py
+++ b/scripts/copy_druid_docs.py
@@ -23,25 +23,44 @@ python copy_druid_docs.py -v 26.0.0
 
 druid_variable = "{{DRUIDVERSION}}"
 
-# Set source_directory to your OSS Druid repo
-# The directory structure should have apache/druid and 
apache/druid-website-src as peers
-source_directory = "../../druid/"
-if not os.path.exists(source_directory):
-    import sys
-    sys.exit("Please supply a valid path for 'source_directory' in 
copy_druid_docs.py")
-
-# Check that the correct branch is checked out for `apache/druid`
-branch_result = subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"], 
cwd=source_directory, capture_output=True)
-current_branch = branch_result.stdout.decode('ascii').strip()
-print(f"Repo:\t'{source_directory}'\nBranch:\t'{current_branch}'\n")
-correct_branch = input("Is the following docs source correct? (y/n)").lower()
-if correct_branch == 'n':
-    print("Exiting. Confirm the correct repo location in the 
'source_directory' variable and check out the correct branch.")
-    quit()
-
-
-# Find/replace {{DRUIDVERSION}} with the actual version
+def check_source(source_directory):
+    """
+    Set source_directory to your OSS Druid repo.
+    The default directory structure assumes apache/druid and 
apache/druid-website-src are peers.
+    To pass in a non-default directory, use the --source flag or pass it into 
main()
+    """
+
+    is_valid = True
+    error_msg = ""
+
+    # Verify that the directory exists
+    full_path_source = os.path.abspath(source_directory)
+    print(f"\nChecking docs source from the 
following:\nRepo:\t'{full_path_source}'")
+    if not os.path.exists(source_directory):
+        is_valid = False
+        error_msg = "Error: Supply a valid path for apache/druid in the 
'--source' flag"
+        return is_valid, error_msg
+
+    # Get the current branch of the source directory (apache/druid)
+    branch_result = subprocess.run(["git", "rev-parse", "--abbrev-ref", 
"HEAD"], cwd=source_directory, capture_output=True)
+    current_branch = branch_result.stdout.decode('ascii').strip()
+
+    # Print information about the branch
+    print(f"Branch:\t'{current_branch}'\n")
+
+    # Verify source directory and its branch
+    correct_branch = input("Is the listed docs source correct? (y/n) ").lower()
+    if correct_branch == 'n':
+        is_valid = False
+        error_msg = "Error: Supply the correct repo for --source and check out 
the correct branch."
+
+    return is_valid, error_msg
+
 def replace_text_in_file(destination_directory, druid_version):
+    """
+    Find/replace {{DRUIDVERSION}} with the actual version
+    """
+
     with open(destination_directory, 'r') as file:
         file_content = file.read()
 
@@ -66,41 +85,42 @@ def do_the_replace(file_path, druid_version):
         elif os.path.isdir(item_path):
             do_the_replace(item_path, druid_version)
 
-def is_it_latest(druid_version, destination_directory_latest):
-
-  is_latest = input(f"Is {druid_version} going to be the highest version 
available for download? If yes, the docs will also be used for 'latest'. (y/n) 
").lower()
+def is_it_latest(druid_version, source_directory, 
destination_directory_latest):
+    is_latest = input(f"Is {druid_version} going to be the highest version 
available for download? If yes, the docs will also be used for 'latest'. (y/n) 
").lower()
 
-  if is_latest == 'y':
-      print("Also copying the docs to docs/latest.")
-      copy_tree(source_directory+'docs', destination_directory_latest)
-      shutil.rmtree(f"{destination_directory_latest}/_bin")
-      do_the_replace(destination_directory_latest, druid_version)
-  elif is_latest == 'n':
-      print("Not copying the docs to docs/latest")
-  else:
-      print("Enter y or n to make a choice")
+    if is_latest == 'y':
+        print("Also copying the docs to docs/latest.")
+        copy_tree(source_directory+'/docs', destination_directory_latest)
+        shutil.rmtree(f"{destination_directory_latest}/_bin")
+        do_the_replace(destination_directory_latest, druid_version)
+    elif is_latest == 'n':
+        print("Not copying the docs to docs/latest")
+    else:
+        print("Enter y or n to make a choice")
 
 
-def main(druid_version):
-
+def main(druid_version, source_directory="../../druid"):
+    is_valid, error_msg = check_source(source_directory)
+    if not is_valid:
+        quit(error_msg + "\n")
 
     # The destination_directory should be druid-website-src/docs/VERSION
     destination_directory = f"../docs/{druid_version}"
     destination_directory_latest = "../docs/latest"
 
     # Copies the docs
-    copy_tree(source_directory+"docs",destination_directory)
+    copy_tree(source_directory+"/docs", destination_directory)
 
     # deletes the _bin directory that's not needed
     shutil.rmtree(f"{destination_directory}/_bin")
 
     # Copy sidebars.json and redirects.json
-    
shutil.copyfile(source_directory+"website/sidebars.json","../sidebars.json")
-    shutil.copyfile(source_directory+"website/redirects.js","../redirects.js")
+    shutil.copyfile(source_directory+"/website/sidebars.json", 
"../sidebars.json")
+    shutil.copyfile(source_directory+"/website/redirects.js", 
"../redirects.js")
 
     do_the_replace(destination_directory, druid_version)
 
-    is_it_latest(druid_version, destination_directory_latest)
+    is_it_latest(druid_version, source_directory, destination_directory_latest)
 
 if __name__ == "__main__":
     import argparse
@@ -109,6 +129,10 @@ if __name__ == "__main__":
     parser.add_argument("-v", "--version", required=True,
                         help="Version to copy. Do not include 'latest'. "
                         "For example: -v 26.0.0")
+
+    parser.add_argument("-s", "--source", default="../../druid",
+                        help="The apache/druid folder to use as docs source.")
+
     args = parser.parse_args()
 
-    main(args.version)
+    main(args.version, args.source)
diff --git a/scripts/do_all_things.py b/scripts/do_all_things.py
index e125eb43..74a9f730 100644
--- a/scripts/do_all_things.py
+++ b/scripts/do_all_things.py
@@ -4,13 +4,13 @@ import shutil
 
 # Example: python do_all_things.py -v 26.0.0
 
-def main(versions, skip_install, use_yarn):
+def main(versions, source, skip_install, use_yarn):
 
     # copy the docs from apache/druid
-    copy_druid_docs.main(args.version)
+    copy_druid_docs.main(versions, source)
 
     # build all specified versions of the docs
-    build_docs.main([args.version, "latest"], skip_install, use_yarn)
+    build_docs.main([versions, "latest"], skip_install, use_yarn)
 
     print("Copying build output to ../published_versions. Use that directory 
to publish the site.")
     shutil.copytree('build','published_versions', dirs_exist_ok=True)
@@ -24,6 +24,9 @@ if __name__ == "__main__":
                         " since it's already accounted for. "
                         "For example: -v 26.0.0")
 
+    parser.add_argument("-s", "--source", default="../../druid",
+                        help="The apache/druid folder to use as docs source.")
+
     parser.add_argument("--skip-install", default=False,
                         help="Skip the Docusaurus 2 installation",
                         action='store_true')
@@ -34,5 +37,5 @@ if __name__ == "__main__":
 
     args = parser.parse_args()
 
-    main(args.version, args.skip_install, args.yarn)
+    main(args.version, args.source, args.skip_install, args.yarn)
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to