Skip to content

Commit

Permalink
Remove old manifests and put everything in folders (#2026)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathbunnyru authored Nov 6, 2023
1 parent 6e880b0 commit 74dfec8
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tagging/update_wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")):
Expand All @@ -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)
Expand Down

0 comments on commit 74dfec8

Please sign in to comment.