From 9a27d0b574b9bb289f4407d0568baacd2e211c08 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 04:59:21 +0100 Subject: [PATCH] refactor: name pack parts in one module The part and marker names of a split pack were built and matched in both the pack reader and the pack writer. The reader owns them now, both patterns built from one. --- install.ps1 | 2 +- install.py | 29 +++++++++++++++++------------ install.sh | 2 +- install/launchers/index.json | 16 ++++++++-------- installer/pack.py | 19 ++++++++----------- installer/pack_source.py | 20 +++++++++++++++++--- 6 files changed, 52 insertions(+), 36 deletions(-) diff --git a/install.ps1 b/install.ps1 index 9e95a543e..9014d129b 100644 --- a/install.ps1 +++ b/install.ps1 @@ -16,7 +16,7 @@ # and Invoke-WebRequest throws on a cut transfer before the hash is read: # the site's build rewrites this line there (scripts/sitebootstrap.py). $mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." - $defaultInstallSha256 = "658d9a948508e21fa5bdc8f5cfa4feb15d81bb58cf715f0fb355333d1f412c30" + $defaultInstallSha256 = "51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. $maximumInstallerBytes = 8MB diff --git a/install.py b/install.py index 86dcfff2e..61c0cec22 100644 --- a/install.py +++ b/install.py @@ -10742,7 +10742,22 @@ def _requested_narrowing( # (scripts/split_pack.py), each holding at its root a marker that names the # pack, the part and every part with its size. Extracted with the files, # the markers say which part a folder lacks. -_PART_FILE = re.compile(r"^(?P.+_BIOS_Pack)\.part(?P\d+)of(?P\d+)\.zip$") +def _part_pattern(ext: str) -> re.Pattern: + return re.compile(rf"^(?P.+_BIOS_Pack)\.part(?P\d+)of(?P\d+)\.{ext}$") + + +_PART_FILE = _part_pattern("zip") +_PART_MARKER = _part_pattern("txt") + + +def part_file_name(name: str, index: int, count: int) -> str: + """Part index of count of the pack name.""" + return f"{name[: -len('.zip')]}.part{index}of{count}.zip" + + +def part_marker_name(name: str, index: int, count: int) -> str: + """The marker part index of count of the pack name holds.""" + return f"{name[: -len('.zip')]}.part{index}of{count}.txt" MAX_PARTS = 999 @@ -10835,12 +10850,11 @@ class PackSource: count = counts[0] if count > MAX_PARTS or any(other != count for other in counts): raise ValueError(f"the parts of {name} disagree on how many there are") - stem = name[: -len(".zip")] folders = list(dict.fromkeys(p.parent for p in chosen)) found: list[Path] = [] missing: list[str] = [] for number in range(1, count + 1): - part_name = f"{stem}.part{number}of{count}.zip" + part_name = part_file_name(name, number, count) place = next((folder / part_name for folder in folders if (folder / part_name).is_file()), None) if place is None: @@ -18525,7 +18539,6 @@ def read_games(args: argparse.Namespace, plat: str, bios_path: Path, manifest: d # --- installer/pack.py ------------------------------------------------------- -_PART_MARKER = re.compile(r"^(?P.+_BIOS_Pack)\.part(?P\d+)of(?P\d+)\.txt$") MAX_MARKER_BYTES = 64 * 1024 @@ -18796,14 +18809,6 @@ def pack_bound(manifest_size: int, members: list[PackMember]) -> int: + sum(_member_bound(member.name, member.size) for member in members)) -def part_file_name(name: str, index: int, count: int) -> str: - return f"{name[: -len('.zip')]}.part{index}of{count}.zip" - - -def part_marker_name(name: str, index: int, count: int) -> str: - return f"{name[: -len('.zip')]}.part{index}of{count}.txt" - - def part_marker_text(name: str, index: int, sizes: list[int]) -> bytes: """The marker of part index, in the words scripts/split_pack.py writes and read_part_marker reads back.""" diff --git a/install.sh b/install.sh index 356acd388..afe182d08 100755 --- a/install.sh +++ b/install.sh @@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins # curl or wget stop on a cut transfer before the hash is read: the site's # build rewrites this line there (scripts/sitebootstrap.py). MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." -DEFAULT_INSTALL_SHA256="658d9a948508e21fa5bdc8f5cfa4feb15d81bb58cf715f0fb355333d1f412c30" +DEFAULT_INSTALL_SHA256="51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. MAX_INSTALLER_BYTES=8388608 diff --git a/install/launchers/index.json b/install/launchers/index.json index 2137b879d..72e7e2fa1 100644 --- a/install/launchers/index.json +++ b/install/launchers/index.json @@ -27,8 +27,8 @@ { "dest": "roms/ports/retrobios/install.py", "repo_path": "install.py", - "size": 1449101, - "sha256": "658d9a948508e21fa5bdc8f5cfa4feb15d81bb58cf715f0fb355333d1f412c30", + "size": 1449198, + "sha256": "51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1", "executable": false }, { @@ -71,8 +71,8 @@ "muos": { "archive": { "dest": "ARCHIVE/RetroBIOS.muxapp", - "size": 1502726, - "sha256": "2465c1d4f53c2935dc33de6eb966be2dab3dcff5f438850855bb98b828ef889b" + "size": 1502823, + "sha256": "a89d78536fbb9c9642f57a879b7895f1d01607c57f781cdeeccaa54851db205f" }, "members": [ { @@ -92,8 +92,8 @@ { "name": "RetroBIOS/install.py", "repo_path": "install.py", - "size": 1449101, - "sha256": "658d9a948508e21fa5bdc8f5cfa4feb15d81bb58cf715f0fb355333d1f412c30", + "size": 1449198, + "sha256": "51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1", "executable": false }, { @@ -166,8 +166,8 @@ { "dest": ".config/modules/retrobios/install.py", "repo_path": "install.py", - "size": 1449101, - "sha256": "658d9a948508e21fa5bdc8f5cfa4feb15d81bb58cf715f0fb355333d1f412c30", + "size": 1449198, + "sha256": "51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1", "executable": false }, { diff --git a/installer/pack.py b/installer/pack.py index 381fd840c..39398a939 100644 --- a/installer/pack.py +++ b/installer/pack.py @@ -7,7 +7,6 @@ import hashlib import io import json import os -import re import shutil import stat import sys @@ -29,7 +28,14 @@ from installer.from_folders import plan_local_copies from installer.host_fs import DRIVE_FULL, _drive_full, _is_dir, _stop from installer.network import fetch_targets, local_targets from installer.offline import LOCAL -from installer.pack_source import MAX_PARTS, _PART_FILE, pack_name_platforms +from installer.pack_source import ( + _PART_FILE, + _PART_MARKER, + MAX_PARTS, + pack_name_platforms, + part_file_name, + part_marker_name, +) from installer.paths import shown_path from installer.platforms import PLATFORM_NAMES, TARGET_PLATFORMS, display_name from installer.safe_replace import BACKUP_DIR @@ -38,7 +44,6 @@ from installer.text import _plural, format_size, screen_text if TYPE_CHECKING: from installer.terminal import Terminal -_PART_MARKER = re.compile(r"^(?P.+_BIOS_Pack)\.part(?P\d+)of(?P\d+)\.txt$") MAX_MARKER_BYTES = 64 * 1024 @@ -309,14 +314,6 @@ def pack_bound(manifest_size: int, members: list[PackMember]) -> int: + sum(_member_bound(member.name, member.size) for member in members)) -def part_file_name(name: str, index: int, count: int) -> str: - return f"{name[: -len('.zip')]}.part{index}of{count}.zip" - - -def part_marker_name(name: str, index: int, count: int) -> str: - return f"{name[: -len('.zip')]}.part{index}of{count}.txt" - - def part_marker_text(name: str, index: int, sizes: list[int]) -> bytes: """The marker of part index, in the words scripts/split_pack.py writes and read_part_marker reads back.""" diff --git a/installer/pack_source.py b/installer/pack_source.py index d81781809..17aecabd8 100644 --- a/installer/pack_source.py +++ b/installer/pack_source.py @@ -25,7 +25,22 @@ if TYPE_CHECKING: # (scripts/split_pack.py), each holding at its root a marker that names the # pack, the part and every part with its size. Extracted with the files, # the markers say which part a folder lacks. -_PART_FILE = re.compile(r"^(?P.+_BIOS_Pack)\.part(?P\d+)of(?P\d+)\.zip$") +def _part_pattern(ext: str) -> re.Pattern: + return re.compile(rf"^(?P.+_BIOS_Pack)\.part(?P\d+)of(?P\d+)\.{ext}$") + + +_PART_FILE = _part_pattern("zip") +_PART_MARKER = _part_pattern("txt") + + +def part_file_name(name: str, index: int, count: int) -> str: + """Part index of count of the pack name.""" + return f"{name[: -len('.zip')]}.part{index}of{count}.zip" + + +def part_marker_name(name: str, index: int, count: int) -> str: + """The marker part index of count of the pack name holds.""" + return f"{name[: -len('.zip')]}.part{index}of{count}.txt" MAX_PARTS = 999 @@ -118,12 +133,11 @@ class PackSource: count = counts[0] if count > MAX_PARTS or any(other != count for other in counts): raise ValueError(f"the parts of {name} disagree on how many there are") - stem = name[: -len(".zip")] folders = list(dict.fromkeys(p.parent for p in chosen)) found: list[Path] = [] missing: list[str] = [] for number in range(1, count + 1): - part_name = f"{stem}.part{number}of{count}.zip" + part_name = part_file_name(name, number, count) place = next((folder / part_name for folder in folders if (folder / part_name).is_file()), None) if place is None: