mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-25 19:08:51 -06:00
refactor: one network layer for the scrapers
Each network job had several copies. One is kept per job and every caller uses it. - Source revision: model.sourcerevision (source_revision, required_revision, platform_revision) replaces BaseTargetScraper's pattern list, the exporter's _REVISION, the four launcher_revision copies and RetroBat's own YAML reader. It reads the union of the shapes: GitHub raw, blob and tree with or without a path after the revision, GitLab raw, blob, tree and archive, codeload tar.gz and zip. The target scrapers now answer for RetroDECK, NextUI, MinUI and MyMinUI, whose tree URLs end at the commit, and the exporter reads GitLab blob and tree and codeload zip. EmuDeck and RetroBat still require a 40-hex commit, and each launcher reader requires its own repository in the URL. - Latest release: fetch_github_latest_version, type-checked, is the only lookup. mame_hash_scraper, romset_dat_importer and the Lakka target scraper call it. romset_dat_importer's NoReleaseError is gone: a release without a tag raises RuntimeError. - Tree listing: github_tree and tree_entries refuse a truncated or unreadable listing. The libretro and core-info scrapers share core_info_files and fetch_info_file, with libretro's refusal of an empty listing. The core-info listing and the RetroDECK, ROCKNIX launcher and libretro listings were not checked for truncation before. - GET: fetch_bytes is the one request path. fetch_text, fetch_present (None on 404 only), github_json and download are built on it, so every read retries 429 and 5xx, caps the body and raises FetchError, a ConnectionError carrying the HTTP status. The target scrapers' own fetch_text raised RuntimeError: they now raise FetchError, and an optional Batocera board include is skipped on 404 only, not on any failure. The exporter's originals, MiSTer, RetroPie, redump and the buildbot index go through it too. - Headers: core.upstream.forge_headers is the one builder. The token goes to api.github.com and raw.githubusercontent.com, the host compared whole, as Bearer. A URL that only names api.github.com in its query got the scrapers' token before, and profile_sync sent its token to github.com, whose release downloads redirect to asset storage with the header. Scraper reads of raw files now carry the token. - Submodule commit: submodule_commit checks that the path is a submodule. Batocera's target scraper accepted any contents answer with a sha, a directory's tree sha included. - Download: download streams through a scratch file renamed into place, retries like fetch_bytes, can keep an existing file and returns the Content-Disposition. It replaces the _download of romset_dat_importer and game_dat_importer.
This commit is contained in:
1 parent
c25426f14c
commit
f61c2cb7d4
43 files changed
+791
-670
No files matched your search
@@ -17,8 +17,6 @@ import importlib
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
if not __package__:
|
||||
# Allow running directly: python scripts/scraper/coreinfo_scraper.py
|
||||
@@ -32,12 +30,13 @@ from .base_scraper import (
|
||||
BaseScraper,
|
||||
BiosRequirement,
|
||||
fetch_github_latest_version,
|
||||
github_json,
|
||||
fetch_text,
|
||||
github_tree,
|
||||
)
|
||||
|
||||
PLATFORM_NAME = "libretro_coreinfo"
|
||||
|
||||
GITHUB_API = "https://api.github.com/repos/libretro/libretro-core-info"
|
||||
CORE_INFO_REPO = "libretro/libretro-core-info"
|
||||
RAW_BASE = "https://raw.githubusercontent.com/libretro/libretro-core-info/master"
|
||||
|
||||
CORE_SYSTEM_MAP = {
|
||||
@@ -200,6 +199,29 @@ def _extract_md5_from_notes(info: dict) -> dict[str, str]:
|
||||
return md5_map
|
||||
|
||||
|
||||
def core_info_files() -> list[str]:
|
||||
"""Paths of every .info file in libretro-core-info, RuntimeError when the
|
||||
listing names none."""
|
||||
info_files = [
|
||||
entry["path"]
|
||||
for entry in github_tree(CORE_INFO_REPO, "master")
|
||||
if entry["path"].endswith("_libretro.info")
|
||||
]
|
||||
if not info_files:
|
||||
raise RuntimeError(f"no .info file in {CORE_INFO_REPO}")
|
||||
return info_files
|
||||
|
||||
|
||||
def fetch_info_file(filename: str) -> dict:
|
||||
"""A .info file of libretro-core-info, parsed.
|
||||
|
||||
A file the listing names and the fetch cannot read is an error: read
|
||||
as empty, the core dropped out of the result and --compare-db counted
|
||||
none of its firmware missing.
|
||||
"""
|
||||
return _parse_info_file(fetch_text(f"{RAW_BASE}/{filename}"))
|
||||
|
||||
|
||||
class Scraper(BaseScraper):
|
||||
"""Scraper for libretro-core-info firmware declarations."""
|
||||
|
||||
@@ -207,45 +229,14 @@ class Scraper(BaseScraper):
|
||||
super().__init__()
|
||||
self._info_files: dict[str, dict] | None = None
|
||||
|
||||
def _fetch_info_list(self) -> list[str]:
|
||||
"""Fetch list of all .info files from GitHub API."""
|
||||
# Use the tree API to get all files at once
|
||||
url = f"{GITHUB_API}/git/trees/master?recursive=1"
|
||||
data = github_json(
|
||||
url, "Failed to list core-info files", timeout=30, error=ConnectionError
|
||||
)
|
||||
return [
|
||||
item["path"]
|
||||
for item in data.get("tree", [])
|
||||
if item["path"].endswith("_libretro.info")
|
||||
]
|
||||
|
||||
def _fetch_info_file(self, filename: str) -> dict:
|
||||
"""Fetch and parse a single .info file.
|
||||
|
||||
A file the listing names and the fetch cannot read is an error: read
|
||||
as empty, the core dropped out of the result and --compare-db
|
||||
counted none of its firmware missing.
|
||||
"""
|
||||
url = f"{RAW_BASE}/{filename}"
|
||||
try:
|
||||
req = urllib.request.Request(
|
||||
url, headers={"User-Agent": "retrobios-scraper/1.0"}
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=15) as resp:
|
||||
content = resp.read().decode("utf-8")
|
||||
except (urllib.error.URLError, TimeoutError) as e:
|
||||
raise ConnectionError(f"Failed to fetch {url}: {e}") from e
|
||||
return _parse_info_file(content)
|
||||
|
||||
def fetch_requirements(self) -> list[BiosRequirement]:
|
||||
"""Fetch firmware requirements from all core .info files."""
|
||||
info_files = self._fetch_info_list()
|
||||
info_files = core_info_files()
|
||||
requirements = []
|
||||
seen = set()
|
||||
|
||||
for filename in info_files:
|
||||
info = self._fetch_info_file(filename)
|
||||
info = fetch_info_file(filename)
|
||||
firmware_list = _extract_firmware(info)
|
||||
|
||||
if not firmware_list:
|
||||
@@ -315,7 +306,7 @@ def main() -> None:
|
||||
|
||||
try:
|
||||
reqs = scraper.fetch_requirements()
|
||||
except ConnectionError as e:
|
||||
except (ConnectionError, RuntimeError) as e:
|
||||
print(f"Error: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
Reference in new issue
Block a user