mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-28 12:28: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
@@ -15,8 +15,6 @@ import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from collections import Counter
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
@@ -32,7 +30,7 @@ from model.safeparse import yaml_load
|
||||
|
||||
from core import upstream
|
||||
|
||||
from .base_scraper import github_headers
|
||||
from .base_scraper import download, fetch_github_latest_version
|
||||
from ._hash_merge import (
|
||||
_build_contents,
|
||||
_build_source_ref,
|
||||
@@ -72,7 +70,8 @@ _FLOPPY_SOURCE = "src/devices/imagedev/floppy.cpp"
|
||||
# Where a device set goes when only machines no seed places load it: MAME
|
||||
# starts such a machine from its set name, as an arcade folder passes one.
|
||||
UNPLACED_SYSTEM = "arcade"
|
||||
_REPO_URL = "https://github.com/mamedev/mame.git"
|
||||
MAME_REPO = "mamedev/mame"
|
||||
_REPO_URL = f"https://github.com/{MAME_REPO}.git"
|
||||
_STALE_HOURS = 24
|
||||
|
||||
|
||||
@@ -158,26 +157,12 @@ def _sparse_clone(tag: str) -> None:
|
||||
|
||||
|
||||
def _get_version() -> str:
|
||||
"""The latest MAME release version, such as 0.289."""
|
||||
return _parse_version_tag(_get_release_tag())
|
||||
|
||||
|
||||
def _get_release_tag() -> str:
|
||||
"""The latest MAME release tag, from the GitHub API.
|
||||
"""The latest MAME release version, such as 0.289.
|
||||
|
||||
version.cpp is generated at build time, not in the repo. A failed lookup
|
||||
raises: "unknown" was cached for a day and written as core_version.
|
||||
"""
|
||||
url = "https://api.github.com/repos/mamedev/mame/releases/latest"
|
||||
try:
|
||||
req = urllib.request.Request(url, headers=github_headers())
|
||||
with urllib.request.urlopen(req, timeout=10) as resp:
|
||||
tag = json.loads(resp.read()).get("tag_name", "")
|
||||
except (urllib.error.URLError, json.JSONDecodeError, OSError) as exc:
|
||||
raise RuntimeError(f"cannot read the MAME release from {url}: {exc}") from exc
|
||||
if not tag:
|
||||
raise RuntimeError(f"no tag_name in {url}")
|
||||
return tag
|
||||
return _parse_version_tag(fetch_github_latest_version(MAME_REPO))
|
||||
|
||||
|
||||
def _parse_version_tag(tag: str) -> str:
|
||||
@@ -313,7 +298,7 @@ def _fetch_hashes(force: bool) -> dict[str, Any]:
|
||||
return cache
|
||||
|
||||
try:
|
||||
tag = _get_release_tag()
|
||||
tag = fetch_github_latest_version(MAME_REPO)
|
||||
_sparse_clone(tag)
|
||||
bios_sets = parse_mame_source_tree(str(_CLONE_DIR))
|
||||
version = _parse_version_tag(tag)
|
||||
@@ -406,12 +391,12 @@ def fetch_release_listxml(version: str) -> Path:
|
||||
|
||||
0.289 is the tag mame0289 and the asset mame0289lx.zip.
|
||||
"""
|
||||
from .romset_dat_importer import MAME_LISTXML_URL, _download
|
||||
from .romset_dat_importer import MAME_LISTXML_URL
|
||||
|
||||
tag = "mame" + version.replace(".", "")
|
||||
return _download(
|
||||
MAME_LISTXML_URL.format(tag=tag), REPO_ROOT / ".cache" / "dats" / f"{tag}lx.zip"
|
||||
)
|
||||
listxml = REPO_ROOT / ".cache" / "dats" / f"{tag}lx.zip"
|
||||
download(MAME_LISTXML_URL.format(tag=tag), listxml, skip_existing=True)
|
||||
return listxml
|
||||
|
||||
|
||||
def release_profile(
|
||||
|
||||
Reference in new issue
Block a user