mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-25 19:08:51 -06:00
fix: write retrodeck repeats to each component
duckstation and retroarch both list the PS1 BIOS with one md5, and the entry was filed under the first component read: an export correction reached duckstation's manifest and left retroarch's line as it was. component now lists every component that repeats an entry (a string for one), and the exporter writes the entry back to each. A repeat is the same name, path, hashes, native system and requirement: MAME's and FBNeo's cchip.zip, or two required labels, stay two entries, since an export corrects a line by its system and writes its requirement back. Rescraped at components fcd0d729: 73 entries list two components, 9 come back as their own entries. install/retrodeck.json is unchanged.
This commit is contained in:
1 parent
e8704a793e
commit
3779f07bb5
8 files changed
+433
-104
No files matched your search
@@ -19,6 +19,7 @@ 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 core.hashing import declared_hash_lists, lists_hashes
|
||||
from model.declarations import declared_components
|
||||
from model.profiles import lists_files
|
||||
from resolve.collisions import accepted_by_all, find_collisions
|
||||
from resolve.content import size_fits
|
||||
@@ -110,7 +111,7 @@ def doubled_destinations(
|
||||
readers.append(reader)
|
||||
declarations.append({
|
||||
"system": entry.get("native_system") or "",
|
||||
"component": entry.get("component") or "",
|
||||
"component": ", ".join(declared_components(entry.get("component"))),
|
||||
"name": entry.get("name", ""),
|
||||
"hashes": declared_hash_lists(entry),
|
||||
"file": local,
|
||||
|
||||
@@ -14,6 +14,7 @@ from collections import OrderedDict
|
||||
|
||||
from .base_exporter import BaseExporter
|
||||
from core.hashing import parse_hash_list
|
||||
from model.declarations import declared_components
|
||||
from resolve.reconcile import NativeFile, NativeSystem, Report
|
||||
|
||||
COMPONENTS_REPO = "RetroDECK/components"
|
||||
@@ -78,6 +79,12 @@ def _pick(
|
||||
return free[0] if free else None
|
||||
|
||||
|
||||
def _components(fe: NativeFile) -> list[str]:
|
||||
"""The manifests an entry is written back to: every component that
|
||||
declares it, an addition's own once placed."""
|
||||
return declared_components(fe.native("component", ""))
|
||||
|
||||
|
||||
class Exporter(BaseExporter[str]):
|
||||
"""Write RetroDECK's component manifests, corrected."""
|
||||
|
||||
@@ -101,7 +108,7 @@ class Exporter(BaseExporter[str]):
|
||||
|
||||
def writable(self, fe: NativeFile, require: str = "") -> bool:
|
||||
"""An addition lands only in a manifest it can be placed in."""
|
||||
if fe.platform is None and not fe.native("component", ""):
|
||||
if fe.platform is None and not _components(fe):
|
||||
return False
|
||||
return super().writable(fe, require)
|
||||
|
||||
@@ -141,9 +148,10 @@ class Exporter(BaseExporter[str]):
|
||||
"""
|
||||
for system in systems.values():
|
||||
components = {
|
||||
str(fe.native("component", ""))
|
||||
component
|
||||
for fe in system.files
|
||||
if fe.platform is not None and fe.native("component", "")
|
||||
if fe.platform is not None
|
||||
for component in _components(fe)
|
||||
}
|
||||
if len(components) != 1:
|
||||
continue
|
||||
@@ -161,13 +169,10 @@ class Exporter(BaseExporter[str]):
|
||||
|
||||
def components(self, systems: dict[str, NativeSystem]) -> list[str]:
|
||||
"""Components the corrected data touches."""
|
||||
found: set[str] = set()
|
||||
for system in systems.values():
|
||||
for fe in system.files:
|
||||
component = str(fe.native("component", ""))
|
||||
if component:
|
||||
found.add(component)
|
||||
return sorted(found)
|
||||
return sorted(
|
||||
{component for system in systems.values() for fe in system.files
|
||||
for component in _components(fe)}
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _entry(fe: NativeFile) -> OrderedDict:
|
||||
@@ -204,11 +209,12 @@ class Exporter(BaseExporter[str]):
|
||||
def _by_component(
|
||||
self, systems: dict[str, NativeSystem]
|
||||
) -> dict[str, list[NativeFile]]:
|
||||
"""Each component's entries. An entry several manifests repeat with
|
||||
the same hashes and requirement is written back to each of them."""
|
||||
grouped: dict[str, list[NativeFile]] = {}
|
||||
for system in systems.values():
|
||||
for fe in system.files:
|
||||
component = str(fe.native("component", ""))
|
||||
if component:
|
||||
for component in _components(fe):
|
||||
grouped.setdefault(component, []).append(fe)
|
||||
return grouped
|
||||
|
||||
|
||||
@@ -22,6 +22,17 @@ def declared_slot(entry: dict, prefix: str = "") -> str:
|
||||
return slot
|
||||
|
||||
|
||||
def declared_components(value: object) -> list[str]:
|
||||
"""RetroDECK: the components whose manifests declare one entry.
|
||||
|
||||
One is written as a string, several as a list: duckstation's and
|
||||
retroarch's manifests both list scph5501.bin with one md5.
|
||||
"""
|
||||
if isinstance(value, list):
|
||||
return [str(item) for item in value if item]
|
||||
return [str(value)] if value else []
|
||||
|
||||
|
||||
def platform_declarations(
|
||||
config: dict, db: dict, *, enrich: bool = True
|
||||
) -> dict[str, list[tuple[int | None, str]]]:
|
||||
|
||||
@@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, TypedDict
|
||||
from core.paths import BIOS_DIR, EMULATORS_DIR, declared_destination
|
||||
from core.ziptools import build_zip_contents_index
|
||||
from model.alternatives import core_file_spares
|
||||
from model.declarations import OUTER_ROOTS, platform_declarations
|
||||
from model.declarations import OUTER_ROOTS, declared_components, platform_declarations
|
||||
from model.profiles import lists_files, load_emulator_profiles
|
||||
from model.systems import select_systems
|
||||
from packs import slots
|
||||
@@ -252,7 +252,9 @@ def _expects(entry: dict) -> str:
|
||||
|
||||
def _side(sys_id: str, entry: dict) -> str:
|
||||
"""One declaration named by the platform's own system, or its component."""
|
||||
native = entry.get("native_system") or entry.get("component")
|
||||
native = entry.get("native_system") or ", ".join(
|
||||
declared_components(entry.get("component"))
|
||||
)
|
||||
return f"{sys_id} ({native})" if native else sys_id
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ if not __package__:
|
||||
__package__ = "scraper"
|
||||
|
||||
from core.hashing import parse_hash_list
|
||||
from model.declarations import declared_components
|
||||
|
||||
from .base_scraper import (
|
||||
BaseScraper,
|
||||
@@ -375,7 +376,10 @@ def _repeat_key(req: BiosRequirement) -> tuple[object, ...]:
|
||||
their hashes are two verdicts on the file (decocass.zip for MAME and for
|
||||
FBNeo, the three 64DD_IPL.bin revisions), and two spellings are two files
|
||||
on its Linux filesystem (MSX.ROM and MSX.rom). Only the same name at the
|
||||
same place with the same hashes repeats a declaration.
|
||||
same place with the same hashes, under the same native system and with
|
||||
the same requirement, repeats a declaration: its components are then
|
||||
one entry's list (_add_component), and what an export writes back to
|
||||
one component's line it writes to the others unchanged.
|
||||
"""
|
||||
return (
|
||||
req.system,
|
||||
@@ -383,9 +387,25 @@ def _repeat_key(req: BiosRequirement) -> tuple[object, ...]:
|
||||
req.destination,
|
||||
frozenset(parse_hash_list(req.md5)),
|
||||
req.sha256 or "",
|
||||
req.native_id,
|
||||
req.required,
|
||||
req.native.get("required_label", ""),
|
||||
)
|
||||
|
||||
|
||||
def _add_component(req: BiosRequirement, component: str) -> None:
|
||||
"""List one more component whose manifest repeats *req*.
|
||||
|
||||
One component stays a string, as the platform file wrote it before
|
||||
several could declare one entry: the PS1 BIOS that duckstation and
|
||||
retroarch both list is one entry naming both.
|
||||
"""
|
||||
listed = declared_components(req.native.get("component"))
|
||||
if component not in listed:
|
||||
listed.append(component)
|
||||
req.native["component"] = listed[0] if len(listed) == 1 else listed
|
||||
|
||||
|
||||
class Scraper(BaseScraper):
|
||||
"""RetroDECK BIOS scraper from component manifests."""
|
||||
|
||||
@@ -482,7 +502,7 @@ class Scraper(BaseScraper):
|
||||
manifests = self._get_manifests()
|
||||
|
||||
requirements: list[BiosRequirement] = []
|
||||
seen: set[tuple[object, ...]] = set()
|
||||
seen: dict[tuple[object, ...], BiosRequirement] = {}
|
||||
|
||||
for _comp_name, manifest in manifests:
|
||||
for comp_key, comp_val in manifest.items():
|
||||
@@ -499,8 +519,9 @@ class Scraper(BaseScraper):
|
||||
continue
|
||||
key = _repeat_key(req)
|
||||
if key in seen:
|
||||
_add_component(seen[key], comp_key)
|
||||
continue
|
||||
seen.add(key)
|
||||
seen[key] = req
|
||||
requirements.append(req)
|
||||
|
||||
return requirements
|
||||
|
||||
Reference in new issue
Block a user