mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-27 20:08:51 -06:00
refactor: read declared hashes with one helper
core.hashing.declared_hash_lists gives an entry's declared values per field in the order written, and declared_hashes builds its sets on it. The gap page, the doubled-destination report and the file lookup used their own copies of that reader. The wanted page keeps its filters on top of it. sitegen.lookup.hash_pairs replaces sorted_hash_values for the lookup, the data exports and the structured data. The one-field aliases parse_md5_list and reconcile.hash_values are gone, and model.profiles reads HASH_FIELDS instead of a fourth tuple.
This commit is contained in:
1 parent
ea68e85c06
commit
02969dda06
30 files changed
+176
-195
No files matched your search
@@ -18,8 +18,8 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
from resolve.archives import contents_members, holds_required_members
|
||||
from resolve.standalone import platform_layouts, standalone_set
|
||||
from resolve.cores import resolve_platform_cores
|
||||
from resolve.reconcile import HASH_FIELDS, hash_values
|
||||
from core.hashing import lists_hashes
|
||||
from core.hashing import declared_hash_lists, lists_hashes
|
||||
from model.profiles import lists_files
|
||||
from resolve.collisions import accepted_by_all, find_collisions
|
||||
from resolve.content import size_fits
|
||||
from resolve.validation import opens_by_name, outside_gap_scope
|
||||
@@ -58,11 +58,6 @@ def _reads(entry: dict, by_name: bool, local: str, db: dict) -> bool:
|
||||
return by_name and _size_fits(entry, local)
|
||||
|
||||
|
||||
def _hashes(entry: dict) -> dict[str, list[str]]:
|
||||
found = {f: hash_values(entry, f) for f in HASH_FIELDS}
|
||||
return {f: values for f, values in found.items() if values}
|
||||
|
||||
|
||||
def doubled_destinations(
|
||||
scraped: dict | None,
|
||||
profiles: dict[str, dict],
|
||||
@@ -86,7 +81,7 @@ def doubled_destinations(
|
||||
named: dict[str, list[tuple[str, dict, dict, bool]]] = {}
|
||||
for key in sorted(resolve_platform_cores(scraped, profiles)):
|
||||
profile = profiles[key]
|
||||
if profile.get("type") in ("launcher", "alias"):
|
||||
if not lists_files(profile):
|
||||
continue
|
||||
for layout, is_standalone in platform_layouts(key, profile, standalone):
|
||||
for entry in layout.get("files") or []:
|
||||
@@ -117,7 +112,7 @@ def doubled_destinations(
|
||||
"system": entry.get("native_system") or "",
|
||||
"component": entry.get("component") or "",
|
||||
"name": entry.get("name", ""),
|
||||
"hashes": _hashes(entry),
|
||||
"hashes": declared_hash_lists(entry),
|
||||
"file": local,
|
||||
"readers": readers,
|
||||
})
|
||||
|
||||
@@ -18,7 +18,8 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
from scraper.emudeck_scraper import FUNCTION_HASH_MAP, RE_FUNC, RE_LOCAL_HASHES
|
||||
|
||||
from .base_exporter import BaseExporter
|
||||
from resolve.reconcile import NativeFile, NativeSystem, Report, hash_values
|
||||
from core.hashing import parse_hash_list
|
||||
from resolve.reconcile import NativeFile, NativeSystem, Report
|
||||
|
||||
SOURCE_URL = (
|
||||
"https://raw.githubusercontent.com/dragoonDorise/EmuDeck/main"
|
||||
@@ -80,7 +81,7 @@ class Exporter(BaseExporter[str]):
|
||||
adds nothing, and the truth's extra accepted revisions are not
|
||||
appended: either would grow an array other consumers read too.
|
||||
"""
|
||||
theirs = hash_values(fe.platform or {}, "md5")
|
||||
theirs = parse_hash_list((fe.platform or {}).get("md5"))
|
||||
if not theirs:
|
||||
return []
|
||||
if "md5" in fe.corrections:
|
||||
@@ -124,7 +125,7 @@ class Exporter(BaseExporter[str]):
|
||||
if system.native_id == system_id
|
||||
for fe in system.files
|
||||
if "md5" in fe.corrections
|
||||
for value in hash_values(fe.platform or {}, "md5")
|
||||
for value in parse_hash_list((fe.platform or {}).get("md5"))
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -6,7 +6,8 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from .base_exporter import BaseExporter
|
||||
from resolve.reconcile import HASH_FIELDS, NativeFile, hash_values, single_size
|
||||
from core.hashing import parse_hash_list
|
||||
from resolve.reconcile import HASH_FIELDS, NativeFile, single_size
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -75,7 +76,7 @@ def _change(
|
||||
|
||||
|
||||
def _platform_value(entry: NativeFile, field_name: str) -> str | list[str]:
|
||||
values = hash_values(entry.platform or {}, field_name)
|
||||
values = parse_hash_list((entry.platform or {}).get(field_name))
|
||||
if (entry.platform or {}).get(f"{field_name}_list"):
|
||||
return values
|
||||
return ",".join(values)
|
||||
@@ -157,7 +158,7 @@ def landed_changes(exporter: BaseExporter, systems: dict) -> LandedChanges:
|
||||
listed is not None
|
||||
and field_name not in entry.corrections
|
||||
and field_name not in entry.filled
|
||||
and listed != hash_values(entry.platform, field_name)
|
||||
and listed != parse_hash_list(entry.platform.get(field_name))
|
||||
and exporter.states(entry, field_name)
|
||||
):
|
||||
records.append(_change(
|
||||
@@ -196,7 +197,7 @@ def landed_changes(exporter: BaseExporter, systems: dict) -> LandedChanges:
|
||||
_change("hash_cleared", entry, field_name,
|
||||
_platform_value(entry, field_name), None)
|
||||
for field_name in HASH_FIELDS
|
||||
if hash_values(entry.platform, field_name)
|
||||
if parse_hash_list(entry.platform.get(field_name))
|
||||
and not entry.hashes(field_name)
|
||||
and exporter.clears(entry, field_name)
|
||||
)
|
||||
|
||||
@@ -21,11 +21,12 @@ from xml.sax.saxutils import quoteattr
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from model.profiles import load_emulator_profiles
|
||||
from core.hashing import parse_hash_list
|
||||
from model.safeparse import parse_untrusted_xml
|
||||
|
||||
from .base_exporter import BaseExporter
|
||||
from resolve.reconcile import (
|
||||
NativeFile, NativeSystem, Report, by_destination, by_name, hash_values,
|
||||
NativeFile, NativeSystem, Report, by_destination, by_name,
|
||||
)
|
||||
|
||||
SOURCE_URL = (
|
||||
@@ -83,7 +84,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(hash_values(attrs, "md5")))
|
||||
attrs["md5"] = ",".join(sorted(parse_hash_list(attrs.get("md5"))))
|
||||
return attrs
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ import json
|
||||
from collections import OrderedDict
|
||||
|
||||
from .base_exporter import BaseExporter
|
||||
from resolve.reconcile import NativeFile, NativeSystem, Report, hash_values
|
||||
from core.hashing import parse_hash_list
|
||||
from resolve.reconcile import NativeFile, NativeSystem, Report
|
||||
|
||||
COMPONENTS_REPO = "RetroDECK/components"
|
||||
COMPONENTS_BRANCH = "main"
|
||||
@@ -250,7 +251,7 @@ class Exporter(BaseExporter[str]):
|
||||
other_revision = (
|
||||
keys
|
||||
and seen_keys.get(keys[0], 0) > 1
|
||||
and not set(hash_values(entry, "md5")) & set(hash_values(by_key[keys[0]], "md5"))
|
||||
and not set(parse_hash_list(entry.get("md5"))) & set(parse_hash_list(by_key[keys[0]].get("md5")))
|
||||
)
|
||||
if other_revision or not keys:
|
||||
merged.append(OrderedDict(entry))
|
||||
@@ -302,7 +303,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 set(hash_values(entry, "md5")) == set(hash_values(combined, "md5")):
|
||||
if set(parse_hash_list(entry.get("md5"))) == set(parse_hash_list(combined.get("md5"))):
|
||||
# Their own spelling, and no key where they wrote none: an
|
||||
# equal empty set wrote "md5": null 39 times.
|
||||
if "md5" in entry:
|
||||
|
||||
@@ -18,7 +18,8 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
from scraper.romm_scraper import SLUG_MAP
|
||||
|
||||
from .base_exporter import BaseExporter
|
||||
from resolve.reconcile import NativeFile, NativeSystem, Report, hash_values
|
||||
from core.hashing import parse_hash_list
|
||||
from resolve.reconcile import NativeFile, NativeSystem, Report
|
||||
|
||||
SOURCE_URL = (
|
||||
"https://raw.githubusercontent.com/rommapp/romm/master/backend/models"
|
||||
@@ -161,7 +162,7 @@ class Exporter(BaseExporter[str]):
|
||||
output[key] = OrderedDict(
|
||||
(field, value)
|
||||
for field, name in _FIELDS
|
||||
if (value := ",".join(hash_values(fe.platform, name))
|
||||
if (value := ",".join(parse_hash_list(fe.platform.get(name)))
|
||||
if name != "size" else str(fe.platform["size"]))
|
||||
)
|
||||
continue
|
||||
@@ -185,7 +186,7 @@ class Exporter(BaseExporter[str]):
|
||||
def _contradicted(fe: NativeFile, name: str) -> bool:
|
||||
"""A hash the platform states and the truth, taking the entry over,
|
||||
does not keep."""
|
||||
return bool(hash_values(fe.platform or {}, name)) and not fe.hashes(name)
|
||||
return bool(parse_hash_list((fe.platform or {}).get(name))) and not fe.hashes(name)
|
||||
|
||||
def states(self, fe: NativeFile, field_name: str) -> bool:
|
||||
"""An entry left whole carries none of the truth's values."""
|
||||
|
||||
Reference in new issue
Block a user