fix: keep stdout to events in a removal

--remove and --backups opened the --manifest and --from-pack before
the event stream started: the list's platform and the pack name went to
stdout ahead of start, and a refusal of the pack came with no event.
They are opened inside the action now.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 19:50:46 +01:00
1 parent eba627aa89
commit c888ae8101
6 files changed
+52 -14

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@
# and Invoke-WebRequest throws on a cut transfer before the hash is read:
# the site's build rewrites this line there (scripts/sitebootstrap.py).
$mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
$defaultInstallSha256 = "ed45f61685e87ea272a58178321d4fefb4421e556404e14e36381b023cf191fa"
$defaultInstallSha256 = "5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
$maximumInstallerBytes = 8MB
+12 -2
View File
@@ -32149,8 +32149,7 @@ def _main_run() -> None:
_main_check_offline(parser, args)
install_bounded_opener()
if args.remove or args.backups:
_open_local_sources(args)
_run_action(args, run_removal if args.remove else run_backups)
_run_action(args, _with_local_sources(run_removal if args.remove else run_backups))
_main_check_sources(parser, args)
_main_dispatch(args)
@@ -32231,6 +32230,17 @@ def _check_pack(parser: argparse.ArgumentParser, args: argparse.Namespace) -> No
f"name): {name}")
def _with_local_sources(action: Callable[[argparse.Namespace], int],
) -> Callable[[argparse.Namespace], int]:
"""action, the list and the pack it was given opened first. Opened
before the action, they said the list's platform on stdout ahead of
start, the first line of --events no JSON."""
def opened(args: argparse.Namespace) -> int:
_open_local_sources(args)
return action(args)
return opened
def _run_action(args: argparse.Namespace,
action: Callable[[argparse.Namespace], int]) -> NoReturn:
"""Run an action and exit with its code, its events framed by start and
+1 -1
View File
@@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins
# curl or wget stop on a cut transfer before the hash is read: the site's
# build rewrites this line there (scripts/sitebootstrap.py).
MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
DEFAULT_INSTALL_SHA256="ed45f61685e87ea272a58178321d4fefb4421e556404e14e36381b023cf191fa"
DEFAULT_INSTALL_SHA256="5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
MAX_INSTALLER_BYTES=8388608
+8 -8
View File
@@ -27,8 +27,8 @@
{
"dest": "roms/ports/retrobios/install.py",
"repo_path": "install.py",
"size": 1465384,
"sha256": "ed45f61685e87ea272a58178321d4fefb4421e556404e14e36381b023cf191fa",
"size": 1465830,
"sha256": "5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab",
"executable": false
},
{
@@ -71,8 +71,8 @@
"muos": {
"archive": {
"dest": "ARCHIVE/RetroBIOS.muxapp",
"size": 1519009,
"sha256": "de8c0baf1dc070332235391e2ea42159337d79eff9adf796cbf2bd8c676b3aa7"
"size": 1519455,
"sha256": "4af67cea311827c3546e9ea72682730c2edc799933d85768ade64c6a2a77f669"
},
"members": [
{
@@ -92,8 +92,8 @@
{
"name": "RetroBIOS/install.py",
"repo_path": "install.py",
"size": 1465384,
"sha256": "ed45f61685e87ea272a58178321d4fefb4421e556404e14e36381b023cf191fa",
"size": 1465830,
"sha256": "5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab",
"executable": false
},
{
@@ -166,8 +166,8 @@
{
"dest": ".config/modules/retrobios/install.py",
"repo_path": "install.py",
"size": 1465384,
"sha256": "ed45f61685e87ea272a58178321d4fefb4421e556404e14e36381b023cf191fa",
"size": 1465830,
"sha256": "5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab",
"executable": false
},
{
+12 -2
View File
@@ -349,8 +349,7 @@ def _main_run() -> None:
_main_check_offline(parser, args)
install_bounded_opener()
if args.remove or args.backups:
_open_local_sources(args)
_run_action(args, run_removal if args.remove else run_backups)
_run_action(args, _with_local_sources(run_removal if args.remove else run_backups))
_main_check_sources(parser, args)
_main_dispatch(args)
@@ -431,6 +430,17 @@ def _check_pack(parser: argparse.ArgumentParser, args: argparse.Namespace) -> No
f"name): {name}")
def _with_local_sources(action: Callable[[argparse.Namespace], int],
) -> Callable[[argparse.Namespace], int]:
"""action, the list and the pack it was given opened first. Opened
before the action, they said the list's platform on stdout ahead of
start, the first line of --events no JSON."""
def opened(args: argparse.Namespace) -> int:
_open_local_sources(args)
return action(args)
return opened
def _run_action(args: argparse.Namespace,
action: Callable[[argparse.Namespace], int]) -> NoReturn:
"""Run an action and exit with its code, its events framed by start and
+18
View File
@@ -335,6 +335,24 @@ class Events(unittest.TestCase):
["event", *install.EVENT_KEYS[event["event"]]]))
def test_a_list_given_as_a_file_keeps_stdout_to_events(self):
"""The list's platform was said on stdout before start: a reader
of the stream got a first line that is not JSON."""
with SharedRepository() as repo:
repo.install_both()
listed = repo.root / "install" / "retroarch.json"
# The command without --platform: the list names it.
python, script = repo.command()[:2]
proc = subprocess.run(
[python, script, "--dest", str(repo.dest), "--remove", "--dry-run",
"--events", "--manifest", str(listed)],
env=repo.env(), capture_output=True, text=True, timeout=60, check=False,
stdin=subprocess.DEVNULL)
self.assertEqual(proc.returncode, 0, proc.stderr)
kinds = [json.loads(line)["event"] for line in proc.stdout.splitlines()]
self.assertEqual(kinds, ["start", "removal_plan", "end"])
self.assertIn("File list:", proc.stderr)
class DeleteABackup(unittest.TestCase):
def test_only_a_backup_folder_and_only_with_a_yes(self):
with SharedRepository() as repo: