mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-24 18:47:53 -06:00
refactor: public names for cross-module reads
This commit is contained in:
1 parent
f371790dc6
commit
3853ca2f1c
254 files changed
+2955
-2969
No files matched your search
@@ -136,7 +136,7 @@ def _member_held(member: dict, crcs: frozenset[str], names: frozenset[str]) -> b
|
||||
return named
|
||||
|
||||
|
||||
def _holding_members(paths: list[str], members: list[dict]) -> list[str]:
|
||||
def holding_members(paths: list[str], members: list[dict]) -> list[str]:
|
||||
"""The same-named archives holding the most required members, then the most members.
|
||||
|
||||
FBNeo reads neocd.bin and 000-lo.lo inside neocdz.zip. The primary copy,
|
||||
@@ -157,7 +157,7 @@ def _holding_members(paths: list[str], members: list[dict]) -> list[str]:
|
||||
return [path for path in paths if scores[path] == best]
|
||||
|
||||
|
||||
def _covering_archives(paths: list[str]) -> list[str]:
|
||||
def covering_archives(paths: list[str]) -> list[str]:
|
||||
"""Same-named archives, those holding every ROM each other copy holds.
|
||||
|
||||
Without a declared layout, a primary that is a superset of the other
|
||||
@@ -185,7 +185,7 @@ def _covering_archives(paths: list[str]) -> list[str]:
|
||||
_unreadable_archives: set[str] = set()
|
||||
|
||||
|
||||
def _warn_unreadable_archive(path: str, exc: Exception) -> None:
|
||||
def warn_unreadable_archive(path: str, exc: Exception) -> None:
|
||||
"""Say once that an archive on disk cannot be read.
|
||||
|
||||
Skipped in silence, a truncated ZIP came out as not_found or
|
||||
|
||||
@@ -16,10 +16,10 @@ from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
from model.systems import _norm_system_id
|
||||
from model.systems import norm_system_id
|
||||
from resolve.cores import resolve_platform_cores, unresolved_platform_cores
|
||||
from resolve.reconcile import HASH_FIELDS, NativeSystem, _hash_values
|
||||
from resolve.launchers import _names as launcher_names
|
||||
from resolve.reconcile import HASH_FIELDS, NativeSystem, hash_values
|
||||
from resolve.launchers import record_names as launcher_names
|
||||
|
||||
|
||||
def _tails(path: str) -> list[str]:
|
||||
@@ -29,17 +29,17 @@ def _tails(path: str) -> list[str]:
|
||||
|
||||
|
||||
def _entry_hashes(entry: dict) -> set[str]:
|
||||
values = {v for f in HASH_FIELDS for v in _hash_values(entry, f)}
|
||||
values = {v for f in HASH_FIELDS for v in hash_values(entry, f)}
|
||||
for member in entry.get("contents") or []:
|
||||
if isinstance(member, dict):
|
||||
values |= {v for f in HASH_FIELDS for v in _hash_values(member, f)}
|
||||
values |= {v for f in HASH_FIELDS for v in hash_values(member, f)}
|
||||
return values
|
||||
|
||||
|
||||
def _declared_hashes(entry: dict) -> dict[str, set[str]]:
|
||||
"""Hash field -> the values a platform entry declares, alt_md5 as md5."""
|
||||
found = {f: set(_hash_values(entry, f)) for f in HASH_FIELDS}
|
||||
found["md5"] |= set(_hash_values(entry, "alt_md5"))
|
||||
found = {f: set(hash_values(entry, f)) for f in HASH_FIELDS}
|
||||
found["md5"] |= set(hash_values(entry, "alt_md5"))
|
||||
return {f: values for f, values in found.items() if values}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ def _contradicts(profile_entry: dict, declared: dict[str, set[str]]) -> bool:
|
||||
"""True when both sides state the same kind of hash and no value agrees:
|
||||
the profile entry describes another dump under the same name."""
|
||||
for field_name, values in declared.items():
|
||||
own = set(_hash_values(profile_entry, field_name))
|
||||
own = set(hash_values(profile_entry, field_name))
|
||||
if own and not set(values) & set(own):
|
||||
return True
|
||||
return False
|
||||
@@ -138,7 +138,7 @@ class ReadEvidence:
|
||||
if names & self.names or (tails and tails[-1] in self.names):
|
||||
return "name"
|
||||
hashes = {
|
||||
v for f in (*HASH_FIELDS, "alt_md5") for v in _hash_values(entry, f)
|
||||
v for f in (*HASH_FIELDS, "alt_md5") for v in hash_values(entry, f)
|
||||
}
|
||||
if hashes & self.hashes:
|
||||
return "hash"
|
||||
@@ -196,7 +196,7 @@ class ProofIndex:
|
||||
tails = _tails(destination)
|
||||
last = {tails[-1]} if tails else set()
|
||||
hashes = {
|
||||
v for f in (*HASH_FIELDS, "alt_md5") for v in _hash_values(entry, f)
|
||||
v for f in (*HASH_FIELDS, "alt_md5") for v in hash_values(entry, f)
|
||||
}
|
||||
# "/" + d in "/" + path: d is a run of whole segments ending in "/",
|
||||
# so it is a run of the path's segments before the last one.
|
||||
@@ -275,7 +275,7 @@ def removal_candidates(
|
||||
by_system: dict[str, list[str]] = {}
|
||||
for key in sorted(examined):
|
||||
for sid in profiles[key].get("systems") or []:
|
||||
by_system.setdefault(_norm_system_id(str(sid)), []).append(key)
|
||||
by_system.setdefault(norm_system_id(str(sid)), []).append(key)
|
||||
|
||||
romset_cores = {key for key in examined if _loads_romsets(profiles[key])}
|
||||
|
||||
@@ -287,7 +287,7 @@ def removal_candidates(
|
||||
if evidence.proof(entry.platform, entry.destination) is not None:
|
||||
continue
|
||||
slug = system_of.get(id(entry.platform), entry.native_system)
|
||||
cores = by_system.get(_norm_system_id(slug), [])
|
||||
cores = by_system.get(norm_system_id(slug), [])
|
||||
readers = (
|
||||
[c for c in cores if c in romset_cores]
|
||||
if entry.name.casefold().endswith(_ARCHIVES) else []
|
||||
@@ -370,7 +370,7 @@ class EntryCategories:
|
||||
self._by_system: dict[str, list[str]] = {}
|
||||
for key in sorted(examined):
|
||||
for sid in profiles[key].get("systems") or []:
|
||||
self._by_system.setdefault(_norm_system_id(str(sid)), []).append(key)
|
||||
self._by_system.setdefault(norm_system_id(str(sid)), []).append(key)
|
||||
# Where the platform says which cores run a system, those settle its
|
||||
# entries: an unprofiled core of another system has no say.
|
||||
self._system_runs: dict[str, tuple[list[str], list[str]]] = {}
|
||||
@@ -461,7 +461,7 @@ class EntryCategories:
|
||||
if system in self._system_runs:
|
||||
system_cores, unresolved = self._system_runs[system]
|
||||
else:
|
||||
system_cores = self._by_system.get(_norm_system_id(system), [])
|
||||
system_cores = self._by_system.get(norm_system_id(system), [])
|
||||
unresolved = self._unresolved
|
||||
# A reader that runs the entry's system comes first and says so: a
|
||||
# core of another system may only share the file's name.
|
||||
|
||||
@@ -9,10 +9,10 @@ from dataclasses import dataclass, field
|
||||
from core.hashing import compute_hashes, parse_md5_list
|
||||
from core.ziptools import check_inside_zip
|
||||
from resolve.localfile import resolve_local_file, variant_base_name
|
||||
from resolve.packfiles import _records_by_path, preferred_entries
|
||||
from resolve.packfiles import records_by_path, preferred_entries
|
||||
|
||||
|
||||
def _normalize(destination: str, fold: bool = True) -> str:
|
||||
def comparable_destination(destination: str, fold: bool = True) -> str:
|
||||
"""Comparable form of a destination, since layers write it differently.
|
||||
|
||||
Case is folded only where the platform's filesystem folds it: on Linux
|
||||
@@ -66,7 +66,7 @@ def find_collisions(
|
||||
continue
|
||||
dest = entry.get("destination") or entry.get("name") or ""
|
||||
if dest:
|
||||
by_dest.setdefault(_normalize(dest, fold), []).append((sys_id, entry))
|
||||
by_dest.setdefault(comparable_destination(dest, fold), []).append((sys_id, entry))
|
||||
|
||||
collisions = []
|
||||
for key, claims in sorted(by_dest.items()):
|
||||
@@ -90,7 +90,7 @@ def find_collisions(
|
||||
# A file every declaration accepts settles the path: RetroDECK
|
||||
# declares ATARIOSB.ROM twice, the second with an md5 list that
|
||||
# also names the first one's file.
|
||||
if any(_accepted_by_all(path, entries, db) for path in resolved):
|
||||
if any(accepted_by_all(path, entries, db) for path in resolved):
|
||||
continue
|
||||
reached = sorted(
|
||||
(sys_id, local)
|
||||
@@ -112,7 +112,7 @@ def find_collisions(
|
||||
return collisions
|
||||
|
||||
|
||||
def _lists_hashes(entry: dict) -> bool:
|
||||
def lists_hashes(entry: dict) -> bool:
|
||||
"""Whether a declaration says anything about content at all."""
|
||||
return any(
|
||||
_declared_hashes(entry, field_name)
|
||||
@@ -142,10 +142,10 @@ def _record_at(path: str, db: dict) -> dict | None:
|
||||
path verify --all and slots.py both take. The index is the pack
|
||||
resolver's, so one run holds one copy of it.
|
||||
"""
|
||||
return _records_by_path(db).get(path)
|
||||
return records_by_path(db).get(path)
|
||||
|
||||
|
||||
def _content_sha1(path: str, db: dict) -> str | None:
|
||||
def content_sha1(path: str, db: dict) -> str | None:
|
||||
"""The sha1 of the file at path, from the database or read from disk.
|
||||
|
||||
A data directory cache is not in the database, so its files are hashed.
|
||||
@@ -158,7 +158,7 @@ def _content_sha1(path: str, db: dict) -> str | None:
|
||||
return compute_hashes(path, frozenset({"sha1"}))["sha1"]
|
||||
|
||||
|
||||
def _accepted_by_all(path: str, entries: list[dict], db: dict) -> bool:
|
||||
def accepted_by_all(path: str, entries: list[dict], db: dict) -> bool:
|
||||
"""Whether every declaration's own hashes accept the file at path."""
|
||||
record = _record_at(path, db)
|
||||
if record is None:
|
||||
|
||||
@@ -14,7 +14,7 @@ from resolve.layout import (
|
||||
CONTENT_TAG_PREFIXES,
|
||||
OUTSIDE_BIOS_FOLDER,
|
||||
ROM_SEARCH_PREFIX,
|
||||
_placed_entry,
|
||||
placed_entry,
|
||||
standalone_layout_path,
|
||||
)
|
||||
from model.declarations import ROMS_ROOT, outer_layout
|
||||
@@ -24,7 +24,7 @@ from core.paths import REPO_ROOT
|
||||
LIBRETRO_RUNNERS = frozenset({"libretro", "retroarch", "retroarch32", "retrorun"})
|
||||
|
||||
|
||||
def _core_key(name: str) -> str:
|
||||
def core_key(name: str) -> str:
|
||||
"""A core name as two platforms spell it alike: mame2003-plus, mame2003_plus."""
|
||||
return str(name).lower().replace("-", "_")
|
||||
|
||||
@@ -83,9 +83,9 @@ def offer_boards(config: dict) -> dict[tuple[str, str], frozenset[str] | None]:
|
||||
for row in config.get("_rom_folders") or []:
|
||||
folder = str(row.get("folder") or "")
|
||||
offers = row.get("offers") or []
|
||||
offered = {(o.get("emulator"), _core_key(o.get("core") or "")) for o in offers}
|
||||
offered = {(o.get("emulator"), core_key(o.get("core") or "")) for o in offers}
|
||||
choices: list[tuple[dict, set[str]]] = []
|
||||
if row.get("core") and (row.get("emulator"), _core_key(row["core"])) not in offered:
|
||||
if row.get("core") and (row.get("emulator"), core_key(row["core"])) not in offered:
|
||||
choices.append((row, every))
|
||||
for key, spec in (row.get("board_defaults") or {}).items():
|
||||
branch = str(key).replace("=", " ", 1)
|
||||
@@ -96,7 +96,7 @@ def offer_boards(config: dict) -> dict[tuple[str, str], frozenset[str] | None]:
|
||||
if when else every))
|
||||
for choice, boards in choices:
|
||||
if choice.get("core") and choice.get("emulator") in LIBRETRO_RUNNERS:
|
||||
found.setdefault((_core_key(choice["core"]), folder), set()).update(boards)
|
||||
found.setdefault((core_key(choice["core"]), folder), set()).update(boards)
|
||||
return {
|
||||
pair: None if not names or boards >= every else frozenset(boards)
|
||||
for pair, boards in found.items()
|
||||
@@ -108,10 +108,10 @@ def content_folder_boards(config: dict) -> dict[tuple[str, str], frozenset[str]
|
||||
with the boards it does so on, None for every board."""
|
||||
pairs: set[tuple[str, str]] = set()
|
||||
for core, systems in (config.get("libretro_systems") or {}).items():
|
||||
pairs |= {(_core_key(core), str(s)) for s in systems or []}
|
||||
pairs |= {(core_key(core), str(s)) for s in systems or []}
|
||||
for system in (config.get("systems") or {}).values():
|
||||
if isinstance(system, dict) and system.get("native_id"):
|
||||
pairs |= {(_core_key(c), str(system["native_id"])) for c in system.get("cores") or []}
|
||||
pairs |= {(core_key(c), str(system["native_id"])) for c in system.get("cores") or []}
|
||||
for record in config.get("launchers") or []:
|
||||
if record.get("kind") == "package" and record.get("build") == "libretro":
|
||||
package = str(record.get("emulator", ""))
|
||||
@@ -120,7 +120,7 @@ def content_folder_boards(config: dict) -> dict[tuple[str, str], frozenset[str]
|
||||
# drivers alone, none of the arcade sets of the core it
|
||||
# shares a repository with.
|
||||
continue
|
||||
core = _core_key(package.removeprefix("lr-"))
|
||||
core = core_key(package.removeprefix("lr-"))
|
||||
pairs |= {(core, str(s)) for s in record.get("systems") or []}
|
||||
# Pairs from the platform's own lists hold on every board, an offer on
|
||||
# the boards its frontend writes it for.
|
||||
@@ -156,10 +156,10 @@ def content_folder_tags(config: dict) -> set[str]:
|
||||
boards = content_folder_boards(config)
|
||||
target = config.get(TARGET_KEY)
|
||||
pairs = {pair for pair, on in boards.items() if not target or on is None or target in on}
|
||||
from resolve.launchers import _roms_place
|
||||
from resolve.launchers import roms_place_of
|
||||
|
||||
def place(folder: str) -> list:
|
||||
return list(_roms_place(config, folder) or ())
|
||||
return list(roms_place_of(config, folder) or ())
|
||||
|
||||
# Without a board, a core a folder offers on some boards only carries
|
||||
# them, for a manifest the installer narrows to one.
|
||||
@@ -272,7 +272,7 @@ def _roms_entry(entry: dict, tree: str, folder: str, rel: str) -> dict:
|
||||
"""The entry placed in a roms folder."""
|
||||
# Below the roms root inside the install tree (EmuELEC's
|
||||
# /storage/roms): a plain dest the platform prefix skips, as a
|
||||
# standalone entry placed there (_placed_entry).
|
||||
# standalone entry placed there (placed_entry).
|
||||
where: dict[str, object] = (
|
||||
{"unprefixed": True} if tree == "install" else {"root": ROMS_ROOT}
|
||||
)
|
||||
@@ -361,7 +361,7 @@ def _standalone_content_layout(emu_name: str, view: dict, searches: list) -> dic
|
||||
out.append(f)
|
||||
held = {(f.get("root") or "", f.get("standalone_path") or "")}
|
||||
extra = [
|
||||
_placed_entry(f, view, (tree, f"{folder}/{layout}")) for tree, folder in reads
|
||||
placed_entry(f, view, (tree, f"{folder}/{layout}")) for tree, folder in reads
|
||||
]
|
||||
extra = [e for e in extra if (e.get("root") or "", e["standalone_path"]) not in held]
|
||||
changed |= bool(extra)
|
||||
@@ -373,7 +373,7 @@ def _standalone_content_layout(emu_name: str, view: dict, searches: list) -> dic
|
||||
changed = True
|
||||
placed = {k: v for k, v in f.items() if k != "unplaced"}
|
||||
out.extend(
|
||||
_placed_entry(placed, view, (tree, f"{folder}/{layout}")) for tree, folder in reads
|
||||
placed_entry(placed, view, (tree, f"{folder}/{layout}")) for tree, folder in reads
|
||||
)
|
||||
return {**view, "files": out} if changed else view
|
||||
|
||||
@@ -403,13 +403,13 @@ def content_layout(
|
||||
return {**view, "files": files}
|
||||
if CONTENT_SCOPE_TAG not in tags:
|
||||
return view
|
||||
names = {_core_key(n) for n in {emu_name, *(str(c) for c in view.get("cores") or [])}}
|
||||
names = {core_key(n) for n in {emu_name, *(str(c) for c in view.get("cores") or [])}}
|
||||
searches = [
|
||||
json.loads(t[len(ROM_SEARCH_PREFIX):])
|
||||
for t in tags if t.startswith(ROM_SEARCH_PREFIX)
|
||||
]
|
||||
build = "standalone" if standalone else "libretro"
|
||||
searches = [s for s in searches if _core_key(s[0]) in names and s[6] == build]
|
||||
searches = [s for s in searches if core_key(s[0]) in names and s[6] == build]
|
||||
if not standalone:
|
||||
return _libretro_content_layout(emu_name, view, tags, names, searches)
|
||||
return _standalone_content_layout(emu_name, view, searches)
|
||||
|
||||
@@ -10,7 +10,7 @@ from core.cli import suggest_names
|
||||
from core.paths import sanitize_pack_path
|
||||
from model.platforms import load_platform_config
|
||||
from model.profiles import preferred_profile, upstream_profile_index
|
||||
from model.systems import _norm_system_id, select_systems
|
||||
from model.systems import norm_system_id, select_systems
|
||||
from model.targets import list_available_targets, load_target_config
|
||||
from core.paths import REPO_ROOT
|
||||
|
||||
@@ -212,11 +212,11 @@ def _platform_profiles(
|
||||
result |= every_libretro()
|
||||
else:
|
||||
# Fallback: system ID intersection with normalization
|
||||
norm_plat_systems = {_norm_system_id(s) for s in config.get("systems", {})}
|
||||
norm_plat_systems = {norm_system_id(s) for s in config.get("systems", {})}
|
||||
result = {
|
||||
name
|
||||
for name, p in profiles.items()
|
||||
if {_norm_system_id(s) for s in p.get("systems", [])} & norm_plat_systems
|
||||
if {norm_system_id(s) for s in p.get("systems", [])} & norm_plat_systems
|
||||
and p.get("type") != "alias"
|
||||
and not p.get("built_by")
|
||||
}
|
||||
@@ -311,7 +311,7 @@ def system_core_reach(
|
||||
None, kept whatever is available, there being no information to exclude
|
||||
it.
|
||||
"""
|
||||
_norm_sid = _norm_system_id
|
||||
_norm_sid = norm_system_id
|
||||
|
||||
# Normalized system -> cores, from ALL profiles
|
||||
norm_system_cores: dict[str, set[str]] = {}
|
||||
|
||||
@@ -9,7 +9,7 @@ from collections.abc import Callable
|
||||
from resolve.content import adler32_fits, content_fits, name_match_size_ok
|
||||
|
||||
|
||||
def _resolve_in_data_dirs(
|
||||
def resolve_in_data_dirs(
|
||||
names_to_try: list[str],
|
||||
data_dir_registry: dict,
|
||||
verdict: Callable[[str], str],
|
||||
@@ -54,7 +54,7 @@ def _resolve_in_data_dirs(
|
||||
return None, mismatch
|
||||
|
||||
|
||||
def _data_dir_tail(
|
||||
def data_dir_tail(
|
||||
dest_hint: str, data_dir_registry: dict, file_entry: dict, db: dict
|
||||
) -> str | None:
|
||||
"""The cached data-directory file at the destination's own tail.
|
||||
|
||||
@@ -205,7 +205,7 @@ def _bios_relative(directory: str, base: str) -> str | None:
|
||||
return None if re.search(r"[\s<>]", relative) else relative
|
||||
|
||||
|
||||
def _directories(record: dict, base: str) -> list[str] | None:
|
||||
def record_directories(record: dict, base: str) -> list[str] | None:
|
||||
"""The directories a record reads, in order. None when the code says none.
|
||||
|
||||
``search_dir`` transcribes the code, conditions included: "bios/chihiro,
|
||||
@@ -230,7 +230,7 @@ def _directories(record: dict, base: str) -> list[str] | None:
|
||||
return found
|
||||
|
||||
|
||||
def _names(record: dict) -> list[str]:
|
||||
def record_names(record: dict) -> list[str]:
|
||||
"""The file names a record tries, placeholders expanded in code order."""
|
||||
expands = record.get("expands") or {}
|
||||
names: list[str] = []
|
||||
@@ -591,8 +591,8 @@ def launcher_places(
|
||||
kind = record.get("kind")
|
||||
if kind not in PLACE_KINDS:
|
||||
continue
|
||||
names = _names(record)
|
||||
directories = _directories(record, base)
|
||||
names = record_names(record)
|
||||
directories = record_directories(record, base)
|
||||
if not names or directories == []:
|
||||
continue
|
||||
anchored = directories is not None
|
||||
@@ -869,7 +869,7 @@ def handed_directories(
|
||||
handles=handles,
|
||||
source_ref=str(record.get("source_ref", "")),
|
||||
roms_place=None if folder is not None else (
|
||||
_roms_place(config, folder_in_roms(part, config))
|
||||
roms_place_of(config, folder_in_roms(part, config))
|
||||
or _configs_place(folder_in_configs(part, config))
|
||||
or _emulators_place(folder_in_emulators(part, config))
|
||||
),
|
||||
@@ -893,7 +893,7 @@ def _emulators_place(path: str | None) -> Place | None:
|
||||
return None if path is None else (EMULATORS_TREE, path)
|
||||
|
||||
|
||||
def _roms_place(config: dict, path: str | None) -> Place | None:
|
||||
def roms_place_of(config: dict, path: str | None) -> Place | None:
|
||||
"""A path below the roms root as a place: in the install tree when the
|
||||
platform installs above its BIOS folder (AmberELEC), else the roms tree."""
|
||||
if path is None:
|
||||
@@ -984,7 +984,7 @@ def executed_files(config: dict) -> list[ExecutedFile]:
|
||||
if str(record.get("passes_to") or "").strip() != "exec":
|
||||
continue
|
||||
raw = str(record.get("search_dir") or "").strip()
|
||||
directories = _directories(record, base)
|
||||
directories = record_directories(record, base)
|
||||
roms = folder_in_roms(raw, config) if raw and not directories else None
|
||||
emulator_folder = folder_in_emulators(raw, config) if raw and not directories else None
|
||||
# A program file needs no extension (pico8, vox): the names are
|
||||
@@ -997,7 +997,7 @@ def executed_files(config: dict) -> list[ExecutedFile]:
|
||||
f"{directories[0]}/{name}" if directories[0] else name
|
||||
))
|
||||
elif roms is not None:
|
||||
place = _roms_place(config, sanitize_pack_path(f"{roms}/{name}" if roms else name))
|
||||
place = roms_place_of(config, sanitize_pack_path(f"{roms}/{name}" if roms else name))
|
||||
elif emulator_folder is not None:
|
||||
place = (EMULATORS_TREE, sanitize_pack_path(f"{emulator_folder}/{name}"))
|
||||
else:
|
||||
|
||||
@@ -127,7 +127,7 @@ def system_dir_path(entry: dict, path: str) -> str:
|
||||
return f"{directory}/{path}" if directory else path
|
||||
|
||||
|
||||
def _handed(standalone_cores: Iterable[str]) -> list:
|
||||
def handed_from_tags(standalone_cores: Iterable[str]) -> list:
|
||||
"""The directories a standalone set carries, as launchers built them."""
|
||||
from resolve.launchers import HandedDirectory
|
||||
|
||||
@@ -245,12 +245,12 @@ def standalone_bindings_for(
|
||||
if isinstance(f, dict) and (path := standalone_layout_path(f, profile))
|
||||
]
|
||||
return standalone_bindings(
|
||||
names, declared, _handed(standalone_cores), _executed(standalone_cores), layout,
|
||||
names, declared, handed_from_tags(standalone_cores), _executed(standalone_cores), layout,
|
||||
pools, systems,
|
||||
)
|
||||
|
||||
|
||||
def _placed_entry(entry: dict, profile: dict, placed: tuple[str, str]) -> dict:
|
||||
def placed_entry(entry: dict, profile: dict, placed: tuple[str, str]) -> dict:
|
||||
"""A standalone entry moved to the (tree, path) a platform reads it from."""
|
||||
tree, path = placed
|
||||
moved = {**entry, "standalone_path": path,
|
||||
|
||||
@@ -15,9 +15,9 @@ from core.ziptools import check_inside_zip
|
||||
from model.database import get_mame_clone_map
|
||||
from model.profiles import CONTENT_CHECKS
|
||||
from resolve.archives import (
|
||||
_covering_archives,
|
||||
_holding_members,
|
||||
_warn_unreadable_archive,
|
||||
covering_archives,
|
||||
holding_members,
|
||||
warn_unreadable_archive,
|
||||
contents_members,
|
||||
)
|
||||
from resolve.content import (
|
||||
@@ -28,14 +28,14 @@ from resolve.content import (
|
||||
name_match_size_ok,
|
||||
shape_fits,
|
||||
)
|
||||
from resolve.datadirs import _data_dir_tail, _resolve_in_data_dirs
|
||||
from resolve.datadirs import data_dir_tail, resolve_in_data_dirs
|
||||
from resolve.ownership import (
|
||||
_affinity_tokens,
|
||||
_engine_tree,
|
||||
_foreign_tree,
|
||||
_maker_folder,
|
||||
_own_tree,
|
||||
_owner_tokens,
|
||||
affinity_tokens,
|
||||
engine_tree,
|
||||
foreign_tree,
|
||||
maker_folder,
|
||||
own_tree,
|
||||
owner_tokens,
|
||||
other_maker,
|
||||
system_makers,
|
||||
)
|
||||
@@ -145,7 +145,7 @@ def _rank_tail_candidates(
|
||||
candidates = [
|
||||
h for h in candidates
|
||||
if not path_of(h).endswith("/" + tail)
|
||||
or not _foreign_tree(path_of(h), owners if start else set(asker))
|
||||
or not foreign_tree(path_of(h), owners if start else set(asker))
|
||||
]
|
||||
if len(candidates) < 2:
|
||||
return candidates
|
||||
@@ -154,8 +154,8 @@ def _rank_tail_candidates(
|
||||
candidates,
|
||||
key=lambda h: (
|
||||
len(path_of(h).split("/")) - depth,
|
||||
not owners & _affinity_tokens(path_of(h).rsplit("/", 1)[0]),
|
||||
_foreign_tree(path_of(h), owners),
|
||||
not owners & affinity_tokens(path_of(h).rsplit("/", 1)[0]),
|
||||
foreign_tree(path_of(h), owners),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -174,15 +174,15 @@ def _by_affinity(paths: list[str], file_entry: dict, dest_hint: str) -> list[str
|
||||
if len(paths) < 2:
|
||||
return paths
|
||||
hint = dest_hint or file_entry.get("path") or file_entry.get("destination") or ""
|
||||
wanted = _affinity_tokens(hint.rsplit("/", 1)[0] if "/" in hint else "")
|
||||
owners = _owner_tokens(file_entry)
|
||||
wanted = affinity_tokens(hint.rsplit("/", 1)[0] if "/" in hint else "")
|
||||
owners = owner_tokens(file_entry)
|
||||
sized = declares_shape(file_entry)
|
||||
|
||||
def score(path: str) -> tuple[int, bool, bool, bool, int]:
|
||||
fits = 0
|
||||
if sized and os.path.exists(path):
|
||||
fits = int(shape_fits(file_entry, path))
|
||||
tokens = _affinity_tokens(path.rsplit("/", 1)[0])
|
||||
tokens = affinity_tokens(path.rsplit("/", 1)[0])
|
||||
# The owner's own copy ranks above any shared tree segment: NetherSX2's
|
||||
# shaders/common/ beat armsx2's own fxaa.fx on two directory tokens.
|
||||
# Another emulator's own tree ranks below everything else.
|
||||
@@ -191,8 +191,8 @@ def _by_affinity(paths: list[str], file_entry: dict, dest_hint: str) -> list[str
|
||||
# flycast-dojo, lindbergh-loader and vvvvvv took C-Dogs' 98-line
|
||||
# gamecontrollerdb.txt by index order.
|
||||
return (
|
||||
fits, bool(owners & tokens), not _foreign_tree(path, owners | wanted),
|
||||
not _engine_tree(path, owners | wanted), len(wanted & tokens),
|
||||
fits, bool(owners & tokens), not foreign_tree(path, owners | wanted),
|
||||
not engine_tree(path, owners | wanted), len(wanted & tokens),
|
||||
)
|
||||
|
||||
return sorted(paths, key=score, reverse=True)
|
||||
@@ -424,7 +424,7 @@ def _tail_candidates(q: _Lookup, start: int, tail: str, owners: set[str]) -> lis
|
||||
"""The records a destination tail names, ranked, ambiguity read."""
|
||||
candidates = _rank_tail_candidates(
|
||||
q.by_path_suffix.get(tail, []), start, tail, q.files_db, owners,
|
||||
frozenset(_owner_tokens(q.file_entry)),
|
||||
frozenset(owner_tokens(q.file_entry)),
|
||||
)
|
||||
raw = q.by_path_suffix.get(tail, [])
|
||||
if start and len(raw) > 1:
|
||||
@@ -436,7 +436,7 @@ def _tail_candidates(q: _Lookup, start: int, tail: str, owners: set[str]) -> lis
|
||||
# tree still answers a tail several files share.
|
||||
candidates = [
|
||||
h for h in candidates
|
||||
if _own_tree(q.files_db.get(h, {}).get("path", ""), owners)
|
||||
if own_tree(q.files_db.get(h, {}).get("path", ""), owners)
|
||||
]
|
||||
return candidates
|
||||
|
||||
@@ -490,7 +490,7 @@ def _by_path_suffix(q: _Lookup) -> tuple[Resolution | None, bool]:
|
||||
hint_parts = q.dest_hint.split("/")
|
||||
# The asking profile and the destination's own directories both name
|
||||
# whose tree a copy may come from.
|
||||
owners = _owner_tokens(q.file_entry) | _affinity_tokens("/".join(hint_parts[:-1]))
|
||||
owners = owner_tokens(q.file_entry) | affinity_tokens("/".join(hint_parts[:-1]))
|
||||
for start in range(min(2, len(hint_parts) - 1)):
|
||||
candidates = _tail_candidates(q, start, "/".join(hint_parts[start:]), owners)
|
||||
if start and len(candidates) > 1:
|
||||
@@ -526,9 +526,9 @@ def _by_data_dir_tail(q: _Lookup, data_dir_registry: dict | None) -> Resolution
|
||||
tail_hint
|
||||
and data_dir_registry
|
||||
and not q.has_strong_hash
|
||||
and not _owner_tokens(q.file_entry)
|
||||
and not owner_tokens(q.file_entry)
|
||||
):
|
||||
hit = _data_dir_tail(tail_hint, data_dir_registry, q.file_entry, q.db)
|
||||
hit = data_dir_tail(tail_hint, data_dir_registry, q.file_entry, q.db)
|
||||
if hit:
|
||||
return hit, "path_exact"
|
||||
return None
|
||||
@@ -609,7 +609,7 @@ def _add_casefold_candidates(q: _Lookup, candidates: list[str], owners: set[str]
|
||||
for match_sha1 in folded.get(try_name.casefold(), []):
|
||||
if match_sha1 in q.files_db and _name_size_ok(q, match_sha1):
|
||||
path = q.files_db[match_sha1]["path"]
|
||||
if _foreign_tree(path, owners):
|
||||
if foreign_tree(path, owners):
|
||||
continue
|
||||
if os.path.exists(path) and path not in candidates:
|
||||
candidates.append(path)
|
||||
@@ -630,7 +630,7 @@ def _same_maker(q: _Lookup, candidates: list[str], makers: frozenset[str]) -> li
|
||||
for match_sha1 in shadowed.get(try_name, []):
|
||||
path = q.files_db.get(match_sha1, {}).get("path", "")
|
||||
if (
|
||||
_maker_folder(path, str(q.db.get("bios_dir") or "bios"))
|
||||
maker_folder(path, str(q.db.get("bios_dir") or "bios"))
|
||||
in makers
|
||||
and _name_size_ok(q, match_sha1)
|
||||
and os.path.exists(path)
|
||||
@@ -656,19 +656,19 @@ def _choose_by_name(
|
||||
# Demul's naomi.zip holds more NAOMI BIOS rows than any MAME
|
||||
# set and broke the superset the MAME cores were served.
|
||||
candidates = [
|
||||
p for p in candidates if not _foreign_tree(p, owners)
|
||||
p for p in candidates if not foreign_tree(p, owners)
|
||||
] or candidates
|
||||
if members:
|
||||
candidates = _holding_members(candidates, members)
|
||||
candidates = holding_members(candidates, members)
|
||||
elif len(candidates) > 1 and q.name.casefold().endswith(".zip"):
|
||||
candidates = _covering_archives(candidates)
|
||||
candidates = covering_archives(candidates)
|
||||
candidates = _by_affinity(candidates, q.file_entry, q.dest_hint)
|
||||
best = candidates[0] if candidates else ""
|
||||
# A copy outside another emulator's tree comes first: the
|
||||
# affinity read pcsx2 in bios/Other/armsx2/pcsx2/ and served
|
||||
# upstream PCSX2 the patches.zip of ARMSX2.
|
||||
candidates = [
|
||||
p for p in candidates if not _foreign_tree(p, owners)
|
||||
p for p in candidates if not foreign_tree(p, owners)
|
||||
] or candidates
|
||||
primary = [p for p in candidates if "/.variants/" not in p]
|
||||
if not (primary or candidates):
|
||||
@@ -682,8 +682,8 @@ def _choose_by_name(
|
||||
# 8 KB copy was set aside, while data/bluemsx held its own,
|
||||
# and MSX2P.ROM of another dump once only msx-emu answered
|
||||
# the exact casing.
|
||||
if data_dir_registry and (exact_foreign or _foreign_tree(best, owners)):
|
||||
hit, _mismatch = _resolve_in_data_dirs(
|
||||
if data_dir_registry and (exact_foreign or foreign_tree(best, owners)):
|
||||
hit, _mismatch = resolve_in_data_dirs(
|
||||
q.names_to_try, data_dir_registry,
|
||||
functools.partial(
|
||||
declared_hash_verdict,
|
||||
@@ -714,11 +714,11 @@ def _by_name(
|
||||
candidates = _exact_name_candidates(q)
|
||||
if candidates and all("/.variants/" in p for p in candidates):
|
||||
_add_variant_primaries(q, candidates)
|
||||
owners = _owner_tokens(q.file_entry)
|
||||
owners = owner_tokens(q.file_entry)
|
||||
# Only another emulator's tree answers the exact casing: what it
|
||||
# holds there says nothing about this entry's file.
|
||||
exact_foreign = bool(candidates) and all(
|
||||
_foreign_tree(p, owners) for p in candidates
|
||||
foreign_tree(p, owners) for p in candidates
|
||||
)
|
||||
if not candidates or exact_foreign:
|
||||
_add_casefold_candidates(q, candidates, owners)
|
||||
@@ -730,13 +730,13 @@ def _by_name(
|
||||
core_owners = {
|
||||
token
|
||||
for core in q.file_entry.get("platform_cores") or ()
|
||||
for token in _affinity_tokens(str(core))
|
||||
for token in affinity_tokens(str(core))
|
||||
}
|
||||
if (
|
||||
not owners
|
||||
and core_owners
|
||||
and candidates
|
||||
and all(_foreign_tree(p, core_owners) for p in candidates)
|
||||
and all(foreign_tree(p, core_owners) for p in candidates)
|
||||
):
|
||||
return None, True
|
||||
if makers and candidates:
|
||||
@@ -803,7 +803,7 @@ def _named_md5_match(q: _Lookup, named: list[tuple[str, str, int | None]]) -> Re
|
||||
):
|
||||
return path, "md5_composite_exact"
|
||||
except (zipfile.BadZipFile, OSError) as exc:
|
||||
_warn_unreadable_archive(path, exc)
|
||||
warn_unreadable_archive(path, exc)
|
||||
if db_md5.lower() in md5_set and not q.composite_only:
|
||||
return path, "md5_exact"
|
||||
return None
|
||||
@@ -821,7 +821,7 @@ def _zipped_named(
|
||||
if zipped_file.casefold() in inner_names:
|
||||
valid.append((path, m, size))
|
||||
except (zipfile.BadZipFile, OSError) as exc:
|
||||
_warn_unreadable_archive(path, exc)
|
||||
warn_unreadable_archive(path, exc)
|
||||
# The archive whose member carries the declared md5 is the one:
|
||||
# neogeo.zip is held twice, each with its own sfix.sfix, and the
|
||||
# first by name was returned as a mismatch while the other matched.
|
||||
@@ -909,7 +909,7 @@ def _in_data_dirs(q: _Lookup, data_dir_registry: dict) -> tuple[Resolution | Non
|
||||
file_entry=q.file_entry,
|
||||
db=q.db,
|
||||
)
|
||||
return _resolve_in_data_dirs(q.names_to_try, data_dir_registry, verdict)
|
||||
return resolve_in_data_dirs(q.names_to_try, data_dir_registry, verdict)
|
||||
|
||||
|
||||
def _resolve_layout(
|
||||
|
||||
@@ -16,7 +16,7 @@ def names_manufacturer(sys_id: str, manufacturer: str) -> bool:
|
||||
return sys_id == slug or sys_id.startswith(f"{slug}-")
|
||||
|
||||
|
||||
def _maker_folder(path: str, bios_dir: str) -> str | None:
|
||||
def maker_folder(path: str, bios_dir: str) -> str | None:
|
||||
"""The bios/<maker>/ folder a collection path is filed under."""
|
||||
prefix = f"{bios_dir.rstrip('/')}/"
|
||||
if not path.startswith(prefix):
|
||||
@@ -40,7 +40,7 @@ def _maker_folders(db: dict) -> frozenset[str]:
|
||||
folders = frozenset(
|
||||
folder
|
||||
for entry in files_db.values()
|
||||
if (folder := _maker_folder(str(entry.get("path", "")), bios_dir))
|
||||
if (folder := maker_folder(str(entry.get("path", "")), bios_dir))
|
||||
and folder not in BUCKET_FOLDERS
|
||||
)
|
||||
_maker_folders_cache[:] = [(files_db, len(files_db), folders)]
|
||||
@@ -55,7 +55,7 @@ def system_makers(file_entry: dict, db: dict) -> frozenset[str]:
|
||||
(pc88, arcade), so nothing is narrowed there.
|
||||
"""
|
||||
sys_id = str(file_entry.get("platform_system") or "")
|
||||
if not sys_id or _owner_tokens(file_entry):
|
||||
if not sys_id or owner_tokens(file_entry):
|
||||
return frozenset()
|
||||
return frozenset(
|
||||
folder for folder in _maker_folders(db) if names_manufacturer(sys_id, folder)
|
||||
@@ -66,11 +66,11 @@ def other_maker(path: str, makers: frozenset[str], db: dict) -> bool:
|
||||
"""Whether a path is filed under a maker the entry's system does not name."""
|
||||
if not makers:
|
||||
return False
|
||||
folder = _maker_folder(path, str(db.get("bios_dir") or "bios"))
|
||||
folder = maker_folder(path, str(db.get("bios_dir") or "bios"))
|
||||
return folder is not None and folder not in BUCKET_FOLDERS and folder not in makers
|
||||
|
||||
|
||||
def _affinity_tokens(text: str) -> set[str]:
|
||||
def affinity_tokens(text: str) -> set[str]:
|
||||
return {
|
||||
token
|
||||
for token in (re.sub(r"[^0-9a-z]", "", part.casefold()) for part in text.split("/"))
|
||||
@@ -78,7 +78,7 @@ def _affinity_tokens(text: str) -> set[str]:
|
||||
}
|
||||
|
||||
|
||||
def _owner_tokens(file_entry: dict) -> set[str]:
|
||||
def owner_tokens(file_entry: dict) -> set[str]:
|
||||
"""Tokens naming the profile that asks for the file.
|
||||
|
||||
A profile named after another with a suffix (cxbx-reloaded-2023,
|
||||
@@ -90,14 +90,14 @@ def _owner_tokens(file_entry: dict) -> set[str]:
|
||||
tokens: set[str] = set()
|
||||
for owner in (file_entry.get("source_profile"), file_entry.get("source_emulator")):
|
||||
if owner:
|
||||
tokens |= _affinity_tokens(str(owner).replace(" ", ""))
|
||||
tokens |= affinity_tokens(str(owner).replace(" ", ""))
|
||||
profile = str(file_entry.get("source_profile") or "").casefold()
|
||||
words = [word for word in re.split(r"[^0-9a-z]+", profile) if word]
|
||||
tokens |= {"".join(words[:end]) for end in range(1, len(words))}
|
||||
return tokens
|
||||
|
||||
|
||||
def _foreign_tree(path: str, owners: set[str]) -> bool:
|
||||
def foreign_tree(path: str, owners: set[str]) -> bool:
|
||||
"""Whether a path lives in the tree of an emulator that is not the asker.
|
||||
|
||||
bios/Other/<emulator>/ holds what one emulator ships. A same-named file
|
||||
@@ -108,20 +108,20 @@ def _foreign_tree(path: str, owners: set[str]) -> bool:
|
||||
parts = path.split("/")
|
||||
if not owners or len(parts) < 4 or parts[0] != "bios" or parts[1] != "Other":
|
||||
return False
|
||||
return not (owners & _affinity_tokens(parts[2]))
|
||||
return not (owners & affinity_tokens(parts[2]))
|
||||
|
||||
|
||||
def _engine_tree(path: str, owners: set[str]) -> bool:
|
||||
def engine_tree(path: str, owners: set[str]) -> bool:
|
||||
"""Whether a path lives in another game's folder under bios/Game Engines/."""
|
||||
parts = path.split("/")
|
||||
if len(parts) < 4 or parts[0] != "bios" or parts[1] != "Game Engines":
|
||||
return False
|
||||
return not (owners & _affinity_tokens(parts[2]))
|
||||
return not (owners & affinity_tokens(parts[2]))
|
||||
|
||||
|
||||
def _own_tree(path: str, owners: set[str]) -> bool:
|
||||
def own_tree(path: str, owners: set[str]) -> bool:
|
||||
"""Whether a path lives in the bios/Other/<emulator>/ tree of the asker."""
|
||||
parts = path.split("/")
|
||||
if not owners or len(parts) < 4 or parts[0] != "bios" or parts[1] != "Other":
|
||||
return False
|
||||
return bool(owners & _affinity_tokens(parts[2]))
|
||||
return bool(owners & affinity_tokens(parts[2]))
|
||||
@@ -21,13 +21,13 @@ from core.paths import REPO_ROOT, declared_destination
|
||||
from resolve.validation import inner_rom_check
|
||||
# CLI-wide network policy. Public helpers can override it explicitly, while
|
||||
# every CLI mode inherits --offline (including large-file release fallback).
|
||||
_OFFLINE = False
|
||||
OFFLINE = False
|
||||
|
||||
|
||||
def set_offline(value: bool) -> None:
|
||||
"""Forbid every network reach for the rest of the run."""
|
||||
global _OFFLINE
|
||||
_OFFLINE = value
|
||||
global OFFLINE
|
||||
OFFLINE = value
|
||||
|
||||
|
||||
def scratch_dir() -> str:
|
||||
@@ -61,7 +61,7 @@ def download_external(
|
||||
if declared is None:
|
||||
print(f" WARNING: no hash for {name}, skipping unverifiable download")
|
||||
return False
|
||||
if _OFFLINE if offline is None else offline:
|
||||
if OFFLINE if offline is None else offline:
|
||||
print(f" WARNING: {name} is external and the run is offline, not fetched")
|
||||
return False
|
||||
algo, expected = declared
|
||||
@@ -140,7 +140,7 @@ def _verified_asset(
|
||||
def run_is_offline(offline: bool | None = None) -> bool:
|
||||
"""Whether this run fetches nothing: --offline, or RETROBIOS_OFFLINE."""
|
||||
return bool(
|
||||
(_OFFLINE if offline is None else offline)
|
||||
(OFFLINE if offline is None else offline)
|
||||
or os.environ.get("RETROBIOS_OFFLINE")
|
||||
)
|
||||
|
||||
@@ -148,7 +148,7 @@ def run_is_offline(offline: bool | None = None) -> bool:
|
||||
_RECORDS_BY_PATH: list[tuple[dict, int, dict[str, dict]]] = []
|
||||
|
||||
|
||||
def _records_by_path(db: dict) -> dict[str, dict]:
|
||||
def records_by_path(db: dict) -> dict[str, dict]:
|
||||
"""The database records by path, built once per database."""
|
||||
files = db.get("files", {})
|
||||
if _RECORDS_BY_PATH:
|
||||
@@ -185,7 +185,7 @@ def pending_release_asset(
|
||||
assets = set(asset_candidates(name, registered))
|
||||
if not assets:
|
||||
return None
|
||||
records = _records_by_path(db)
|
||||
records = records_by_path(db)
|
||||
declared_size = file_entry.get("size")
|
||||
for path, asset in sorted(asset_names(registered).items()):
|
||||
record = records.get(path)
|
||||
@@ -396,7 +396,7 @@ def resolve_file(
|
||||
# exactly what the flag forbids.
|
||||
return (path, status) if path else (None, "not_found")
|
||||
cached = _verified_asset(
|
||||
name, declared, file_entry, _OFFLINE if offline is None else offline,
|
||||
name, declared, file_entry, OFFLINE if offline is None else offline,
|
||||
)
|
||||
if cached:
|
||||
return cached, "release_asset"
|
||||
|
||||
@@ -17,13 +17,13 @@ from collections.abc import Callable
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
|
||||
from model.systems import _norm_system_id
|
||||
from model.systems import norm_system_id
|
||||
from core.paths import REPO_ROOT
|
||||
|
||||
HASH_FIELDS = ("sha1", "md5", "sha256", "crc32")
|
||||
|
||||
|
||||
def _hash_values(entry: dict, field_name: str) -> list[str]:
|
||||
def hash_values(entry: dict, field_name: str) -> list[str]:
|
||||
"""Return a hash field as a list, whatever shape it was written in."""
|
||||
raw = entry.get(field_name)
|
||||
if not raw:
|
||||
@@ -62,8 +62,8 @@ def checked_hashes(entry: dict | None) -> dict | None:
|
||||
kinds = {str(k) for k in raw}
|
||||
else:
|
||||
kinds = {str(raw)}
|
||||
checked = [f for f in HASH_FIELDS if f in kinds and _hash_values(entry, f)]
|
||||
if checked and all(len(set(_hash_values(entry, f))) == 1 for f in checked):
|
||||
checked = [f for f in HASH_FIELDS if f in kinds and hash_values(entry, f)]
|
||||
if checked and all(len(set(hash_values(entry, f))) == 1 for f in checked):
|
||||
return entry
|
||||
return {k: v for k, v in entry.items() if k not in HASH_FIELDS or k in kinds}
|
||||
|
||||
@@ -96,8 +96,8 @@ def contradicted_hashes(truth_entry: dict, platform_entry: dict | None) -> list[
|
||||
theirs = comparable(platform_entry)
|
||||
return [
|
||||
field_name for field_name in HASH_FIELDS
|
||||
if (ours := set(_hash_values(checked, field_name)))
|
||||
and (held := set(_hash_values(theirs, field_name)))
|
||||
if (ours := set(hash_values(checked, field_name)))
|
||||
and (held := set(hash_values(theirs, field_name)))
|
||||
and not ours & held
|
||||
]
|
||||
|
||||
@@ -111,15 +111,15 @@ def is_label(entry: dict) -> bool:
|
||||
return bool(entry.get("_cores")) and "_named_by" in entry and not entry["_named_by"]
|
||||
|
||||
|
||||
def _is_placeholder(name: str) -> bool:
|
||||
def is_placeholder(name: str) -> bool:
|
||||
return "<" in name or ">" in name or "*" in name
|
||||
|
||||
|
||||
def _field_sets(entry: dict | None) -> dict[str, set[str]]:
|
||||
return {f: set(_hash_values(entry or {}, f)) for f in HASH_FIELDS}
|
||||
return {f: set(hash_values(entry or {}, f)) for f in HASH_FIELDS}
|
||||
|
||||
|
||||
def _single_size(value: int | str | list[int | str]) -> int | None:
|
||||
def single_size(value: int | str | list[int | str]) -> int | None:
|
||||
"""One size, or None: a list names several accepted revisions, which a
|
||||
single size field cannot state (int() on it stopped the whole export)."""
|
||||
if isinstance(value, list):
|
||||
@@ -206,9 +206,9 @@ class NativeFile:
|
||||
rejects a file will reject it whatever the platform declares.
|
||||
"""
|
||||
if field_name == "md5" and self.composite_md5:
|
||||
return _hash_values(self.platform or {}, field_name)
|
||||
truth_values = _hash_values(self._checked_truth, field_name)
|
||||
platform_values = _hash_values(self.platform or {}, field_name)
|
||||
return hash_values(self.platform or {}, field_name)
|
||||
truth_values = hash_values(self._checked_truth, field_name)
|
||||
platform_values = hash_values(self.platform or {}, field_name)
|
||||
source = self._identity_source()
|
||||
if source == "platform":
|
||||
return platform_values
|
||||
@@ -242,11 +242,11 @@ class NativeFile:
|
||||
is written when it names one value, which is then that dump's.
|
||||
"""
|
||||
if field_name == "md5" and self.composite_md5:
|
||||
values = _hash_values(self.platform or {}, field_name)
|
||||
values = hash_values(self.platform or {}, field_name)
|
||||
return values[0] if values else ""
|
||||
source = self._identity_source()
|
||||
truth_values = _hash_values(self._checked_truth, field_name)
|
||||
platform_values = _hash_values(self.platform or {}, field_name)
|
||||
truth_values = hash_values(self._checked_truth, field_name)
|
||||
platform_values = hash_values(self.platform or {}, field_name)
|
||||
if source == "truth":
|
||||
return truth_values[0] if truth_values else ""
|
||||
if source == "platform" or not truth_values:
|
||||
@@ -305,7 +305,7 @@ class NativeFile:
|
||||
for entry in order:
|
||||
if not entry or not entry.get("size"):
|
||||
continue
|
||||
single = _single_size(entry["size"])
|
||||
single = single_size(entry["size"])
|
||||
if single is None:
|
||||
if accepted is None:
|
||||
accepted = {int(v) for v in entry["size"]}
|
||||
@@ -425,19 +425,19 @@ def by_name(truth_entry: dict, platform_entry: dict) -> bool:
|
||||
|
||||
def by_hash(truth_entry: dict, platform_entry: dict) -> bool:
|
||||
"""A value on any of the four hash fields in common: a renamed file."""
|
||||
ours = {v for f in HASH_FIELDS for v in _hash_values(truth_entry, f)}
|
||||
ours = {v for f in HASH_FIELDS for v in hash_values(truth_entry, f)}
|
||||
if not ours:
|
||||
return False
|
||||
theirs = comparable(platform_entry)
|
||||
return bool(ours & {v for f in HASH_FIELDS for v in _hash_values(theirs, f)})
|
||||
return bool(ours & {v for f in HASH_FIELDS for v in hash_values(theirs, f)})
|
||||
|
||||
|
||||
def _contradicts(truth_entry: dict, platform_entry: dict) -> bool:
|
||||
"""A hash both entries declare, without a value in common."""
|
||||
platform_entry = comparable(platform_entry)
|
||||
return any(
|
||||
(ours := set(_hash_values(truth_entry, f)))
|
||||
and (theirs := set(_hash_values(platform_entry, f)))
|
||||
(ours := set(hash_values(truth_entry, f)))
|
||||
and (theirs := set(hash_values(platform_entry, f)))
|
||||
and not ours & theirs
|
||||
for f in HASH_FIELDS
|
||||
)
|
||||
@@ -541,7 +541,7 @@ def _correct_matched(matched: NativeFile, truth_entry: dict, report: Report) ->
|
||||
report.hashes_corrected.append(
|
||||
f"{matched.native_system}/{matched.name} {field_name}"
|
||||
)
|
||||
elif _hash_values(checked, field_name) and not _hash_values(
|
||||
elif hash_values(checked, field_name) and not hash_values(
|
||||
comparable(matched.platform), field_name
|
||||
):
|
||||
matched.filled.append(field_name)
|
||||
@@ -581,7 +581,7 @@ class _TruthPass:
|
||||
def __post_init__(self) -> None:
|
||||
scraped_systems = self.scraped_systems
|
||||
self.norm_to_scraped = {
|
||||
_norm_system_id(key): key for key in scraped_systems
|
||||
norm_system_id(key): key for key in scraped_systems
|
||||
}
|
||||
self.platform_ids = {
|
||||
native_id
|
||||
@@ -593,7 +593,7 @@ class _TruthPass:
|
||||
}
|
||||
self.native_by_norm = {}
|
||||
for system in self.systems.values():
|
||||
self.native_by_norm.setdefault(_norm_system_id(system.native_id), system.native_id)
|
||||
self.native_by_norm.setdefault(norm_system_id(system.native_id), system.native_id)
|
||||
|
||||
def target_native_ids(self, truth_sid: str) -> tuple[list[str], bool]:
|
||||
"""The native ids a truth system spans, and whether the first one
|
||||
@@ -601,7 +601,7 @@ class _TruthPass:
|
||||
scraped_systems = self.scraped_systems
|
||||
scraped_key = truth_sid if truth_sid in scraped_systems else None
|
||||
if scraped_key is None:
|
||||
scraped_key = self.norm_to_scraped.get(_norm_system_id(truth_sid))
|
||||
scraped_key = self.norm_to_scraped.get(norm_system_id(truth_sid))
|
||||
if scraped_key is not None:
|
||||
sys_data = scraped_systems[scraped_key]
|
||||
ids = {
|
||||
@@ -620,7 +620,7 @@ class _TruthPass:
|
||||
ordered.remove(primary)
|
||||
ordered.insert(0, primary)
|
||||
return ordered, primary in ids or len(ordered) == 1
|
||||
direct = self.native_by_norm.get(_norm_system_id(truth_sid))
|
||||
direct = self.native_by_norm.get(norm_system_id(truth_sid))
|
||||
return ([direct] if direct else [truth_sid]), True
|
||||
|
||||
def _files_of(self, target_ids: list[str]) -> list[NativeFile]:
|
||||
@@ -639,7 +639,7 @@ class _TruthPass:
|
||||
truth_files = [
|
||||
entry for entry in truth_files
|
||||
if (name := str(entry.get("name", "")))
|
||||
and not name.startswith("_") and not _is_placeholder(name)
|
||||
and not name.startswith("_") and not is_placeholder(name)
|
||||
]
|
||||
candidates = [c for c in self._files_of(target_ids) if c.truth is None]
|
||||
pairs = pair_entries(truth_files, [c.platform or {} for c in candidates])
|
||||
|
||||
@@ -16,7 +16,7 @@ except ImportError:
|
||||
yaml = None
|
||||
|
||||
from core.hashing import compute_hashes, parse_hash_list, parse_md5_list, stream_hashes
|
||||
from model.nodedup import _in_nodedup_dir
|
||||
from model.nodedup import in_nodedup_dir
|
||||
from model.platforms import load_platform_config
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.registry import list_registered_platforms
|
||||
@@ -467,7 +467,7 @@ def _check_duplicate(result: ValidationResult, db: dict, relative: str) -> None:
|
||||
# PR that regenerated database.json was told each new file
|
||||
# duplicated itself.
|
||||
result.add_check(True, "Already in the database at this path")
|
||||
elif _in_nodedup_dir(relative):
|
||||
elif in_nodedup_dir(relative):
|
||||
result.add_info(
|
||||
f"Identical to `{existing['path']}`, kept: this tree is read by path"
|
||||
)
|
||||
|
||||
@@ -8,7 +8,7 @@ from collections.abc import Iterable, Mapping
|
||||
from dataclasses import dataclass
|
||||
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.systems import _norm_system_id
|
||||
from model.systems import norm_system_id
|
||||
from resolve.contentlayout import content_folder_tags, content_layout
|
||||
from resolve.layout import (
|
||||
CONTENT_TAG_PREFIXES,
|
||||
@@ -20,8 +20,8 @@ from resolve.layout import (
|
||||
OUTSIDE_BIOS_FOLDER,
|
||||
OWN_BUILD_PREFIX,
|
||||
SYSTEM_FILE_PREFIX,
|
||||
_handed,
|
||||
_placed_entry,
|
||||
handed_from_tags,
|
||||
placed_entry,
|
||||
core_system_dirs,
|
||||
entry_launch_systems,
|
||||
runs_standalone,
|
||||
@@ -131,7 +131,7 @@ def standalone_set(config: dict) -> set[str]:
|
||||
natives = native_systems(config)
|
||||
names |= {
|
||||
SYSTEM_FILE_PREFIX + json.dumps(
|
||||
[natives.get(str(native), str(native)), MACHINE_KEY + _norm_system_id(str(m))]
|
||||
[natives.get(str(native), str(native)), MACHINE_KEY + norm_system_id(str(m))]
|
||||
)
|
||||
for record in config.get("launchers") or []
|
||||
for native in record.get("systems") or []
|
||||
@@ -196,7 +196,7 @@ class _StandaloneLaunches:
|
||||
names = {emu_name, *(str(c) for c in profile.get("cores") or [])}
|
||||
per_system = bool(
|
||||
profile.get("standalone_directories") or profile.get("standalone_pools")
|
||||
) and any(h.systems and h.emulator in names for h in _handed(standalone_cores))
|
||||
) and any(h.systems and h.emulator in names for h in handed_from_tags(standalone_cores))
|
||||
index = system_file_index(standalone_cores) if per_system else {}
|
||||
# A profile system the platform launches under a system of its own, as
|
||||
# its list says for one entry, is launched there for every entry:
|
||||
@@ -212,7 +212,7 @@ class _StandaloneLaunches:
|
||||
# the folder its record gives, every other launch the folder the records
|
||||
# naming none give.
|
||||
named_systems = frozenset().union(*(
|
||||
h.systems for h in _handed(standalone_cores) if h.emulator in names
|
||||
h.systems for h in handed_from_tags(standalone_cores) if h.emulator in names
|
||||
)) if per_system else frozenset()
|
||||
|
||||
# The layout folders a search setting stands for (standalone_pools):
|
||||
@@ -237,7 +237,7 @@ class _StandaloneLaunches:
|
||||
# own system selects the launch that offers it as a machine
|
||||
# (RetroBat runs XRoar's coco3 under coco).
|
||||
systems = systems.union(*(
|
||||
self.index.get(MACHINE_KEY + _norm_system_id(s), set()) for s in own
|
||||
self.index.get(MACHINE_KEY + norm_system_id(s), set()) for s in own
|
||||
))
|
||||
return systems
|
||||
|
||||
@@ -298,7 +298,7 @@ class _StandaloneLaunches:
|
||||
# -hash bios/mame/hash (Mame64.Generator.cs:172, 177-178), and
|
||||
# the hash/ beside mame.exe is no longer read.
|
||||
moved = {k: v for k, v in f.items() if k != "bundled"}
|
||||
files.extend(_placed_entry(moved, self.profile, placed) for placed in places)
|
||||
files.extend(placed_entry(moved, self.profile, placed) for placed in places)
|
||||
return files
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import sys
|
||||
from dataclasses import dataclass
|
||||
|
||||
from model.declarations import OUTER_ROOTS
|
||||
from model.systems import _norm_system_id
|
||||
from model.systems import norm_system_id
|
||||
from model.registry import load_data_dir_registry
|
||||
from resolve.standalone import platform_layouts, standalone_set as platform_standalone_set
|
||||
from resolve.cores import resolve_platform_cores
|
||||
@@ -676,7 +676,7 @@ class _SystemMap:
|
||||
declared_by_name.setdefault(fname, []).append((psid, fe))
|
||||
norm_to_platform: dict[str, str] = {}
|
||||
for psid in config.get("systems", {}):
|
||||
norm_to_platform.setdefault(_norm_system_id(psid), psid)
|
||||
norm_to_platform.setdefault(norm_system_id(psid), psid)
|
||||
return cls(
|
||||
set(config.get("systems", {}).keys()), declared_by_name, norm_to_platform, db,
|
||||
)
|
||||
@@ -685,7 +685,7 @@ class _SystemMap:
|
||||
"""Map a profile system ID to the platform's system ID."""
|
||||
if profile_sid in self.platform_sys_ids:
|
||||
return profile_sid
|
||||
return self.norm_to_platform.get(_norm_system_id(profile_sid), profile_sid)
|
||||
return self.norm_to_platform.get(norm_system_id(profile_sid), profile_sid)
|
||||
|
||||
def attribute(self, fe: dict, own: str | None, on_platform: set[str]) -> list[str]:
|
||||
"""The platform systems an entry belongs to, [] when nothing decides.
|
||||
@@ -962,12 +962,12 @@ def _diff_system(truth_sys: dict, scraped_sys: dict) -> dict:
|
||||
correct while the export corrected hashes the diff never named. An entry
|
||||
never answers for two.
|
||||
"""
|
||||
from resolve.reconcile import _is_placeholder, is_label, pair_entries, platform_declares
|
||||
from resolve.reconcile import is_placeholder, is_label, pair_entries, platform_declares
|
||||
|
||||
truth_files = [
|
||||
fe for fe in truth_sys.get("files", [])
|
||||
if fe.get("name") and not fe["name"].startswith("_")
|
||||
and not _is_placeholder(fe["name"])
|
||||
and not is_placeholder(fe["name"])
|
||||
]
|
||||
scraped_files = scraped_sys.get("files", [])
|
||||
|
||||
@@ -1074,7 +1074,7 @@ def _update_summary(summary: dict, sys_div: dict) -> None:
|
||||
def diff_platform_truth(truth: dict, scraped: dict) -> dict:
|
||||
"""Compare truth YAML against scraped YAML, returning divergences.
|
||||
|
||||
System IDs are matched using normalized forms (via _norm_system_id) to
|
||||
System IDs are matched using normalized forms (via norm_system_id) to
|
||||
handle naming differences between emulator profiles and scraped platforms
|
||||
(e.g. 'sega-game-gear' vs 'sega-gamegear').
|
||||
"""
|
||||
@@ -1099,13 +1099,13 @@ def diff_platform_truth(truth: dict, scraped: dict) -> dict:
|
||||
# Build normalized-ID lookup for truth systems
|
||||
norm_to_truth: dict[str, str] = {}
|
||||
for sid in truth_systems:
|
||||
norm_to_truth[_norm_system_id(sid)] = sid
|
||||
norm_to_truth[norm_system_id(sid)] = sid
|
||||
|
||||
# Match scraped systems to truth via normalized IDs
|
||||
matched_truth: set[str] = set()
|
||||
|
||||
for s_sid in sorted(scraped_systems):
|
||||
norm = _norm_system_id(s_sid)
|
||||
norm = norm_system_id(s_sid)
|
||||
t_sid = norm_to_truth.get(norm)
|
||||
|
||||
if t_sid is None:
|
||||
|
||||
@@ -50,7 +50,7 @@ _CONTENT_REASONS = {
|
||||
_HASH_CHECKS = frozenset({"crc32", "md5", "sha1", "adler32"})
|
||||
|
||||
|
||||
def _parse_validation(validation: list | dict | None) -> list[str]:
|
||||
def parse_validation(validation: list | dict | None) -> list[str]:
|
||||
"""Extract the validation check list from a file's validation field.
|
||||
|
||||
Handles both simple list and divergent (core/upstream) dict forms.
|
||||
@@ -378,7 +378,7 @@ def _index_entry(index: dict[str, dict], emu_name: str, f: dict, checks: list[st
|
||||
_merge_per_emulator(item, emu_name, f, checks)
|
||||
|
||||
|
||||
def _build_validation_index(profiles: dict) -> dict[str, dict]:
|
||||
def build_validation_index(profiles: dict) -> dict[str, dict]:
|
||||
"""Build per-filename validation rules from emulator profiles.
|
||||
|
||||
Returns {filename: {"checks": [str], "size": int|None, "min_size": int|None,
|
||||
@@ -407,7 +407,7 @@ def _build_validation_index(profiles: dict) -> dict[str, dict]:
|
||||
fname = f.get("name", "")
|
||||
if not fname:
|
||||
continue
|
||||
checks = _parse_validation(f.get("validation"))
|
||||
checks = parse_validation(f.get("validation"))
|
||||
slot = (fname, emu_name, f.get("path") or fname)
|
||||
if not checks:
|
||||
unchecked.add(slot)
|
||||
|
||||
Reference in new issue
Block a user