diff --git a/scripts/sitegen/getpages.py b/scripts/sitegen/getpages.py index b5132225f..a6c96d9a0 100644 --- a/scripts/sitegen/getpages.py +++ b/scripts/sitegen/getpages.py @@ -47,6 +47,43 @@ def _unzip_into(platform_name: str, display: str, extract_to: str | None, parts: ] +def _pack_lines(platform_name: str, display: str, record: dict, pack: dict) -> list[str]: + """The ZIP of a release and the command, on its get/ page. A pack in + parts puts the command first: 3,236 people took part 1 of the RetroArch + pack and 2,404 part 3, and the command has no part to miss. A pack in + one file keeps its ZIP first, the command after it.""" + parts = len(pack["assets"]) + release = release_line(platform_name, record) + extract_to = (load_platform_registry(str(siteinputs.current().platforms)).get(platform_name) or {}).get("extract_to") + command = setup_routes(platform_name, display) + download = [ + "This address stays the same. It always gives the latest ZIP.", + "", + asset_links(platform_name, record, REPO_URL, f"Download {display} Pack", + button=lambda text, url: markup.button(text, url, primary=True)), + "", + f"- {fmt_size(pack['download_size'])} to download, " + f"{fmt_size(pack['extracted_size'])} once unzipped.", + *(["- Both parts are needed." if parts == 2 else f"- All {parts} parts are needed."] + if parts > 1 else []), + *_unzip_into(platform_name, display, extract_to, parts), + *(line for text in release for line in (text, "")), + version_line(platform_name, record, named=len(release) > 1), + "", + ] + if parts == 1: + return [*download, *command] + return [ + f"The ZIP comes in {parts} parts, all needed. The command needs no ZIP. " + "It installs every file and checks it.", + "", + *command, + f"## Or download the {parts} parts {{ #download }}", + "", + *download, + ] + + def generate_get_page(platform_name: str) -> str: """get//: the address a link outside the site can keep. @@ -77,24 +114,7 @@ def generate_get_page(platform_name: str) -> str: f"# {title}", "", ] if released and pack and pack.get("assets"): - parts = len(pack["assets"]) - release = release_line(platform_name, record) - extract_to = (load_platform_registry(str(siteinputs.current().platforms)).get(platform_name) or {}).get("extract_to") - lines += [ - "This address stays the same. It always gives the latest ZIP.", - "", - asset_links(platform_name, record, REPO_URL, f"Download {display} Pack", - button=lambda text, url: markup.button(text, url, primary=True)), - "", - f"- {fmt_size(pack['download_size'])} to download, " - f"{fmt_size(pack['extracted_size'])} once unzipped.", - *(["- Both parts are needed." if parts == 2 else f"- All {parts} parts are needed."] - if parts > 1 else []), - *_unzip_into(platform_name, display, extract_to, parts), - *(line for text in release for line in (text, "")), - version_line(platform_name, record, named=len(release) > 1), - "", - ] + lines += _pack_lines(platform_name, display, record, pack) elif released and record.get("tag"): lines += [ f"No {display} ZIP yet. The next release has one. " diff --git a/tests/test_release_packs.py b/tests/test_release_packs.py index 9501950c0..8864453d6 100644 --- a/tests/test_release_packs.py +++ b/tests/test_release_packs.py @@ -493,6 +493,41 @@ class EveryPlatformHasAPermanentPage(unittest.TestCase): self.assertIn(f"/i | sh -s -- --platform {name}", page) self.assertIn("No ZIP for ", page) + def test_a_pack_in_parts_puts_the_command_first(self): + """3,236 people took part 1 of the RetroArch pack and 2,404 part 3. + The command installs everything with no part to miss.""" + from sitegen import getpages + + record = releaserecord.load_advertised() + split = [name for name in sorted(RELEASED) + if len((releaserecord.pack_for(name, record) or {}).get("assets") or []) > 1] + if not split: + self.skipTest("no release publishes a pack in parts") + with contextlib.chdir(REPO_ROOT): + for name in split: + page = getpages.generate_get_page(name) + parts = len(releaserecord.pack_for(name, record)["assets"]) + with self.subTest(platform=name): + command = page.index(f"--platform {name}") + self.assertLess(command, page.index(f"## Or download the {parts} parts")) + self.assertLess(command, page.index(".part1of")) + self.assertIn(f"All {parts} parts are needed.", page) + + def test_a_pack_in_one_file_keeps_its_zip_first(self): + from sitegen import getpages + + record = releaserecord.load_advertised() + whole = [name for name in sorted(RELEASED) + if len((releaserecord.pack_for(name, record) or {}).get("assets") or []) == 1] + if not whole: + self.skipTest("no release publishes a pack in one file") + with contextlib.chdir(REPO_ROOT): + for name in whole: + page = getpages.generate_get_page(name) + with self.subTest(platform=name): + self.assertLess(page.index("_BIOS_Pack.zip"), page.index(f"--platform {name}")) + self.assertNotIn("parts are needed", page) + def test_the_generator_writes_and_sweeps_them(self): from sitegen import config