From 7e75078a8b04abb1046c97b6c4521c2b0e252048 Mon Sep 17 00:00:00 2001 From: Francois Andrieu Date: Feb 09 2022 07:55:08 +0000 Subject: hardlinking each lang: take 2 --- diff --git a/build-scripts/rebuild-site.py b/build-scripts/rebuild-site.py index 861b794..fde6c07 100755 --- a/build-scripts/rebuild-site.py +++ b/build-scripts/rebuild-site.py @@ -48,7 +48,7 @@ def get_config(): def log(msg): - print(msg) + print(msg, flush=True) def get_languages(config): @@ -400,6 +400,7 @@ def main(): log(" {lang} done".format(lang=lang)) # Building all the translated sites + lastlang = list(languages)[-1] for lang in languages: log("") log("===== Building the {lang} site =====".format(lang=lang)) @@ -411,47 +412,52 @@ def main(): log("ERROR building the {lang} site".format(lang=lang)) sys.exit(1) - # Copying all the translated sites - log("") - log("=== Copying translated sites ===") - - results_dir = os.path.join(docs_repo, "public") - publish_dir = "/antora/output" - copying_dir = os.path.join(publish_dir, "copying.tmp") - - # I have: - # docs_repo/public <- results_dir (local partition) - # /antora/output/copying.tmp <- copying_dir (mounted partition) - # /antora/output <- publish_dir (mounted partition) - # - # I need to: - # 1/ copy from local to mounted - # 2/ remove old in mounted - # 3/ move new within mounted - # 4/ remove the copying dir - - # Make sure copying_dir exists and is empty - shutil.rmtree(copying_dir, ignore_errors=True) - subprocess.run(["mkdir", copying_dir]) - - # Copy results from local partition to a mounted partition - log("Copying between partitions...") - subprocess.run(["cp", "-a", results_dir, "{}/".format(copying_dir)]) - - # Swap the old tree for the new one for each language - log("Moving languages to the final place:") - for lang in languages: - log(" - {}".format(lang)) - shutil.rmtree(os.path.join(publish_dir, lang), ignore_errors=True) - subprocess.run(["mv", os.path.join(copying_dir, "public", lang), "{}/".format(publish_dir)]) + # Copying the translated site + log("") + log(f"=== Copying the {lang} site ===") + + results_dir = os.path.join(docs_repo, "public", lang) + publish_dir = f"/antora/output/{lang}" + copying_dir = f"/antora/output/{lang}.tmp" + lastlang_dir = f"/antora/output/{lastlang}" + + # I have: + # docs_repo/public/xx <- results_dir (local partition) + # /antora/output/xx.tmp <- copying_dir (mounted partition) + # /antora/output/xx <- publish_dir (mounted partition) + # + # I need to: + # 1/ copy from local to mounted + # 2/ remove old in mounted + # 3/ move new within mounted + # 4/ remove the copying dir + + # Make sure copying_dir doesn't exist + shutil.rmtree(copying_dir, ignore_errors=True) + + # Copy results from local partition to a mounted partition + log(f"Copying from {results_dir} to {copying_dir}") + subprocess.run(["cp", "-a", results_dir, copying_dir]) + + # Swap the old tree for the new one for each language + log(f"Moving language to the final place: {copying_dir} to {publish_dir}") + shutil.rmtree(publish_dir, ignore_errors=True) + subprocess.run(["mv", copying_dir, publish_dir]) + + # Recreate hardlinks as we go, in case the rsync job + # start while we are still building + if (lang != lastlang): + log(f"hardlinking files: {publish_dir} - {lastlang_dir}") + subprocess.run(["hardlink", "-cv", publish_dir, lastlang_dir]) + + # Remove local build + shutil.rmtree(results_dir, ignore_errors=True) + + # End Building all the translated sites # https://pagure.io/fedora-infrastructure/issue/8964 log("Consolidate files with hardlink...") - subprocess.run(["hardlink", "-v", "{}/".format(publish_dir)]) - - # And finally remove the copying dir - log("Removing the copying dir...") - shutil.rmtree(copying_dir, ignore_errors=True) + subprocess.run(["hardlink", "-cv", "/antora/output/"]) log("DONE!")