mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-25 19:08:51 -06:00
refactor: read md5 lists through parse_hash_list
The RetroDECK and Recalbox exporters compare md5 lists with resolve.reconcile.hash_values, and the RetroDECK scraper reads an entry's md5 with md5_field and parse_hash_list instead of its own copy. Recalbox's comparison no longer keeps an empty item: md5="a,,b" states a,b where it stated ,a,b. The RetroDECK scraper now splits a comma-joined value and refuses an md5 that is neither a string nor a list of strings, as the batocera-systems readers do. The ten cached component manifests write neither form, so retrodeck.yml is unchanged.
This commit is contained in:
1 parent
e19025231e
commit
f7c08a6ca3
5 files changed
+50
-20
No files matched your search
@@ -24,7 +24,9 @@ from model.profiles import load_emulator_profiles
|
||||
from model.safeparse import parse_untrusted_xml
|
||||
|
||||
from .base_exporter import BaseExporter
|
||||
from resolve.reconcile import NativeFile, NativeSystem, Report, by_destination, by_name
|
||||
from resolve.reconcile import (
|
||||
NativeFile, NativeSystem, Report, by_destination, by_name, hash_values,
|
||||
)
|
||||
|
||||
SOURCE_URL = (
|
||||
"https://gitlab.com/recalbox/recalbox/-/raw/master/board/recalbox/fsoverlay"
|
||||
@@ -81,7 +83,7 @@ def _stated(text: str) -> dict[str, str]:
|
||||
# Recalbox accepts any digest of the list (Bios.cpp:109-130): the
|
||||
# order is not content, and neogeo.zip's 24, reordered, were
|
||||
# written again.
|
||||
attrs["md5"] = ",".join(sorted({h.strip().lower() for h in attrs["md5"].split(",")}))
|
||||
attrs["md5"] = ",".join(sorted(hash_values(attrs, "md5")))
|
||||
return attrs
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import json
|
||||
from collections import OrderedDict
|
||||
|
||||
from .base_exporter import BaseExporter
|
||||
from resolve.reconcile import NativeFile, NativeSystem, Report
|
||||
from resolve.reconcile import NativeFile, NativeSystem, Report, hash_values
|
||||
|
||||
COMPONENTS_REPO = "RetroDECK/components"
|
||||
COMPONENTS_BRANCH = "main"
|
||||
@@ -33,11 +33,6 @@ def _systems_of(entry: dict) -> list[str]:
|
||||
return [str(declared)] if declared else []
|
||||
|
||||
|
||||
def _md5_set(value: object) -> set[str]:
|
||||
values = value if isinstance(value, list) else str(value or "").split(",")
|
||||
return {str(m).strip().lower() for m in values if str(m).strip()}
|
||||
|
||||
|
||||
def _paths_key(entry: dict) -> tuple[str, ...]:
|
||||
"""Where an entry says the file goes: no paths is the BIOS root."""
|
||||
paths = entry.get("paths")
|
||||
@@ -255,7 +250,7 @@ class Exporter(BaseExporter[str]):
|
||||
other_revision = (
|
||||
keys
|
||||
and seen_keys.get(keys[0], 0) > 1
|
||||
and not _md5_set(entry.get("md5")) & _md5_set(by_key[keys[0]].get("md5"))
|
||||
and not set(hash_values(entry, "md5")) & set(hash_values(by_key[keys[0]], "md5"))
|
||||
)
|
||||
if other_revision or not keys:
|
||||
merged.append(OrderedDict(entry))
|
||||
@@ -307,7 +302,7 @@ class Exporter(BaseExporter[str]):
|
||||
for field in ("md5", "sha256"):
|
||||
if field in cls.carries() and field not in own:
|
||||
combined.pop(field, None)
|
||||
if _md5_set(entry.get("md5")) == _md5_set(combined.get("md5")):
|
||||
if set(hash_values(entry, "md5")) == set(hash_values(combined, "md5")):
|
||||
# Their own spelling, and no key where they wrote none: an
|
||||
# equal empty set wrote "md5": null 39 times.
|
||||
if "md5" in entry:
|
||||
|
||||
@@ -39,6 +39,8 @@ if not __package__:
|
||||
importlib.import_module("scraper")
|
||||
__package__ = "scraper"
|
||||
|
||||
from core.hashing import parse_hash_list
|
||||
|
||||
from .base_scraper import (
|
||||
BaseScraper,
|
||||
BiosRequirement,
|
||||
@@ -48,6 +50,7 @@ from .base_scraper import (
|
||||
fetch_text,
|
||||
github_tree,
|
||||
json_object,
|
||||
md5_field,
|
||||
requirement_entry,
|
||||
)
|
||||
from .retrodeck_launchers import extract_launchers
|
||||
@@ -298,17 +301,18 @@ def _entry_folder(paths_raw: object) -> str | None:
|
||||
return resolved
|
||||
|
||||
|
||||
_MD5 = re.compile(r"[0-9a-f]{32}")
|
||||
|
||||
|
||||
def _entry_md5(md5_raw: object) -> str:
|
||||
"""MD5 handling: sanitize upstream errors."""
|
||||
if isinstance(md5_raw, list):
|
||||
parts = [str(m).strip().lower() for m in md5_raw if m]
|
||||
elif md5_raw:
|
||||
parts = [str(md5_raw).strip().lower()]
|
||||
else:
|
||||
parts = []
|
||||
# Keep only valid 32-char hex MD5 hashes
|
||||
valid = [p for p in parts if re.fullmatch(r"[0-9a-f]{32}", p)]
|
||||
return ",".join(valid)
|
||||
"""The valid md5 values of a manifest entry, comma-joined.
|
||||
|
||||
An entry writes one string or a list of strings, as a batocera-systems
|
||||
item does. A value that is not a 32-digit hex md5 is an upstream error
|
||||
and is left out.
|
||||
"""
|
||||
values, _listed = md5_field(md5_raw or None)
|
||||
return ",".join(m for m in parse_hash_list(values) if _MD5.fullmatch(m))
|
||||
|
||||
|
||||
def _entry_requirement(entry: dict, comp_key: str, default_system: object) -> BiosRequirement | None:
|
||||
|
||||
Reference in new issue
Block a user