|
9 | 9 | LOGGER = logging.getLogger(__name__) |
10 | 10 |
|
11 | 11 |
|
12 | | -def update_home_wiki_page(wiki_dir: Path, year_month: str) -> None: |
| 12 | +def regenerate_home_wiki_page(wiki_dir: Path) -> None: |
13 | 13 | YEAR_MONTHLY_TABLES = "<!-- YEAR_MONTHLY_TABLES -->\n" |
14 | 14 |
|
15 | | - TABLE_HEADER = """\ |
16 | | -| Month | |
17 | | -| ---------------------- | |
| 15 | + YEAR_TABLE_HEADER = """\ |
| 16 | +## {year} |
| 17 | +
|
| 18 | +| Month | Builds | Images | |
| 19 | +| ---------------------- | ------ | ------ | |
18 | 20 | """ |
19 | 21 |
|
20 | 22 | wiki_home_file = wiki_dir / "Home.md" |
21 | 23 | wiki_home_content = wiki_home_file.read_text() |
22 | 24 |
|
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 | + ) |
40 | 46 |
|
41 | 47 | wiki_home_file.write_text(wiki_home_content) |
| 48 | + LOGGER.info("Updated Home page") |
42 | 49 |
|
43 | 50 |
|
44 | 51 | def update_monthly_wiki_page( |
@@ -114,9 +121,9 @@ def update_wiki(wiki_dir: Path, hist_lines_dir: Path, manifests_dir: Path) -> No |
114 | 121 | build_history_line = build_history_line_file.read_text() |
115 | 122 | assert build_history_line.startswith("| `") |
116 | 123 | year_month = build_history_line[3:10] |
117 | | - update_home_wiki_page(wiki_dir, year_month) |
118 | 124 | update_monthly_wiki_page(wiki_dir, year_month, build_history_line) |
119 | 125 |
|
| 126 | + regenerate_home_wiki_page(wiki_dir) |
120 | 127 | remove_old_manifests(wiki_dir) |
121 | 128 |
|
122 | 129 |
|
|
0 commit comments