mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-24 18:47:53 -06:00
refactor: share the entry name set with categories
This commit is contained in:
1 parent
bf777d321f
commit
11dac5a641
2 files changed
+9
-25
No files matched your search
@@ -18,7 +18,7 @@ from pathlib import Path
|
||||
|
||||
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.reconcile import HASH_FIELDS, NativeSystem, entry_names, hash_values
|
||||
from resolve.launchers import record_names as launcher_names
|
||||
|
||||
|
||||
@@ -97,11 +97,7 @@ class ReadEvidence:
|
||||
for loc in [*locations, str(entry.get("name", ""))] if loc
|
||||
}
|
||||
continue
|
||||
self.names |= {
|
||||
str(n).casefold()
|
||||
for n in (entry.get("name"), *(entry.get("aliases") or []))
|
||||
if n
|
||||
}
|
||||
self.names |= entry_names(entry)
|
||||
for location in locations:
|
||||
tails = _tails(location)
|
||||
self.tails.update(tails)
|
||||
@@ -125,11 +121,7 @@ class ReadEvidence:
|
||||
|
||||
def proof(self, entry: dict, destination: str) -> str | None:
|
||||
"""How a profile reads the entry, or None when nothing answers."""
|
||||
names = {
|
||||
str(n).casefold()
|
||||
for n in (entry.get("name"), *(entry.get("aliases") or []))
|
||||
if n
|
||||
}
|
||||
names = entry_names(entry)
|
||||
tails = _tails(destination)
|
||||
if any(t in self.tails for t in tails[:-1]):
|
||||
return "path"
|
||||
@@ -188,11 +180,7 @@ class ProofIndex:
|
||||
|
||||
def proofs(self, entry: dict, destination: str) -> dict[int, str]:
|
||||
"""Reader position -> its proof, for the readers that have one."""
|
||||
names = {
|
||||
str(n).casefold()
|
||||
for n in (entry.get("name"), *(entry.get("aliases") or []))
|
||||
if n
|
||||
}
|
||||
names = entry_names(entry)
|
||||
tails = _tails(destination)
|
||||
last = {tails[-1]} if tails else set()
|
||||
hashes = {
|
||||
@@ -403,7 +391,7 @@ class EntryCategories:
|
||||
for position, f in enumerate(self._profiles[key].get("files") or []):
|
||||
if not isinstance(f, dict) or (f.get("category") == GAME_DATA) != (kind == GAME_DATA):
|
||||
continue
|
||||
for n in {str(n).casefold() for n in (f.get("name"), *(f.get("aliases") or [])) if n}:
|
||||
for n in entry_names(f):
|
||||
by_name.setdefault(n, []).append((position, f))
|
||||
for value in self._accepted_by(f):
|
||||
by_hash.setdefault(value, []).append((position, f))
|
||||
@@ -420,11 +408,7 @@ class EntryCategories:
|
||||
A same-named entry is kept, marked `"by": "name"`, only when no
|
||||
entry accepts the hash and its own hashes do not contradict it.
|
||||
"""
|
||||
names = {
|
||||
str(n).casefold()
|
||||
for n in (entry.get("name"), *(entry.get("aliases") or []))
|
||||
if n
|
||||
}
|
||||
names = entry_names(entry)
|
||||
declared = _declared_hashes(entry)
|
||||
by_name_index, by_hash_index = self._index_of(key, kind)
|
||||
|
||||
|
||||
@@ -378,7 +378,7 @@ def _match_key(entry: dict) -> tuple[str, str]:
|
||||
return dest.casefold(), str(entry.get("name", "")).casefold()
|
||||
|
||||
|
||||
def _names(entry: dict) -> set[str]:
|
||||
def entry_names(entry: dict) -> set[str]:
|
||||
"""The names an entry answers to: its own and the aliases it declares."""
|
||||
return {
|
||||
str(n).casefold()
|
||||
@@ -405,7 +405,7 @@ def by_name(truth_entry: dict, platform_entry: dict) -> bool:
|
||||
"""One of the truth's names, in the same directory, at the same size."""
|
||||
t_dest = _match_key(truth_entry)[0]
|
||||
theirs_dest, theirs = _match_key(platform_entry)
|
||||
if not theirs or theirs not in _names(truth_entry):
|
||||
if not theirs or theirs not in entry_names(truth_entry):
|
||||
return False
|
||||
# Two declared directories that differ name two files: the truth's
|
||||
# BeebFile/BIOS.rom is not Recalbox's np2kai/bios.rom.
|
||||
@@ -650,7 +650,7 @@ class _TruthPass:
|
||||
for candidate in (c for c in self._files_of(target_ids) if c.platform is not None):
|
||||
own = str(candidate.name).casefold()
|
||||
candidate.namesakes.extend(
|
||||
entry for entry in truth_files if own in _names(entry)
|
||||
entry for entry in truth_files if own in entry_names(entry)
|
||||
)
|
||||
|
||||
for t_index, truth_entry in enumerate(truth_files):
|
||||
|
||||
Reference in new issue
Block a user