mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 06:18:51 -06:00
refactor: make names shared across modules public
This commit is contained in:
1 parent
c3b67d5485
commit
61e302d8f6
45 files changed
+653
-653
No files matched your search
@@ -172,7 +172,7 @@ def set_by(entry: dict, passes_to: str) -> bool:
|
||||
return bool(key) and key in setting_tokens(passes_to)
|
||||
|
||||
|
||||
def _bios_relative(directory: str, base: str) -> str | None:
|
||||
def bios_relative(directory: str, base: str) -> str | None:
|
||||
"""A launcher directory relative to the BIOS root, None when it is not one."""
|
||||
directory = directory.strip().rstrip("/")
|
||||
roots = {base, "<system_directory>", *BIOS_ROOT_TOKENS}
|
||||
@@ -205,7 +205,7 @@ def record_directories(record: dict, base: str) -> list[str] | None:
|
||||
for part in re.split(r",|\bthen\b|\belse\b", text):
|
||||
if not part.strip():
|
||||
continue
|
||||
relative = _bios_relative(part, base)
|
||||
relative = bios_relative(part, base)
|
||||
if relative is None:
|
||||
return []
|
||||
if relative not in found:
|
||||
|
||||
@@ -10,11 +10,11 @@ from model.declarations import CONFIGS_ROOT, ROMS_ROOT, declared_root, declared_
|
||||
from model.launcherrecords import record_emulators
|
||||
from core.paths import sanitize_pack_path
|
||||
from resolve.launcherconfig import bound_launchers
|
||||
from resolve.launcherplaces import _bios_relative, record_directories
|
||||
from resolve.launcherplaces import bios_relative, record_directories
|
||||
|
||||
|
||||
# The names a platform's launch code gives its BIOS root, besides the
|
||||
# base_destination _bios_relative reads: RetroPie's scriptmodules set
|
||||
# base_destination bios_relative reads: RetroPie's scriptmodules set
|
||||
# biosdir="$home/RetroPie/BIOS", EmuDeck's scripts ${biosPath}, RetroDECK's
|
||||
# component scripts $bios_path.
|
||||
BIOS_ROOT_VARIABLES = ("$biosdir", "$home/RetroPie/BIOS", "${biosPath}", "$bios_path")
|
||||
@@ -96,7 +96,7 @@ def ini_keys(passes_to: str) -> frozenset[str]:
|
||||
|
||||
def _folder_in_bios(directory: str, base: str) -> str | None:
|
||||
"""A directory relative to the BIOS root, None when it lies outside."""
|
||||
relative = _bios_relative(directory, base)
|
||||
relative = bios_relative(directory, base)
|
||||
if relative is not None:
|
||||
return relative
|
||||
directory = directory.strip().rstrip("/")
|
||||
|
||||
@@ -24,14 +24,14 @@ from resolve.ownership import (
|
||||
owner_tokens,
|
||||
system_makers,
|
||||
)
|
||||
from resolve.lookup import Resolution, _Lookup, _entry_hint, _lookup, _record_match_status
|
||||
from resolve.lookup import Resolution, Lookup, entry_hint, lookup, record_match_status
|
||||
from resolve.namestages import (
|
||||
_by_name,
|
||||
_by_zip_contents,
|
||||
_named_candidates,
|
||||
_named_md5_match,
|
||||
_ranked_mismatch,
|
||||
_zipped_named,
|
||||
name_or_alias_match,
|
||||
by_zip_contents,
|
||||
named_candidates,
|
||||
named_md5_match,
|
||||
ranked_mismatch,
|
||||
zipped_named,
|
||||
)
|
||||
|
||||
|
||||
@@ -122,16 +122,16 @@ def _rank_tail_candidates(
|
||||
)
|
||||
|
||||
|
||||
def _held_record(q: _Lookup, match_sha1: str) -> Resolution | None:
|
||||
def _held_record(q: Lookup, match_sha1: str) -> Resolution | None:
|
||||
"""The record's path and evidence, when it satisfies the entry and is on disk."""
|
||||
path = q.files_db[match_sha1]["path"]
|
||||
status = _record_match_status(q, match_sha1)
|
||||
status = record_match_status(q, match_sha1)
|
||||
if status and os.path.exists(path):
|
||||
return path, status
|
||||
return None
|
||||
|
||||
|
||||
def _by_sha1(q: _Lookup) -> Resolution | None:
|
||||
def _by_sha1(q: Lookup) -> Resolution | None:
|
||||
"""SHA1 exact match (accept list-valued sha1 from profiles)."""
|
||||
for cand in q.sha1_candidates:
|
||||
if cand in q.files_db:
|
||||
@@ -141,7 +141,7 @@ def _by_sha1(q: _Lookup) -> Resolution | None:
|
||||
return None
|
||||
|
||||
|
||||
def _by_sha256(q: _Lookup) -> Resolution | None:
|
||||
def _by_sha256(q: Lookup) -> Resolution | None:
|
||||
"""SHA256 exact match, through the by_sha256 index."""
|
||||
if not q.sha256_candidates:
|
||||
return None
|
||||
@@ -155,7 +155,7 @@ def _by_sha256(q: _Lookup) -> Resolution | None:
|
||||
return None
|
||||
|
||||
|
||||
def _by_crc32(q: _Lookup) -> Resolution | None:
|
||||
def _by_crc32(q: Lookup) -> Resolution | None:
|
||||
"""CRC32 lookup, only when no stronger hash is declared."""
|
||||
if (
|
||||
not q.crc_candidates
|
||||
@@ -182,7 +182,7 @@ def _by_crc32(q: _Lookup) -> Resolution | None:
|
||||
return None
|
||||
|
||||
|
||||
def _md5_hits(q: _Lookup) -> Iterator[tuple[str, str, str]]:
|
||||
def _md5_hits(q: Lookup) -> Iterator[tuple[str, str, str]]:
|
||||
"""Each held record a declared md5 names: path, evidence, md5 asked.
|
||||
|
||||
Skipped for zipped_file: the md5 is the inner ROM's, not the container's.
|
||||
@@ -207,7 +207,7 @@ def _named_or_variant(names: frozenset[str], candidate_path: str) -> bool:
|
||||
return any(bn.startswith(n + ".") for n in names)
|
||||
|
||||
|
||||
def _tail_candidates(q: _Lookup, start: int, tail: str, owners: set[str]) -> list[str]:
|
||||
def _tail_candidates(q: Lookup, start: int, tail: str, owners: set[str]) -> list[str]:
|
||||
"""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,
|
||||
@@ -228,7 +228,7 @@ def _tail_candidates(q: _Lookup, start: int, tail: str, owners: set[str]) -> lis
|
||||
return candidates
|
||||
|
||||
|
||||
def _tail_match(q: _Lookup, candidates: list[str]) -> Resolution | None:
|
||||
def _tail_match(q: Lookup, candidates: list[str]) -> Resolution | None:
|
||||
"""The first candidate of a tail on disk that the entry accepts."""
|
||||
for match_sha1 in candidates:
|
||||
if match_sha1 not in q.files_db:
|
||||
@@ -247,13 +247,13 @@ def _tail_match(q: _Lookup, candidates: list[str]) -> Resolution | None:
|
||||
):
|
||||
continue
|
||||
return path, "path_exact"
|
||||
status = _record_match_status(q, match_sha1)
|
||||
status = record_match_status(q, match_sha1)
|
||||
if status:
|
||||
return path, status
|
||||
return None
|
||||
|
||||
|
||||
def _by_path_suffix(q: _Lookup) -> tuple[Resolution | None, bool]:
|
||||
def _by_path_suffix(q: Lookup) -> tuple[Resolution | None, bool]:
|
||||
"""The file at the destination's tail, and whether the indexed one is absent."""
|
||||
own_file_absent = False
|
||||
if not (q.dest_hint and q.by_path_suffix):
|
||||
@@ -296,7 +296,7 @@ def _by_path_suffix(q: _Lookup) -> tuple[Resolution | None, bool]:
|
||||
return None, own_file_absent
|
||||
|
||||
|
||||
def _by_data_dir_tail(q: _Lookup, data_dir_registry: dict | None) -> Resolution | None:
|
||||
def _by_data_dir_tail(q: Lookup, data_dir_registry: dict | None) -> Resolution | None:
|
||||
"""The same tail in a data directory, for a platform's hashless entry."""
|
||||
# by_path_suffix indexes bios/
|
||||
# only, so AmberELEC's Machines/MSX - Arabic/config.ini fell through to
|
||||
@@ -322,7 +322,7 @@ def _by_data_dir_tail(q: _Lookup, data_dir_registry: dict | None) -> Resolution
|
||||
|
||||
|
||||
def _by_mame_clone(
|
||||
q: _Lookup, zip_contents: dict | None, depth: int, data_dir_registry: dict | None
|
||||
q: Lookup, zip_contents: dict | None, depth: int, data_dir_registry: dict | None
|
||||
) -> Resolution | None:
|
||||
"""If a file was deduped, resolve via canonical."""
|
||||
clone_map = get_mame_clone_map(q.db.get("bios_dir"))
|
||||
@@ -351,7 +351,7 @@ def _by_mame_clone(
|
||||
return None
|
||||
|
||||
|
||||
def _in_data_dirs(q: _Lookup, data_dir_registry: dict) -> tuple[Resolution | None, str | None]:
|
||||
def _in_data_dirs(q: Lookup, data_dir_registry: dict) -> tuple[Resolution | None, str | None]:
|
||||
"""Data directory fallback: scan data/ caches for matching filename."""
|
||||
verdict = functools.partial(
|
||||
declared_hash_verdict,
|
||||
@@ -436,7 +436,7 @@ def resolve_local_file(
|
||||
|
||||
A path or filename is never allowed to override a declared strong hash.
|
||||
"""
|
||||
dest_hint = _entry_hint(file_entry, dest_hint)
|
||||
dest_hint = entry_hint(file_entry, dest_hint)
|
||||
# A launcher that moves the layout (EmuDeck links azahar's sysdata to
|
||||
# bios/azahar/keys) changes where the file goes, not the tail the
|
||||
# collection indexes it under. Both are asked, and the stronger proof
|
||||
@@ -459,7 +459,7 @@ def resolve_local_file(
|
||||
# the container's own md5: neocd.bin's md5 is also the composite of a
|
||||
# one-member neocdz.zip, and the raw ROM shipped under the archive's name.
|
||||
composite_only = file_entry.get("zip_digest") == "composite"
|
||||
q = _lookup(
|
||||
q = lookup(
|
||||
file_entry, db, _name_as_hint(file_entry.get("name", ""), dest_hint),
|
||||
[cut_owners.get(value, value) for value in md5_list],
|
||||
composite_only=composite_only,
|
||||
@@ -521,25 +521,25 @@ def resolve_local_file(
|
||||
makers: frozenset[str] = frozenset() if has_strong_hash else system_makers(file_entry, db)
|
||||
|
||||
if not has_strong_hash and not unsourceable:
|
||||
found, unsourceable = _by_name(q, makers, data_dir_registry)
|
||||
found, unsourceable = name_or_alias_match(q, makers, data_dir_registry)
|
||||
if found:
|
||||
return found
|
||||
|
||||
# 4. Name + alias fallback with md5_composite + direct MD5 per candidate
|
||||
named = _named_candidates(q, makers)
|
||||
named = named_candidates(q, makers)
|
||||
if named:
|
||||
found = _named_md5_match(q, named)
|
||||
found = named_md5_match(q, named)
|
||||
if q.zipped_file:
|
||||
found = found or _zipped_named(q, named, q.zipped_file)
|
||||
found = found or zipped_named(q, named, q.zipped_file)
|
||||
elif not unsourceable:
|
||||
found = found or _ranked_mismatch(q, named)
|
||||
found = found or ranked_mismatch(q, named)
|
||||
if found:
|
||||
return found
|
||||
|
||||
# 5. zipped_file content match via pre-built index (last resort:
|
||||
# matches inner ROM MD5 across ALL ZIPs in the repo, so only use
|
||||
# when name-based resolution failed entirely)
|
||||
found = _by_zip_contents(q, zip_contents)
|
||||
found = by_zip_contents(q, zip_contents)
|
||||
|
||||
# MAME clone fallback: if a file was deduped, resolve via canonical. The
|
||||
# clone name is a name step like the others: an unsourceable entry skips
|
||||
|
||||
+13
-13
@@ -27,7 +27,7 @@ Resolution = tuple[str, str]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class _Lookup:
|
||||
class Lookup:
|
||||
"""One entry as resolve_local_file reads it: its names and declared hashes."""
|
||||
|
||||
file_entry: dict
|
||||
@@ -76,9 +76,9 @@ def _lookup_names(name: str, aliases: list, dest_hint: str) -> tuple[list[str],
|
||||
return names_to_try, own_names
|
||||
|
||||
|
||||
def _lookup(
|
||||
def lookup(
|
||||
file_entry: dict, db: dict, dest_hint: str, md5_list: list[str], *, composite_only: bool
|
||||
) -> _Lookup:
|
||||
) -> Lookup:
|
||||
"""Read the names and every declared hash of an entry once."""
|
||||
sha1 = file_entry.get("sha1")
|
||||
name = file_entry.get("name", "")
|
||||
@@ -107,7 +107,7 @@ def _lookup(
|
||||
if candidate.strip()
|
||||
)
|
||||
indexes = db.get("indexes", {})
|
||||
return _Lookup(
|
||||
return Lookup(
|
||||
file_entry=file_entry,
|
||||
db=db,
|
||||
dest_hint=dest_hint,
|
||||
@@ -127,7 +127,7 @@ def _lookup(
|
||||
)
|
||||
|
||||
|
||||
def _record_match_status(q: _Lookup, match_sha1: str) -> str | None:
|
||||
def record_match_status(q: Lookup, match_sha1: str) -> str | None:
|
||||
"""Return hash evidence when a DB record satisfies every declaration."""
|
||||
entry = q.files_db.get(match_sha1)
|
||||
if not entry:
|
||||
@@ -174,7 +174,7 @@ def held_record_for(file_entry: dict, db: dict) -> str | None:
|
||||
(cut_md5_owner(value, by_md5) or value) if len(value) < 32 else value
|
||||
for value in parse_hash_list(file_entry.get("md5"))
|
||||
]
|
||||
q = _lookup(
|
||||
q = lookup(
|
||||
file_entry, db, "", md5_list,
|
||||
composite_only=file_entry.get("zip_digest") == "composite",
|
||||
)
|
||||
@@ -187,7 +187,7 @@ def held_record_for(file_entry: dict, db: dict) -> str | None:
|
||||
if not (q.sha1_candidates or q.sha256_candidates or q.md5_list or q.zipped_file):
|
||||
candidates += [indexes.get("by_crc32", {}).get(v) for v in q.crc_candidates]
|
||||
return next(
|
||||
(c for c in candidates if c and c in q.files_db and _record_match_status(q, c)),
|
||||
(c for c in candidates if c and c in q.files_db and record_match_status(q, c)),
|
||||
None,
|
||||
)
|
||||
|
||||
@@ -203,8 +203,8 @@ def variant_copies(
|
||||
A copy passes the shape the entry's code checks and, when the entry
|
||||
declares hashes, agrees with every one of them, as the resolver requires.
|
||||
"""
|
||||
q = _lookup(
|
||||
file_entry, db, _entry_hint(file_entry, dest_hint), [
|
||||
q = lookup(
|
||||
file_entry, db, entry_hint(file_entry, dest_hint), [
|
||||
(cut_md5_owner(value, db.get("indexes", {}).get("by_md5", {})) or value)
|
||||
if len(value) < 32 else value
|
||||
for value in parse_hash_list(file_entry.get("md5"))
|
||||
@@ -229,8 +229,8 @@ def variant_copies(
|
||||
os.path.dirname(os.path.normpath(path)) == home
|
||||
and os.path.normpath(path) != primary
|
||||
and variant_base_name(os.path.basename(path)) in names
|
||||
and (not hashed or _record_match_status(q, match_sha1))
|
||||
and _name_size_ok(q, match_sha1)
|
||||
and (not hashed or record_match_status(q, match_sha1))
|
||||
and name_size_ok(q, match_sha1)
|
||||
and os.path.exists(path)
|
||||
and path not in out
|
||||
):
|
||||
@@ -238,7 +238,7 @@ def variant_copies(
|
||||
return out
|
||||
|
||||
|
||||
def _name_size_ok(q: _Lookup, match_sha1: str) -> bool:
|
||||
def name_size_ok(q: Lookup, match_sha1: str) -> bool:
|
||||
"""Whether a record found by name has the shape the entry's code checks."""
|
||||
record = q.files_db.get(match_sha1, {})
|
||||
return name_match_size_ok(q.file_entry, record.get("size")) and adler32_fits(
|
||||
@@ -246,7 +246,7 @@ def _name_size_ok(q: _Lookup, match_sha1: str) -> bool:
|
||||
) and content_fits(q.file_entry, record.get("path", ""))
|
||||
|
||||
|
||||
def _entry_hint(file_entry: dict, dest_hint: str) -> str:
|
||||
def entry_hint(file_entry: dict, dest_hint: str) -> str:
|
||||
"""The destination tail the collection indexes the entry under."""
|
||||
# A platform that hands each core a system directory of its own (MinUI's
|
||||
# Bios/<TAG>/) writes that folder in front of the core's path. The tail
|
||||
|
||||
@@ -23,7 +23,7 @@ from resolve.content import (
|
||||
shape_fits,
|
||||
)
|
||||
from resolve.datadirs import resolve_in_data_dirs
|
||||
from resolve.lookup import Resolution, _Lookup, _name_size_ok
|
||||
from resolve.lookup import Resolution, Lookup, name_size_ok
|
||||
from resolve.ownership import (
|
||||
affinity_tokens,
|
||||
engine_tree,
|
||||
@@ -83,7 +83,7 @@ def _by_affinity(paths: list[str], file_entry: dict, dest_hint: str) -> list[str
|
||||
return sorted(paths, key=score, reverse=True)
|
||||
|
||||
|
||||
def _exact_name_candidates(q: _Lookup) -> list[str]:
|
||||
def _exact_name_candidates(q: Lookup) -> list[str]:
|
||||
"""The held files answering to the entry's names, exact casing."""
|
||||
candidates: list[str] = []
|
||||
# The entry's own names first, the destination's basename only when
|
||||
@@ -99,7 +99,7 @@ def _exact_name_candidates(q: _Lookup) -> list[str]:
|
||||
for match_sha1 in (
|
||||
by_proven_name.get(try_name) or q.by_name.get(try_name, [])
|
||||
):
|
||||
if match_sha1 in q.files_db and _name_size_ok(q, match_sha1):
|
||||
if match_sha1 in q.files_db and name_size_ok(q, match_sha1):
|
||||
path = q.files_db[match_sha1]["path"]
|
||||
if os.path.exists(path) and path not in candidates:
|
||||
candidates.append(path)
|
||||
@@ -108,7 +108,7 @@ def _exact_name_candidates(q: _Lookup) -> list[str]:
|
||||
return candidates
|
||||
|
||||
|
||||
def _add_variant_primaries(q: _Lookup, candidates: list[str]) -> None:
|
||||
def _add_variant_primaries(q: Lookup, candidates: list[str]) -> None:
|
||||
"""Add the primaries that variants answering the exact casing stand in for."""
|
||||
# Only variants answer the exact casing, but the primary they
|
||||
# stand in for may be stored under another one: x1 asked for
|
||||
@@ -127,14 +127,14 @@ def _add_variant_primaries(q: _Lookup, candidates: list[str]) -> None:
|
||||
"/.variants/" not in path
|
||||
and os.path.dirname(path) in homes
|
||||
and os.path.basename(path).casefold() == wanted
|
||||
and _name_size_ok(q, match_sha1)
|
||||
and name_size_ok(q, match_sha1)
|
||||
and os.path.exists(path)
|
||||
and path not in candidates
|
||||
):
|
||||
candidates.append(path)
|
||||
|
||||
|
||||
def _add_casefold_candidates(q: _Lookup, candidates: list[str], owners: set[str]) -> None:
|
||||
def _add_casefold_candidates(q: Lookup, candidates: list[str], owners: set[str]) -> None:
|
||||
"""Add the held files answering to the entry's names in another casing."""
|
||||
# Case-insensitive fallback: upstream platforms disagree on
|
||||
# casing (VEC_MineStorm.vec vs VEC_Minestorm.vec). Two casings
|
||||
@@ -148,7 +148,7 @@ def _add_casefold_candidates(q: _Lookup, candidates: list[str], owners: set[str]
|
||||
folded = _casefold_name_index(q.by_name)
|
||||
for try_name in q.names_to_try:
|
||||
for match_sha1 in folded.get(try_name.casefold(), []):
|
||||
if match_sha1 in q.files_db and _name_size_ok(q, match_sha1):
|
||||
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):
|
||||
continue
|
||||
@@ -156,7 +156,7 @@ def _add_casefold_candidates(q: _Lookup, candidates: list[str], owners: set[str]
|
||||
candidates.append(path)
|
||||
|
||||
|
||||
def _same_maker(q: _Lookup, candidates: list[str], makers: frozenset[str]) -> list[str]:
|
||||
def _same_maker(q: Lookup, candidates: list[str], makers: frozenset[str]) -> list[str]:
|
||||
"""The candidates filed under the system's maker, or its shadowed aliases."""
|
||||
candidates = [p for p in candidates if not other_maker(p, makers, q.db)]
|
||||
if candidates:
|
||||
@@ -173,7 +173,7 @@ def _same_maker(q: _Lookup, candidates: list[str], makers: frozenset[str]) -> li
|
||||
if (
|
||||
maker_folder(path, str(q.db.get("bios_dir") or "bios"))
|
||||
in makers
|
||||
and _name_size_ok(q, match_sha1)
|
||||
and name_size_ok(q, match_sha1)
|
||||
and os.path.exists(path)
|
||||
and path not in candidates
|
||||
):
|
||||
@@ -182,7 +182,7 @@ def _same_maker(q: _Lookup, candidates: list[str], makers: frozenset[str]) -> li
|
||||
|
||||
|
||||
def _choose_by_name(
|
||||
q: _Lookup,
|
||||
q: Lookup,
|
||||
candidates: list[str],
|
||||
owners: set[str],
|
||||
exact_foreign: bool,
|
||||
@@ -244,8 +244,8 @@ def _choose_by_name(
|
||||
return chosen, "name_exact"
|
||||
|
||||
|
||||
def _by_name(
|
||||
q: _Lookup, makers: frozenset[str], data_dir_registry: dict | None
|
||||
def name_or_alias_match(
|
||||
q: Lookup, makers: frozenset[str], data_dir_registry: dict | None
|
||||
) -> tuple[Resolution | None, bool]:
|
||||
"""Any file with that name or alias (existence check).
|
||||
|
||||
@@ -287,7 +287,7 @@ def _by_name(
|
||||
return _choose_by_name(q, candidates, owners, exact_foreign, data_dir_registry), False
|
||||
|
||||
|
||||
def _named_candidates(q: _Lookup, makers: frozenset[str]) -> list[tuple[str, str, int | None]]:
|
||||
def named_candidates(q: Lookup, makers: frozenset[str]) -> list[tuple[str, str, int | None]]:
|
||||
"""Every held file of the entry's names: path, md5, size."""
|
||||
named: list[tuple[str, str, int | None]] = []
|
||||
seen_paths = set()
|
||||
@@ -320,7 +320,7 @@ def _named_candidates(q: _Lookup, makers: frozenset[str]) -> list[tuple[str, str
|
||||
return named
|
||||
|
||||
|
||||
def _named_md5_match(q: _Lookup, named: list[tuple[str, str, int | None]]) -> Resolution | None:
|
||||
def named_md5_match(q: Lookup, named: list[tuple[str, str, int | None]]) -> Resolution | None:
|
||||
"""A named file whose md5, or archive composite, is a declared one.
|
||||
|
||||
Sorts *named* in place for a composite-only entry, as the steps after
|
||||
@@ -350,8 +350,8 @@ def _named_md5_match(q: _Lookup, named: list[tuple[str, str, int | None]]) -> Re
|
||||
return None
|
||||
|
||||
|
||||
def _zipped_named(
|
||||
q: _Lookup, named: list[tuple[str, str, int | None]], zipped_file: str
|
||||
def zipped_named(
|
||||
q: Lookup, named: list[tuple[str, str, int | None]], zipped_file: str
|
||||
) -> Resolution | None:
|
||||
"""When zipped_file is set, only accept candidates that contain it."""
|
||||
valid = []
|
||||
@@ -376,14 +376,14 @@ def _zipped_named(
|
||||
return None
|
||||
|
||||
|
||||
def _ranked_mismatch(q: _Lookup, named: list[tuple[str, str, int | None]]) -> Resolution:
|
||||
def ranked_mismatch(q: Lookup, named: list[tuple[str, str, int | None]]) -> Resolution:
|
||||
"""The named file the entry would take, reported as a hash mismatch."""
|
||||
ordered = _by_affinity([c[0] for c in named], q.file_entry, q.dest_hint)
|
||||
primary = [c for c in ordered if "/.variants/" not in c]
|
||||
return (primary[0] if primary else ordered[0]), "hash_mismatch"
|
||||
|
||||
|
||||
def _by_zip_contents(q: _Lookup, zip_contents: dict | None) -> Resolution | None:
|
||||
def by_zip_contents(q: Lookup, zip_contents: dict | None) -> Resolution | None:
|
||||
"""zipped_file content match via pre-built index.
|
||||
|
||||
Last resort: matches inner ROM MD5 across ALL ZIPs in the repo, so only
|
||||
|
||||
+21
-21
@@ -17,15 +17,15 @@ from resolve.entryscope import (
|
||||
installed_with_emulator,
|
||||
)
|
||||
from resolve.truthsystems import (
|
||||
_SystemMap,
|
||||
_brought,
|
||||
_cover,
|
||||
_enrich_hashes,
|
||||
_has_exploitable_data,
|
||||
_platform_entries,
|
||||
_require_by_slot,
|
||||
_serialize_systems,
|
||||
_sizes_clash,
|
||||
SystemMap,
|
||||
brought_by,
|
||||
cover,
|
||||
enrich_hashes,
|
||||
has_exploitable_data,
|
||||
platform_entries,
|
||||
require_by_slot,
|
||||
serialize_systems,
|
||||
sizes_clash,
|
||||
)
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ def _shares_hash(a: dict, b: dict) -> bool:
|
||||
|
||||
def _contents_disagree(a: dict, b: dict) -> bool:
|
||||
"""A hash both declare without a value in common, or no size both admit."""
|
||||
return contradicts(declared_hashes(a), declared_hashes(b)) or _sizes_clash(a, b)
|
||||
return contradicts(declared_hashes(a), declared_hashes(b)) or sizes_clash(a, b)
|
||||
|
||||
|
||||
def _fold_into(existing: dict, file_entry: dict, emu_name: str) -> None:
|
||||
@@ -160,7 +160,7 @@ def _fold_into(existing: dict, file_entry: dict, emu_name: str) -> None:
|
||||
existing["_cores"] = existing.get("_cores", set()) | {emu_name}
|
||||
if file_entry.get("_opens_by_name", True):
|
||||
existing["_named_by"] = existing.get("_named_by", set()) | {emu_name}
|
||||
existing["_brought_by"] = existing.get("_brought_by", set()) | _brought(file_entry, emu_name)
|
||||
existing["_brought_by"] = existing.get("_brought_by", set()) | brought_by(file_entry, emu_name)
|
||||
sr = file_entry.get("source_ref")
|
||||
if sr is not None:
|
||||
sr_key = _serialize_source_ref(sr)
|
||||
@@ -310,11 +310,11 @@ def _new_truth_entry(file_entry: dict, emu_name: str, db: dict | None) -> dict:
|
||||
if grouped:
|
||||
_fold_set_member(entry, file_entry, emu_name)
|
||||
entry["_named_by"] = {emu_name} if file_entry.get("_opens_by_name", True) else set()
|
||||
entry["_brought_by"] = _brought(file_entry, emu_name)
|
||||
entry["_brought_by"] = brought_by(file_entry, emu_name)
|
||||
sr = file_entry.get("source_ref")
|
||||
entry["_source_refs"] = {_serialize_source_ref(sr)} if sr is not None else set()
|
||||
if db:
|
||||
_enrich_hashes(entry, db)
|
||||
enrich_hashes(entry, db)
|
||||
# Which core gave each hash, for the conflict warning. Dropped before
|
||||
# the model is written.
|
||||
entry["_hash_by"] = {h: emu_name for h in HASH_FIELDS if entry.get(h)}
|
||||
@@ -440,7 +440,7 @@ def generate_platform_truth(
|
||||
# 1. File-based: if the scraped platform already has this file, use its system
|
||||
# 2. Exact match: profile system ID == platform system ID
|
||||
# 3. Normalized match: strip manufacturer prefix + separators
|
||||
mapping = _SystemMap.of(config, db)
|
||||
mapping = SystemMap.of(config, db)
|
||||
|
||||
systems: dict[str, dict] = {}
|
||||
unattributed: dict[str, int] = {}
|
||||
@@ -459,7 +459,7 @@ def generate_platform_truth(
|
||||
on_platform = {
|
||||
mapping.map_sys_id(sid) for sid in profile.get("systems", [])
|
||||
} & mapping.platform_sys_ids
|
||||
for fe in _platform_entries(emu_name, profile, launches, platform_name):
|
||||
for fe in platform_entries(emu_name, profile, launches, platform_name):
|
||||
sys_targets = mapping.targets(fe, profile, on_platform)
|
||||
if not sys_targets:
|
||||
unattributed[emu_name] = unattributed.get(emu_name, 0) + 1
|
||||
@@ -469,7 +469,7 @@ def generate_platform_truth(
|
||||
_merge_file_into_system(
|
||||
system, fe if position == 0 else copy.deepcopy(fe), emu_name, db
|
||||
)
|
||||
_cover(system_cores, sys_id, "profiled", emu_name)
|
||||
cover(system_cores, sys_id, "profiled", emu_name)
|
||||
|
||||
# Ensure all systems of resolved cores have entries (even with 0 files).
|
||||
# This documents that the system is covered: the core was analyzed and
|
||||
@@ -480,12 +480,12 @@ def generate_platform_truth(
|
||||
for prof_sid in profile.get("systems", []):
|
||||
sys_id = mapping.map_sys_id(prof_sid)
|
||||
systems.setdefault(sys_id, {})
|
||||
_cover(system_cores, sys_id, "profiled", emu_name)
|
||||
cover(system_cores, sys_id, "profiled", emu_name)
|
||||
|
||||
# Track unprofiled cores per system based on profile system lists
|
||||
for emu_name in cores_unprofiled:
|
||||
for sys_id in systems:
|
||||
_cover(system_cores, sys_id, "unprofiled", emu_name)
|
||||
cover(system_cores, sys_id, "unprofiled", emu_name)
|
||||
|
||||
_fold_data_directory_readers(
|
||||
systems, profiles, sorted(cores_profiled), launches, platform_name,
|
||||
@@ -493,7 +493,7 @@ def generate_platform_truth(
|
||||
)
|
||||
|
||||
for sys_data in systems.values():
|
||||
_require_by_slot(sys_data.get("files", []))
|
||||
require_by_slot(sys_data.get("files", []))
|
||||
|
||||
# Drop files with no exploitable data AFTER all cores have contributed.
|
||||
# A file declared by one core without hash/size/path may be enriched by
|
||||
@@ -502,9 +502,9 @@ def generate_platform_truth(
|
||||
for sys_data in systems.values():
|
||||
files_list = sys_data.get("files", [])
|
||||
if files_list:
|
||||
sys_data["files"] = [fe for fe in files_list if _has_exploitable_data(fe)]
|
||||
sys_data["files"] = [fe for fe in files_list if has_exploitable_data(fe)]
|
||||
|
||||
_serialize_systems(systems, system_cores)
|
||||
serialize_systems(systems, system_cores)
|
||||
|
||||
return {
|
||||
"platform": platform_name,
|
||||
|
||||
@@ -19,7 +19,7 @@ from resolve.launches import PlatformLaunches
|
||||
from resolve.standalone import platform_layouts
|
||||
|
||||
|
||||
def _enrich_hashes(entry: dict, db: dict) -> None:
|
||||
def enrich_hashes(entry: dict, db: dict) -> None:
|
||||
"""Fill the hashes a profile omits from the record its own hash names.
|
||||
|
||||
The record is found by sha1, sha256, then md5, then crc32 with the size
|
||||
@@ -60,7 +60,7 @@ def _enrich_hashes(entry: dict, db: dict) -> None:
|
||||
entry["size"] = record["size"]
|
||||
|
||||
|
||||
def _require_by_slot(files: list[dict]) -> None:
|
||||
def require_by_slot(files: list[dict]) -> None:
|
||||
"""A core that requires a name an entry answers for requires the entry.
|
||||
|
||||
Merged by name, one core's alternatives land in several entries. Ymir
|
||||
@@ -90,7 +90,7 @@ def _require_by_slot(files: list[dict]) -> None:
|
||||
entry["required"] = True
|
||||
|
||||
|
||||
def _brought(file_entry: dict, emu_name: str) -> set[str]:
|
||||
def brought_by(file_entry: dict, emu_name: str) -> set[str]:
|
||||
"""The core and build that need the file brought, empty when the
|
||||
emulator installs it. An entry read without layer (a test, a caller of
|
||||
its own) is brought by its core's libretro build."""
|
||||
@@ -98,7 +98,7 @@ def _brought(file_entry: dict, emu_name: str) -> set[str]:
|
||||
return {brought} if brought else set()
|
||||
|
||||
|
||||
def _has_exploitable_data(entry: dict) -> bool:
|
||||
def has_exploitable_data(entry: dict) -> bool:
|
||||
"""Check if an entry has any data beyond its name that can drive verification.
|
||||
|
||||
Applied AFTER merging all cores so entries benefit from enrichment by
|
||||
@@ -189,7 +189,7 @@ def _sizes(entry: dict) -> tuple[set[int], tuple[int, float] | None]:
|
||||
return exact, (low or 0, float("inf") if high is None else high)
|
||||
|
||||
|
||||
def _sizes_clash(a: dict, b: dict) -> bool:
|
||||
def sizes_clash(a: dict, b: dict) -> bool:
|
||||
"""No size both entries admit, lists and windows included."""
|
||||
exact_a, window_a = _sizes(a)
|
||||
exact_b, window_b = _sizes(b)
|
||||
@@ -210,7 +210,7 @@ def _identity(entry: dict, db: dict | None) -> dict:
|
||||
"""The entry with the hashes and size the database knows for its hash."""
|
||||
probe = {k: entry[k] for k in ("sha1", "md5", "crc32", "size") if entry.get(k)}
|
||||
if db and probe and not any(isinstance(v, list) for v in probe.values()):
|
||||
_enrich_hashes(probe, db)
|
||||
enrich_hashes(probe, db)
|
||||
return {**entry, **{k: v for k, v in probe.items() if not entry.get(k)}}
|
||||
|
||||
|
||||
@@ -232,13 +232,13 @@ def _declaration_verdict(entry: dict, declaration: dict, db: dict | None) -> str
|
||||
ours, theirs = _identity(entry, db), _identity(declaration, db)
|
||||
if _identity_values(ours) & _identity_values(theirs):
|
||||
return "same"
|
||||
if _sizes_clash(ours, theirs):
|
||||
if sizes_clash(ours, theirs):
|
||||
return "other"
|
||||
return "undecided"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class _SystemMap:
|
||||
class SystemMap:
|
||||
"""How a profile's systems and entries map onto a platform's systems."""
|
||||
|
||||
platform_sys_ids: set[str]
|
||||
@@ -252,7 +252,7 @@ class _SystemMap:
|
||||
db: dict | None
|
||||
|
||||
@classmethod
|
||||
def of(cls, config: dict, db: dict | None) -> _SystemMap:
|
||||
def of(cls, config: dict, db: dict | None) -> SystemMap:
|
||||
declared_by_name: dict[str, list[tuple[str, dict]]] = {}
|
||||
for psid, sys_data in config.get("systems", {}).items():
|
||||
for fe in sys_data.get("files", []):
|
||||
@@ -333,7 +333,7 @@ class _SystemMap:
|
||||
return sys_targets
|
||||
|
||||
|
||||
def _cover(
|
||||
def cover(
|
||||
system_cores: dict[str, dict[str, set[str]]], sys_id: str, kind: str, emu_name: str,
|
||||
) -> None:
|
||||
sys_cov = system_cores.setdefault(
|
||||
@@ -346,7 +346,7 @@ def _cover(
|
||||
sys_cov[kind].add(emu_name)
|
||||
|
||||
|
||||
def _platform_entries(
|
||||
def platform_entries(
|
||||
emu_name: str, profile: dict, launches: PlatformLaunches, platform_name: str,
|
||||
) -> list[dict]:
|
||||
# The pack's rule (validation.deliverable), per build: a file the
|
||||
@@ -365,7 +365,7 @@ def _platform_entries(
|
||||
])
|
||||
|
||||
|
||||
def _serialize_systems(
|
||||
def serialize_systems(
|
||||
systems: dict[str, dict], system_cores: dict[str, dict[str, set[str]]],
|
||||
) -> None:
|
||||
# Convert sets to sorted lists for serialization
|
||||
|
||||
Reference in new issue
Block a user