mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-25 10:58:52 -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
@@ -31,8 +31,6 @@ import importlib
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
if not __package__:
|
||||
@@ -45,9 +43,10 @@ from .base_scraper import (
|
||||
BaseScraper,
|
||||
BiosRequirement,
|
||||
fetch_branch_head,
|
||||
fetch_bytes,
|
||||
fetch_github_latest_version,
|
||||
github_headers,
|
||||
fetch_present,
|
||||
fetch_text,
|
||||
github_tree,
|
||||
json_object,
|
||||
requirement_entry,
|
||||
)
|
||||
@@ -56,7 +55,6 @@ from .retrodeck_launchers import extract_launchers
|
||||
PLATFORM_NAME = "retrodeck"
|
||||
COMPONENTS_REPO = "RetroDECK/components"
|
||||
COMPONENTS_BRANCH = "main"
|
||||
COMPONENTS_API_URL = "https://api.github.com/repos/" + COMPONENTS_REPO + "/git/trees/{rev}"
|
||||
RAW_BASE = "https://raw.githubusercontent.com/" + COMPONENTS_REPO + "/{rev}"
|
||||
SKIP_DIRS = {"archive_later", "archive_old", "automation-tools", ".github"}
|
||||
|
||||
@@ -412,31 +410,10 @@ class Scraper(BaseScraper):
|
||||
|
||||
def _fetch_remote_manifests(self) -> list[tuple[str, dict]]:
|
||||
"""Fetch component manifests via GitHub API."""
|
||||
from core.github import github_token
|
||||
|
||||
token = github_token()
|
||||
headers = {"User-Agent": "retrobios-scraper/1.0"}
|
||||
if token:
|
||||
headers["Authorization"] = f"token {token}"
|
||||
|
||||
try:
|
||||
req = urllib.request.Request(
|
||||
COMPONENTS_API_URL.format(rev=self.revision), headers=headers
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||
tree = json.loads(resp.read().decode())
|
||||
except (urllib.error.HTTPError, urllib.error.URLError) as e:
|
||||
raise ConnectionError(f"Failed to fetch component tree: {e}") from e
|
||||
|
||||
if tree.get("truncated"):
|
||||
# A partial tree lists some components: writing the YAML from it
|
||||
# drops the others' systems without a word.
|
||||
raise ConnectionError("GitHub tree response truncated")
|
||||
|
||||
component_dirs = [
|
||||
item["path"]
|
||||
for item in tree.get("tree", [])
|
||||
if item["type"] == "tree" and item["path"] not in SKIP_DIRS
|
||||
for item in github_tree(COMPONENTS_REPO, self.revision, recursive=False)
|
||||
if item.get("type") == "tree" and item["path"] not in SKIP_DIRS
|
||||
]
|
||||
|
||||
manifests: list[tuple[str, dict]] = []
|
||||
@@ -446,17 +423,12 @@ class Scraper(BaseScraper):
|
||||
# Only a 404 says the component has no manifest. A 429, a 503 or
|
||||
# a dropped connection is no answer: skipping it wrote
|
||||
# retrodeck.yml without that component's systems, exit code 0.
|
||||
text = fetch_present(url)
|
||||
if text is None:
|
||||
print(" no manifest", file=sys.stderr)
|
||||
continue
|
||||
try:
|
||||
req = urllib.request.Request(url, headers=headers)
|
||||
with urllib.request.urlopen(req, timeout=15) as resp:
|
||||
data = json.loads(resp.read().decode())
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code == 404:
|
||||
print(" no manifest", file=sys.stderr)
|
||||
continue
|
||||
raise ConnectionError(f"{url}: HTTP {e.code}") from e
|
||||
except urllib.error.URLError as e:
|
||||
raise ConnectionError(f"{url}: {e.reason}") from e
|
||||
data = json.loads(text)
|
||||
except json.JSONDecodeError as e:
|
||||
raise ValueError(f"{url}: not JSON: {e}") from e
|
||||
manifests.append((comp, data))
|
||||
@@ -492,17 +464,7 @@ class Scraper(BaseScraper):
|
||||
local = Path(self.manifests_dir) / path
|
||||
text = local.read_text(encoding="utf-8") if local.is_file() else None
|
||||
else:
|
||||
url = f"{RAW_BASE.format(rev=self.revision)}/{path}"
|
||||
try:
|
||||
req = urllib.request.Request(url, headers=github_headers())
|
||||
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||
text = resp.read().decode("utf-8")
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code != 404:
|
||||
raise ConnectionError(f"{url}: HTTP {e.code}") from e
|
||||
text = None
|
||||
except urllib.error.URLError as e:
|
||||
raise ConnectionError(f"{url}: {e.reason}") from e
|
||||
text = fetch_present(f"{RAW_BASE.format(rev=self.revision)}/{path}")
|
||||
self._files[path] = text
|
||||
return text
|
||||
|
||||
@@ -544,7 +506,7 @@ class Scraper(BaseScraper):
|
||||
(automation-tools/alchemist/desired_versions.sh, ES_DE_DESIRED_VERSION).
|
||||
"""
|
||||
tag = fetch_github_latest_version(ES_DE_REPO)
|
||||
text = fetch_bytes(ES_DE_SYSTEMS_URL.format(rev=tag)).decode("utf-8")
|
||||
text = fetch_text(ES_DE_SYSTEMS_URL.format(rev=tag))
|
||||
return es_systems_libretro_systems(text)
|
||||
|
||||
def generate_platform_yaml(self) -> dict:
|
||||
|
||||
Reference in new issue
Block a user