mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 18:17:53 -06:00
refactor: move campaign and probe modes to probes
This commit is contained in:
1 parent
fd1c2e1c16
commit
2123bd8317
7 files changed
+206
-178
No files matched your search
@@ -26,9 +26,6 @@ of the emulator in its log, the process dying, a uniform screen to the end.
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import http.client
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
from collections.abc import Sequence
|
||||
from pathlib import Path
|
||||
@@ -36,44 +33,10 @@ from pathlib import Path
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
|
||||
import core_probe as cp
|
||||
from core import upstream
|
||||
from core.paths import REPO_ROOT
|
||||
from probes.appimage import fetch, github_releases, select_asset
|
||||
from probes.standaloneemulators import EMULATORS, Emulator
|
||||
from probes.standalonerecord import DEFAULT_WORK_DIR, Busy, RunFailed, measure, validate
|
||||
|
||||
|
||||
def probe(args: argparse.Namespace) -> int:
|
||||
emu = EMULATORS[args.emulator]
|
||||
problems = validate(args)
|
||||
if problems:
|
||||
for problem in problems:
|
||||
print(f"ERROR: {problem}", file=sys.stderr)
|
||||
return 2
|
||||
# One run on the host at a time, as core_probe: the lock is held for
|
||||
# this run, its load check included, and freed when it ends.
|
||||
with cp.host_probe_lock():
|
||||
return _probe(args, emu)
|
||||
|
||||
|
||||
def _probe(args: argparse.Namespace, emu: Emulator) -> int:
|
||||
try:
|
||||
record = measure(args, emu)
|
||||
except RunFailed as exc:
|
||||
print(f"ERROR: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
except Busy as exc:
|
||||
print(f"ERROR: {exc}", file=sys.stderr)
|
||||
return 3
|
||||
if args.record:
|
||||
try:
|
||||
lines, record = cp.write_record(Path(args.record), record)
|
||||
except cp.ProbeError as exc:
|
||||
print(f"ERROR: {exc}", file=sys.stderr)
|
||||
return 2
|
||||
print(f"recorded {lines}", file=sys.stderr)
|
||||
print(json.dumps(record, indent=2))
|
||||
return 0
|
||||
from probes.standaloneemulators import EMULATORS
|
||||
from probes.standalonemodes import run_mode
|
||||
from probes.standalonerecord import DEFAULT_WORK_DIR
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
@@ -127,27 +90,7 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
|
||||
|
||||
def main(argv: Sequence[str] | None = None) -> int:
|
||||
args = build_parser().parse_args(argv)
|
||||
emu = EMULATORS[args.emulator]
|
||||
if args.mode == "resolve":
|
||||
try:
|
||||
releases = github_releases(emu.repo)
|
||||
except cp.ProbeError as exc:
|
||||
print(f"ERROR: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
asset = select_asset(releases, emu.asset_endswith, emu.asset_contains)
|
||||
print(json.dumps({"emulator": emu.name, "platform": emu.platform,
|
||||
"installer_ref": emu.installer_ref, "asset": asset}, indent=2))
|
||||
return 0 if asset else 1
|
||||
if args.mode == "fetch":
|
||||
try:
|
||||
print(json.dumps(fetch(emu), indent=2))
|
||||
except (cp.ProbeError, upstream.UpstreamError, OSError, http.client.HTTPException,
|
||||
subprocess.CalledProcessError) as exc:
|
||||
print(f"ERROR: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
return probe(args)
|
||||
return run_mode(build_parser().parse_args(argv))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user