Skip to content

Commit a41b6e8

Browse files
committed
Add some statistics to wiki page
1 parent c175251 commit a41b6e8

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

tagging/update_wiki.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,43 @@
99
LOGGER = logging.getLogger(__name__)
1010

1111

12-
def update_home_wiki_page(wiki_dir: Path, year_month: str) -> None:
12+
def regenerate_home_wiki_page(wiki_dir: Path) -> None:
1313
YEAR_MONTHLY_TABLES = "<!-- YEAR_MONTHLY_TABLES -->\n"
1414

15-
TABLE_HEADER = """\
16-
| Month |
17-
| ---------------------- |
15+
YEAR_TABLE_HEADER = """\
16+
## {year}
17+
18+
| Month | Builds | Images |
19+
| ---------------------- | ------ | ------ |
1820
"""
1921

2022
wiki_home_file = wiki_dir / "Home.md"
2123
wiki_home_content = wiki_home_file.read_text()
2224

23-
year = year_month[:4]
24-
year_header = f"## {year}\n"
25-
if year_header not in wiki_home_content:
26-
assert YEAR_MONTHLY_TABLES in wiki_home_content
27-
wiki_home_content = wiki_home_content.replace(
28-
YEAR_MONTHLY_TABLES,
29-
YEAR_MONTHLY_TABLES + f"\n{year_header}\n{TABLE_HEADER}",
30-
)
31-
LOGGER.info(f"Updated wiki home page with year header for year: {year}")
32-
33-
year_month_line = f"| [`{year_month}`](./{year_month}) |\n"
34-
if year_month_line not in wiki_home_content:
35-
assert TABLE_HEADER in wiki_home_content
36-
wiki_home_content = wiki_home_content.replace(
37-
TABLE_HEADER, TABLE_HEADER + year_month_line
38-
)
39-
LOGGER.info(f"Updated wiki home page with month: {year_month}")
25+
assert YEAR_MONTHLY_TABLES in wiki_home_content
26+
wiki_home_content = wiki_home_content[
27+
: wiki_home_content.find(YEAR_MONTHLY_TABLES) + len(YEAR_MONTHLY_TABLES)
28+
]
29+
30+
all_year_dirs = sorted((wiki_dir / "monthly-files").glob("*"), reverse=True)
31+
for year_dir in all_year_dirs:
32+
wiki_home_content += "\n" + YEAR_TABLE_HEADER.format(year=year_dir.name)
33+
34+
all_year_month_files = sorted(year_dir.glob("*.md"), reverse=True)
35+
for year_month_file in all_year_month_files:
36+
year_month_file_content = year_month_file.read_text()
37+
images = year_month_file_content.count("Build manifest")
38+
builds = sum(
39+
"jupyter/base-notebook" in line and "aarch64" not in line
40+
for line in year_month_file_content.split("\n")
41+
)
42+
year_month = year_month_file.stem
43+
wiki_home_content += (
44+
f"| [`{year_month}`](./{year_month}) | {builds: <6} | {images: <6} |\n"
45+
)
4046

4147
wiki_home_file.write_text(wiki_home_content)
48+
LOGGER.info("Updated Home page")
4249

4350

4451
def update_monthly_wiki_page(
@@ -114,9 +121,9 @@ def update_wiki(wiki_dir: Path, hist_lines_dir: Path, manifests_dir: Path) -> No
114121
build_history_line = build_history_line_file.read_text()
115122
assert build_history_line.startswith("| `")
116123
year_month = build_history_line[3:10]
117-
update_home_wiki_page(wiki_dir, year_month)
118124
update_monthly_wiki_page(wiki_dir, year_month, build_history_line)
119125

126+
regenerate_home_wiki_page(wiki_dir)
120127
remove_old_manifests(wiki_dir)
121128

122129

0 commit comments

Comments
 (0)