amoghrajesh commented on code in PR #792: URL: https://github.com/apache/airflow-site/pull/792#discussion_r1220903688
########## post-docs/add-back-references.py: ########## @@ -0,0 +1,81 @@ +import os +import shutil +from urllib.request import urlopen +import semver + +docs_link = "https://raw.githubusercontent.com/apache/airflow/main/docs/apache-airflow/redirects.txt" +docs_archive_path = "../docs-archive" +apache_airflow_path = docs_archive_path + "/apache-airflow" +stable_version_path = apache_airflow_path + "/stable.txt" +new_docs_version = "2.5.1" + + +def download_file(url): + filedata = urlopen(url) + datatowrite = filedata.read() + + with open('redirects.txt', 'wb') as f: + f.write(datatowrite) + + +def construct_mapping(): + old_to_new_map = dict() + with open('redirects.txt') as f: + file_content = [] + lines = f.readlines() + # Skip empty line + + for line in lines: + if not line.strip(): + continue + + # Skip comments + if line.startswith("#"): + continue + + line = line.rstrip() + file_content.append(line) + + old_path, new_path = line.split(" ") + old_path = old_path.replace(".rst", ".html") + new_path = new_path.replace(".rst", ".html") + + old_to_new_map[old_path] = new_path + return old_to_new_map + + +def get_stable_version(): + version = '' + with open(stable_version_path) as f: + lines = f.readlines() + version = lines[0].rstrip() + return version + + +def version_is_less_than(a): + return semver.compare(a, new_docs_version) == -1 + + +download_file(docs_link) +old_to_new = construct_mapping() +stable = get_stable_version() + +versions = [f.path.split("/")[-1] for f in os.scandir(apache_airflow_path) if f.is_dir()] +versions = [v for v in versions if version_is_less_than(v)] + +for version in versions: + r = apache_airflow_path + "/" + version + + for p in old_to_new: + if os.path.exists(r + "/" + p): + d = old_to_new[p].split("/") + file_name = old_to_new[p].split("/")[-1] + dest_fpath = r + "/" + "/".join(d[: len(d) - 1]) + os.makedirs(dest_fpath, exist_ok=True) + + dest_fpath = dest_fpath + "/" + file_name + + if not os.path.exists(dest_fpath): + shutil.copy(r + "/" + p, dest_fpath) Review Comment: Yeah, thanks for the catch. Integrated with latest commit -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
