diff --git a/build_for_portal.py b/build_for_portal.py index 586e6bbec5bd..357bff6388ad 100644 --- a/build_for_portal.py +++ b/build_for_portal.py @@ -37,10 +37,11 @@ EXTERNAL_LINK_RE = re.compile( "[\./]*([\w_-]+)/[\w_/-]*?([\w_.-]*\.(?:html|adoc))", re.DOTALL ) -INCLUDE_RE = re.compile("include::(.*?)\[(.*?)\]", re.M) +INCLUDE_RE = re.compile(r"^include::(.*?)\[(.*?)\]", re.M) IFDEF_RE = re.compile(r"^if(n?)def::(.*?)\[\]", re.M) ENDIF_RE = re.compile(r"^endif::(.*?)\[\]\r?\n", re.M) COMMENT_CONTENT_RE = re.compile(r"^^////$.*?^////$", re.M | re.DOTALL) +COMMENTED_XREF_RE = re.compile(r"^//.*xref:.*$") TAG_CONTENT_RE = re.compile( r"//\s+tag::(.*?)\[\].*?// end::(.*?)\[\]", re.M | re.DOTALL ) @@ -625,10 +626,19 @@ def scrub_file(info, book_src_dir, src_file, tag=None, cwd=None): # data that it finds. # modified 20/Aug/2024 to process https links which are preceded # by an added directory (happens with hugeBook) + # Modified 05/Dec/2024 to allow for https links from openshift-kni repo. + # Check for both allowed URL patterns https_pos = base_src_file.find("https://raw.githubusercontent.com/openshift/") - if https_pos >=0: - base_src_file = base_src_file[https_pos:] + https_kni_pos = base_src_file.find("https://raw.githubusercontent.com/openshift-kni/") + + if https_pos >= 0 or https_kni_pos >= 0: + # Ensure we start from the correct URL (either github or openshift-kni) + if https_kni_pos >= 0: + base_src_file = base_src_file[https_kni_pos:] + else: + base_src_file = base_src_file[https_pos:] + try: response = requests.get(base_src_file) if response: @@ -656,6 +666,9 @@ def scrub_file(info, book_src_dir, src_file, tag=None, cwd=None): if line.strip() == "" and not content_found: continue + # Replace lines containing commented xrefs + line = COMMENTED_XREF_RE.sub("// Removed commented line that contains an xref", line) + # Check if the line should be included in the output if include_line(line): content_found = True diff --git a/makeBuild.py b/makeBuild.py index 9abe8bc9ee44..60a5b7b25df4 100755 --- a/makeBuild.py +++ b/makeBuild.py @@ -3,6 +3,7 @@ # uses a refactored Aura script which is an opensource port of ccutil +import argparse import sys import os import logging @@ -19,6 +20,15 @@ #print(branch) +def setup_parser(): + parser = argparse.ArgumentParser( + formatter_class=argparse.ArgumentDefaultsHelpFormatter + ) + parser.add_argument( + "--include-api-book", help="Include the rest_api book in the build", action="store_true", default=False, + ) + return parser + # function to convert XML ids to HTML 4 compatible ids from ccutil def _fix_ids_for_html4(tree): """ @@ -122,6 +132,10 @@ def build_book(book): # Initialize logging cli.init_logging(False, False) + +parser = setup_parser() +args = parser.parse_args() + for distro in os.listdir("drupal-build"): print("---------------------------------------") @@ -136,7 +150,9 @@ def build_book(book): continue # rest api book is a pain and doesn't convert well if book == "rest_api": - continue + # Exclude the REST API book unless we explicitly require it + if not args.include_api_book: + continue if os.path.exists(os.path.join("drupal-build", distro, book,"hugeBook.flag")): for secondary_book in os.listdir(os.path.join("drupal-build", distro, book)):