diff --git a/wiki/adding-a-platform.md b/wiki/adding-a-platform.md index 6fbeae52c..6a241daa2 100644 --- a/wiki/adding-a-platform.md +++ b/wiki/adding-a-platform.md @@ -458,7 +458,10 @@ launchers: | `choices_from` | The feature or option file listing the values the option takes (es_features, a core `.opt`), never the record's evidence | | `source_ref` | `path:lines` in the repository and at the revision `source` pins, which the site links | -Batocera's generators are read with `ast`, RetroBat's C# generators as text. +Batocera's generators are read with `ast`: `scripts/scraper/batocera_configgen.py` +opens the configgen tree and `scripts/scraper/configgen_sites.py` reads each BIOS +path a generator names, both shared with KNULLI. RetroBat's C# generators are read as +text through `scripts/scraper/csharp_source.py`. ROCKNIX and EmuDeck launch from shell scripts and configs shipped with each package, so `scripts/scraper/shell_launchers.py` reads assignments, `for` loops, `ln -s` commands and `key = value` lines. A ROCKNIX package can ship diff --git a/wiki/adding-a-scraper.md b/wiki/adding-a-scraper.md index ceb99ab77..f7e2cb072 100644 --- a/wiki/adding-a-scraper.md +++ b/wiki/adding-a-scraper.md @@ -115,14 +115,19 @@ scraper sets `lists_files = False`. ### Helper functions -Two additional functions in `base_scraper.py`: +Other functions in `base_scraper.py`: - `fetch_github_latest_version(repo)` - fetches the latest release tag via GitHub API. - `fetch_github_latest_tag(repo, prefix)` - fetches the most recent tag matching an optional prefix. +- `github_json(url, failure)` - an api.github.com answer, parsed, with the + token `github_headers()` adds. A failed request raises `RuntimeError` (or the + `error` class given) with `failure` and the cause. +- `fetch_text(url)` - a platform file as text, `ConnectionError` when it cannot + be read. `fetch_bytes(url)` is the same read with retries on a rate limit. -Both send `GITHUB_TOKEN` when it is set and raise `RuntimeError` when the tag -cannot be read, rather than letting a scraper fall back to a branch. +The GitHub functions send `GITHUB_TOKEN` when it is set and raise `RuntimeError` +when the tag cannot be read, rather than letting a scraper fall back to a branch. ## Creating a BIOS scraper @@ -264,6 +269,11 @@ BaseTargetScraper write_output(data, path) # write YAML to disk ``` +The package also gives `fetch_text(url, headers)` (raises `RuntimeError`: a +target written from a failed request would lose its cores), `forge_headers(url)` +(the GitHub token on api.github.com URLs) and `target_cli(Scraper, description)`, +the `--dry-run` / `--output` command line every target scraper shares. + ### Output format `fetch_targets()` must return a dict with this structure: @@ -306,7 +316,7 @@ handle overrides. ### Module contract ```python -from scripts.scraper.targets import BaseTargetScraper +from . import BaseTargetScraper, target_cli PLATFORM_NAME = "myplatform" # the platform's registry key @@ -317,6 +327,14 @@ class Scraper(BaseTargetScraper): def fetch_targets(self) -> dict: # Fetch and parse target data ... + + +def main() -> None: + target_cli(Scraper, "Scrape MyPlatform per-device cores") + + +if __name__ == "__main__": + main() ``` Register the target scraper in `_registry.yml`: diff --git a/wiki/tools.md b/wiki/tools.md index a3b14327f..861e7a088 100644 --- a/wiki/tools.md +++ b/wiki/tools.md @@ -345,6 +345,11 @@ python scripts/export_native.py --platform batocera --fetch python scripts/export_native.py --all --fetch # into exports/, published on the site ``` +The command is a thin layer over `scripts/exporter/`: `native.py` runs one +platform's export and writes its report, `originals.py` reads and caches the +platforms' own files at their pinned revision, `landed.py` lists what the +written file changed, and each `*_exporter.py` renders one format. + `--fetch` downloads the platform's own file into `.cache/upstream-native/`, at the revision the platform YAML's `source:` names. Formats that carry code are patched from it rather than regenerated, and the export fails @@ -1693,8 +1698,8 @@ python -m scripts.scraper.mame_hash_scraper --devices --listxml .cache/dats/mame python -m scripts.scraper.mame_hash_scraper --devices --listxml .cache/dats/mame0289lx.zip ``` -Internal modules: `base_scraper.py` (abstract base with `_fetch_raw()` caching -and shared CLI), `dat_parser.py` (clrmamepro DAT format parser), +Internal modules: `base_scraper.py` (abstract base with `_fetch_raw()` caching, +the GitHub and text fetches, and the shared CLI), `dat_parser.py` (clrmamepro DAT format parser), `logiqx_parser.py` (Logiqx XML DAT parser, used by the dump catalogs), `mame_parser.py` (MAME C source BIOS root set parser), `fbneo_parser.py` (FBNeo C source BIOS set parser),