refactor: split this round's fixes into small helpers

This commit is contained in:
Abdessamad Derraz committed 2026-10-06 11:16:06 +02:00
1 parent 6748982d94
commit eb8c7e5267
15 files changed
+218 -157

No files matched your search

+9 -4
View File
@@ -38,6 +38,10 @@ 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}
@dataclass
class NativeFile:
"""One file as the platform will read it, after correction."""
@@ -67,8 +71,7 @@ class NativeFile:
truth's crc32 beside Batocera's md5 for bios7.bin is one dump, and
reading it as a contradiction emptied the md5 the frontend checks.
"""
truth = {f: set(_hash_values(self.truth or {}, f)) for f in HASH_FIELDS}
plat = {f: set(_hash_values(self.platform or {}, f)) for f in HASH_FIELDS}
truth, plat = _field_sets(self.truth), _field_sets(self.platform)
if not any(truth.values()):
return "platform"
if not any(plat.values()):
@@ -76,10 +79,12 @@ class NativeFile:
shared = [f for f in HASH_FIELDS if truth[f] and plat[f]]
if any(truth[f] & plat[f] for f in shared):
return "both"
return "truth" if shared or self._sizes_differ() else "both"
def _sizes_differ(self) -> bool:
t_size = (self.truth or {}).get("size")
p_size = (self.platform or {}).get("size")
sizes_differ = isinstance(t_size, int) and isinstance(p_size, int) and t_size != p_size
return "truth" if shared or sizes_differ else "both"
return isinstance(t_size, int) and isinstance(p_size, int) and t_size != p_size
def hashes(self, field_name: str) -> list[str]:
"""Accepted values for a hash, truth first when it has an opinion.
+10 -3
View File
@@ -95,6 +95,14 @@ class Exporter(BaseExporter):
return False
return super().states(fe, field_name)
def _expected_md5s(
self, systems: dict[str, NativeSystem], name: str, system_id: str
) -> list[str]:
"""What a check must now hold; a refused rewrite keeps EmuDeck's own array."""
if name in getattr(self, "_withdrawn", {}):
return []
return self._md5s(systems, system_id)
def _refused_systems(self) -> set[str]:
withdrawn = getattr(self, "_withdrawn", {})
return {FUNCTION_HASH_MAP[name] for name in withdrawn if name in FUNCTION_HASH_MAP}
@@ -200,9 +208,8 @@ class Exporter(BaseExporter):
if name not in defined:
issues.append(f"check absent from the output: {name}")
continue
md5s = self._md5s(systems, system_id)
if not md5s or name in getattr(self, "_withdrawn", {}):
# A refused rewrite keeps EmuDeck's own array, by design.
md5s = self._expected_md5s(systems, name, system_id)
if not md5s:
continue
body = next(
content[start:end]
+1 -1
View File
@@ -64,7 +64,7 @@ class Exporter(BaseExporter):
"""
return native_id in SLUG_MAP
def writable(self, fe: NativeFile, require: str = "") -> bool:
def writable(self, fe: NativeFile, require: str = "") -> bool: # noqa: ARG002
"""What RomM already ships stays; the conditions gate additions.
An entry of theirs that could never verify is still theirs, and the