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.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:04:39 +01:00
1 parent b338d94fa0
commit 9a27d0b574
6 files changed
+52 -36

No files matched your search

+17 -3
View File
@@ -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<stem>.+_BIOS_Pack)\.part(?P<index>\d+)of(?P<count>\d+)\.zip$")
def _part_pattern(ext: str) -> re.Pattern:
return re.compile(rf"^(?P<stem>.+_BIOS_Pack)\.part(?P<index>\d+)of(?P<count>\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: