mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-04-13 12:22:33 -05:00
Add many MAME/MESS BIOS entries (TRS-80 family, Bandai RX-78, Sega AI) and update docs/navigation counts (README, mkdocs). Remove empty supplemental file references from database.json and update generated timestamps and totals. Harden and refactor tooling: add MAX_RESPONSE_SIZE limited reader in base_scraper, make target scrapers an abstract base, narrow exception handling in the Batocera targets parser, and switch generate_pack.py and verify.py to use build_target_cores_cache (simplifies target config loading and error handling). verify.py also loads supplemental cross-reference names and accepts them through verify_platform. Update tests to import from updated modules (validation/truth). Misc: small bugfix for case-insensitive path conflict check.
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
"""Target scraper plugin discovery module.
|
|
|
|
Auto-detects *_targets_scraper.py files and exposes their scrapers.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
import pkgutil
|
|
from abc import ABC, abstractmethod
|
|
from pathlib import Path
|
|
|
|
|
|
class BaseTargetScraper(ABC):
|
|
"""Base class for target scrapers."""
|
|
|
|
def __init__(self, url: str = ""):
|
|
self.url = url
|
|
|
|
@abstractmethod
|
|
def fetch_targets(self) -> dict:
|
|
"""Fetch targets and their core lists. Returns dict matching target YAML format."""
|
|
...
|
|
|
|
def write_output(self, data: dict, output_path: str) -> None:
|
|
"""Write target data to YAML file."""
|
|
try:
|
|
import yaml
|
|
except ImportError:
|
|
raise ImportError("PyYAML required: pip install pyyaml")
|
|
with open(output_path, "w") as f:
|
|
yaml.dump(data, f, default_flow_style=False, sort_keys=False)
|
|
|
|
|
|
_scrapers: dict[str, type] = {}
|
|
|
|
|
|
def discover_target_scrapers() -> dict[str, type]:
|
|
"""Auto-discover all *_targets_scraper.py modules."""
|
|
if _scrapers:
|
|
return _scrapers
|
|
package_dir = Path(__file__).parent
|
|
for finder, name, ispkg in pkgutil.iter_modules([str(package_dir)]):
|
|
if not name.endswith("_targets_scraper"):
|
|
continue
|
|
module = importlib.import_module(f".{name}", package=__package__)
|
|
platform_name = getattr(module, "PLATFORM_NAME", None)
|
|
scraper_class = getattr(module, "Scraper", None)
|
|
if platform_name and scraper_class:
|
|
_scrapers[platform_name] = scraper_class
|
|
return _scrapers
|