mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-27 11:58:53 -06:00
refactor: group every scraper's systems one way
This commit is contained in:
1 parent
f245c210e0
commit
0548d3d823
5 files changed
+31
-58
No files matched your search
@@ -562,27 +562,9 @@ def _print_json(reqs: list[BiosRequirement]) -> None:
|
||||
|
||||
def _generic_config(reqs: list[BiosRequirement]) -> dict:
|
||||
"""Generic fallback: just systems from requirements."""
|
||||
config: dict = {"systems": {}}
|
||||
for req in reqs:
|
||||
sys_id = req.system
|
||||
if sys_id not in config["systems"]:
|
||||
sys_entry: dict = {"files": []}
|
||||
if req.native_id:
|
||||
sys_entry["native_id"] = req.native_id
|
||||
config["systems"][sys_id] = sys_entry
|
||||
entry = {
|
||||
"name": req.name,
|
||||
"destination": req.destination or req.name,
|
||||
"required": req.required,
|
||||
}
|
||||
if req.sha1:
|
||||
entry["sha1"] = req.sha1
|
||||
if req.md5:
|
||||
entry["md5"] = req.md5
|
||||
if req.zipped_file:
|
||||
entry["zipped_file"] = req.zipped_file
|
||||
config["systems"][sys_id]["files"].append(entry)
|
||||
return config
|
||||
return {"systems": systems_from_requirements(
|
||||
reqs, lambda req: {"native_id": req.native_id} if req.native_id else {},
|
||||
)}
|
||||
|
||||
|
||||
def _keep_existing(config: dict, output_path: Path) -> None:
|
||||
|
||||
@@ -31,6 +31,7 @@ from .base_scraper import (
|
||||
BiosRequirement,
|
||||
fetch_github_latest_version,
|
||||
fetch_text,
|
||||
_print_dry_run,
|
||||
github_tree,
|
||||
)
|
||||
|
||||
@@ -331,17 +332,7 @@ def main() -> None:
|
||||
print(f" {r.system}: {r.destination} {opt}")
|
||||
return
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
by_system = defaultdict(list)
|
||||
for r in reqs:
|
||||
by_system[r.system].append(r)
|
||||
|
||||
print(f"Total: {len(reqs)} unique firmware paths across {len(by_system)} systems")
|
||||
for sys_name, files in sorted(by_system.items()):
|
||||
req_count = sum(1 for f in files if f.required)
|
||||
opt_count = sum(1 for f in files if not f.required)
|
||||
print(f" {sys_name}: {req_count} required, {opt_count} optional")
|
||||
_print_dry_run(reqs)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -32,7 +32,7 @@ from .base_scraper import (
|
||||
fetch_branch_head,
|
||||
fetch_bytes,
|
||||
json_object,
|
||||
requirement_entry,
|
||||
systems_from_requirements,
|
||||
)
|
||||
|
||||
PLATFORM_NAME = "misterfpga"
|
||||
@@ -117,6 +117,14 @@ def system_of(path: str) -> str:
|
||||
return remainder.split("/", 1)[0]
|
||||
|
||||
|
||||
def _system_fields(req: BiosRequirement) -> dict:
|
||||
_, display, repo = SYSTEM_MAP.get(req.native_id or "", (req.system, req.system, ""))
|
||||
fields: dict = {"native_id": req.native_id, "name": display}
|
||||
if repo:
|
||||
fields["docs"] = f"https://github.com/MiSTer-devel/{repo}"
|
||||
return fields
|
||||
|
||||
|
||||
class Scraper(BaseScraper):
|
||||
"""Scraper for the MiSTer BiosDB database."""
|
||||
|
||||
@@ -174,26 +182,7 @@ class Scraper(BaseScraper):
|
||||
def generate_platform_yaml(self) -> dict:
|
||||
"""Build the MiSTer FPGA platform configuration."""
|
||||
data = json.loads(self._fetch_raw())
|
||||
systems: dict[str, dict] = {}
|
||||
|
||||
for req in self.fetch_requirements():
|
||||
_, display, repo = SYSTEM_MAP.get(
|
||||
req.native_id or "", (req.system, req.system, "")
|
||||
)
|
||||
entry = systems.setdefault(
|
||||
req.system,
|
||||
{
|
||||
"files": [],
|
||||
"native_id": req.native_id,
|
||||
"name": display,
|
||||
"docs": f"https://github.com/MiSTer-devel/{repo}" if repo else "",
|
||||
},
|
||||
)
|
||||
entry["files"].append(requirement_entry(req))
|
||||
|
||||
for entry in systems.values():
|
||||
if not entry["docs"]:
|
||||
del entry["docs"]
|
||||
systems = systems_from_requirements(self.fetch_requirements(), _system_fields)
|
||||
|
||||
# The BiosDB has no release: the date it was built is the only
|
||||
# version the list carries, and the manifest needs one.
|
||||
|
||||
@@ -51,7 +51,7 @@ from .base_scraper import (
|
||||
github_tree,
|
||||
json_object,
|
||||
md5_field,
|
||||
requirement_entry,
|
||||
systems_from_requirements,
|
||||
)
|
||||
from .retrodeck_launchers import extract_launchers
|
||||
|
||||
@@ -526,10 +526,7 @@ class Scraper(BaseScraper):
|
||||
}
|
||||
)
|
||||
|
||||
systems: dict[str, dict] = {}
|
||||
for req in reqs:
|
||||
sys_entry = systems.setdefault(req.system, {"files": []})
|
||||
sys_entry["files"].append(requirement_entry(req))
|
||||
systems = systems_from_requirements(reqs)
|
||||
|
||||
version = fetch_github_latest_version("RetroDECK/RetroDECK")
|
||||
# The ROM folders each libretro core runs for: its save folders.
|
||||
|
||||
@@ -112,6 +112,20 @@ class CompareWithConfig(unittest.TestCase):
|
||||
self.assertEqual([r.name for r in changes.removed], ["a.bin"])
|
||||
|
||||
|
||||
class GenericConfigWritesFullEntries(unittest.TestCase):
|
||||
def test_fallback_serializes_like_every_scraper(self):
|
||||
from scraper.base_scraper import _generic_config, requirement_entry
|
||||
|
||||
req = BiosRequirement(
|
||||
name="a.bin", system="sys", md5="ABCDEF", size=4, native_id="nat",
|
||||
)
|
||||
self.assertEqual(
|
||||
_generic_config([req]),
|
||||
{"systems": {"sys": {"files": [requirement_entry(req)], "native_id": "nat"}}},
|
||||
)
|
||||
self.assertEqual(requirement_entry(req)["md5"], "abcdef")
|
||||
|
||||
|
||||
class TestConnection(unittest.TestCase):
|
||||
def test_reachable_source_reports_true(self):
|
||||
self.assertTrue(_StubScraper([]).test_connection())
|
||||
|
||||
Reference in new issue
Block a user