mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 10:07:48 -06:00
Library functions printed their refusal and exited, each deciding on its own whether --events got an error event. --cores-dir, --installed-cores with no core, a list without system_cores or standalone_builds, a pack that cannot be used, a board list a run needs and --dest alone beside two setups ended on code 1 with no reason in the stream. They now raise Refusal (installer/refusal.py), carrying the stage, the reason, the platform, the lines and the code. The install, an action framed by events and main report it once: the error event, then the same lines on stderr, so the text and exit codes stay as they were.
37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
"""A refusal that ends the run, raised where it is decided and reported once by the command."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
from installer.events import EVENTS
|
|
|
|
|
|
class Refusal(SystemExit):
|
|
"""The run refused, with the error event a script reads and the lines a
|
|
person reads. Each site printed its lines and chose on its own whether
|
|
--events got the reason, and several did not: a script learned code 1
|
|
and nothing else. message is the event's, by default the lines joined
|
|
without their leading "Error: "."""
|
|
|
|
def __init__(self, stage: str, reason: str, platform: str, *lines: str,
|
|
code: int = 1, message: str | None = None) -> None:
|
|
super().__init__(code)
|
|
self.stage, self.reason, self.platform = stage, reason, platform
|
|
self.lines = lines
|
|
if message is None:
|
|
message = " ".join(line.strip() for line in lines)
|
|
if message.startswith("Error: "):
|
|
message = message[len("Error: "):]
|
|
self.message = message
|
|
self.reported = False
|
|
|
|
def report(self) -> None:
|
|
"""The error event, then the lines on stderr, once."""
|
|
if self.reported:
|
|
return
|
|
self.reported = True
|
|
EVENTS.emit("error", stage=self.stage, reason=self.reason, platform=self.platform,
|
|
message=self.message)
|
|
for line in self.lines:
|
|
print(line, file=sys.stderr)
|