From 74dfec85fb35ea8a0f9037ed4f70eecf76a45854 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Mon, 6 Nov 2023 16:02:08 +0100 Subject: [PATCH] Remove old manifests and put everything in folders (#2026) --- tagging/update_wiki.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tagging/update_wiki.py b/tagging/update_wiki.py index 2796b7e28..d92027923 100755 --- a/tagging/update_wiki.py +++ b/tagging/update_wiki.py @@ -45,12 +45,36 @@ def update_monthly_wiki_page( monthly_page.write_text(monthly_page_content) +def get_manifest_timestamp(manifest_file: Path) -> str: + file_content = manifest_file.read_text() + pos = file_content.find("Build datetime: ") + return file_content[pos + 16 : pos + 36] + + +def get_manifest_month(manifest_file: Path) -> str: + return get_manifest_timestamp(manifest_file)[:10] + + +def remove_old_manifests(wiki_dir: Path) -> None: + MAX_NUMBER_OF_MANIFESTS = 4500 + + manifest_files = [] + for file in (wiki_dir / "manifests").rglob("*.md"): + manifest_files.append((get_manifest_timestamp(file), file)) + + manifest_files.sort(reverse=True) + for _, file in manifest_files[MAX_NUMBER_OF_MANIFESTS:]: + LOGGER.info(f"Removing manifest: {file.name}") + file.unlink() + + def update_wiki(wiki_dir: Path, hist_line_dir: Path, manifest_dir: Path) -> None: LOGGER.info("Updating wiki") LOGGER.info("Copying manifest files") for manifest_file in manifest_dir.glob("*.md"): - shutil.copy(manifest_file, wiki_dir / "manifests" / manifest_file.name) + month = get_manifest_month(manifest_file) + shutil.copy(manifest_file, wiki_dir / "manifests" / month / manifest_file.name) LOGGER.info(f"Manifest file added: {manifest_file.name}") for build_history_line_file in sorted(hist_line_dir.glob("*.txt")): @@ -60,6 +84,8 @@ def update_wiki(wiki_dir: Path, hist_line_dir: Path, manifest_dir: Path) -> None update_home_wiki_page(wiki_dir, month) update_monthly_wiki_page(wiki_dir, month, build_history_line) + remove_old_manifests(wiki_dir) + if __name__ == "__main__": logging.basicConfig(level=logging.INFO)