mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 10:07:48 -06:00
fix: target scrapers exit on errors like scrapers
This commit is contained in:
1 parent
83fdc97edd
commit
79c3c02885
4 files changed
+26
-42
No files matched your search
@@ -518,7 +518,7 @@ def _quoted_str(dumper: yaml.SafeDumper, data: str) -> yaml.ScalarNode:
|
||||
_PlatformDumper.add_representer(str, _quoted_str)
|
||||
|
||||
|
||||
def _exit_on_scrape_error(error: Exception) -> NoReturn:
|
||||
def exit_on_scrape_error(error: Exception) -> NoReturn:
|
||||
"""Print what failed and what to try, then exit 1 without a traceback."""
|
||||
print(f"Error: {error}", file=sys.stderr)
|
||||
refused = re.search(r"\b(403|429)\b|rate limit", str(error), re.I)
|
||||
@@ -617,13 +617,13 @@ def _write_output(
|
||||
try:
|
||||
config = generate()
|
||||
except (OSError, ValueError, RuntimeError) as e:
|
||||
_exit_on_scrape_error(e)
|
||||
exit_on_scrape_error(e)
|
||||
else:
|
||||
config = _generic_config(reqs)
|
||||
if scraper.lists_files and not any(
|
||||
(system or {}).get("files") for system in (config.get("systems") or {}).values()
|
||||
):
|
||||
_exit_on_scrape_error(RuntimeError(
|
||||
exit_on_scrape_error(RuntimeError(
|
||||
f"{scraper_class.__module__}: the generated platform lists no file"
|
||||
))
|
||||
output_path = Path(output)
|
||||
@@ -658,11 +658,11 @@ def scraper_cli(
|
||||
scraper = scraper_class(revision=args.revision) if takes_revision else scraper_class()
|
||||
reqs = scraper.fetch_requirements()
|
||||
except (OSError, ValueError, RuntimeError) as e:
|
||||
_exit_on_scrape_error(e)
|
||||
exit_on_scrape_error(e)
|
||||
if scraper.lists_files and not reqs:
|
||||
# Written, an empty read became a platform with no system that
|
||||
# verify and the pack count 0/0 and call consistent.
|
||||
_exit_on_scrape_error(RuntimeError(
|
||||
exit_on_scrape_error(RuntimeError(
|
||||
f"{scraper_class.__module__}: upstream returned no BIOS entry"
|
||||
))
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from model.sourcerevision import platform_revision
|
||||
|
||||
# Every target scraper reads the network through the platform scrapers'
|
||||
# helpers: one retry policy, one size cap, one token rule.
|
||||
from ..base_scraper import fetch_text, forge_headers
|
||||
from ..base_scraper import exit_on_scrape_error, fetch_text, forge_headers
|
||||
|
||||
__all__ = ["BaseTargetScraper", "discover_target_scrapers", "fetch_text", "forge_headers",
|
||||
"target_cli"]
|
||||
@@ -66,8 +66,11 @@ def target_cli(scraper_class: type[BaseTargetScraper], description: str, unit: s
|
||||
parser.add_argument("--output", "-o", help="Output YAML file")
|
||||
args = parser.parse_args()
|
||||
|
||||
scraper = scraper_class()
|
||||
data = scraper.fetch_targets()
|
||||
try:
|
||||
scraper = scraper_class()
|
||||
data = scraper.fetch_targets()
|
||||
except (OSError, ValueError, RuntimeError) as e:
|
||||
exit_on_scrape_error(e)
|
||||
if args.dry_run:
|
||||
for name, info in data["targets"].items():
|
||||
print(f" {name} ({info['architecture']}): {len(info['cores'])} {unit}")
|
||||
|
||||
@@ -20,14 +20,11 @@ Buildbot structure varies by platform:
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import yaml
|
||||
|
||||
from . import BaseTargetScraper, fetch_text
|
||||
from . import BaseTargetScraper, fetch_text, target_cli
|
||||
|
||||
PLATFORM_NAME = "retroarch"
|
||||
|
||||
@@ -165,36 +162,7 @@ class Scraper(BaseTargetScraper):
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(
|
||||
allow_abbrev=False,
|
||||
description="Scrape RetroArch buildbot nightly targets"
|
||||
)
|
||||
parser.add_argument("--dry-run", action="store_true", help="Show target summary")
|
||||
parser.add_argument("--output", "-o", help="Output YAML file")
|
||||
args = parser.parse_args()
|
||||
|
||||
scraper = Scraper()
|
||||
data = scraper.fetch_targets()
|
||||
|
||||
total_cores = sum(len(t["cores"]) for t in data["targets"].values())
|
||||
print(
|
||||
f"\n{len(data['targets'])} targets, {total_cores} total core entries",
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
if args.dry_run:
|
||||
for name, info in sorted(data["targets"].items()):
|
||||
print(
|
||||
f" {name:30s} {info['architecture']:10s} {len(info['cores']):>4d} cores"
|
||||
)
|
||||
return
|
||||
|
||||
if args.output:
|
||||
scraper.write_output(data, args.output)
|
||||
print(f"Written to {args.output}")
|
||||
return
|
||||
|
||||
print(yaml.dump(data, default_flow_style=False, sort_keys=False))
|
||||
target_cli(Scraper, "Scrape RetroArch buildbot nightly targets")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -118,6 +118,19 @@ class FailedRequestsStopTheScrape(unittest.TestCase):
|
||||
self.assertEqual(targets["x86_64"]["cores"], ["mgba"])
|
||||
self.assertNotIn("x86_wow64", targets)
|
||||
|
||||
def test_the_command_line_names_the_failure(self):
|
||||
"""target_cli let the RuntimeError out as a traceback, without the
|
||||
`gh auth login` hint scraper_cli gives on a refused API call."""
|
||||
stderr = io.StringIO()
|
||||
with mock.patch("urllib.request.urlopen", _refuse), mock.patch(
|
||||
"sys.argv", ["retroarch_targets_scraper", "--dry-run"]
|
||||
), mock.patch("sys.stderr", stderr), mock.patch(
|
||||
"scripts.scraper.base_scraper.github_token", return_value=""
|
||||
), self.assertRaises(SystemExit) as raised:
|
||||
retroarch_targets_scraper.main()
|
||||
self.assertEqual(raised.exception.code, 1)
|
||||
self.assertIn("Error:", stderr.getvalue())
|
||||
|
||||
|
||||
class BatoceraKconfig(unittest.TestCase):
|
||||
"""The Batocera target scraper read every select as unconditional and
|
||||
|
||||
Reference in new issue
Block a user