mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-24 10:37:54 -06:00
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:
1 parent
b338d94fa0
commit
9a27d0b574
6 files changed
+52
-36
No files matched your search
+1
-1
@@ -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
|
||||
|
||||
+17
-12
@@ -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<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
|
||||
|
||||
@@ -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<stem>.+_BIOS_Pack)\.part(?P<index>\d+)of(?P<count>\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."""
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
},
|
||||
{
|
||||
|
||||
+8
-11
@@ -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<stem>.+_BIOS_Pack)\.part(?P<index>\d+)of(?P<count>\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."""
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user