From 63bb66df4d0343a79560516d49c3e55a48436f79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20St=C3=A5hl?= Date: Fri, 28 Feb 2025 13:32:38 +0100 Subject: [PATCH] wip --- scripts/chickn.py | 27 +++++++++++++++++--- tests/protocols/dmap/test_dmap_functional.py | 2 +- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/scripts/chickn.py b/scripts/chickn.py index 69fe5b47b..3e968591b 100755 --- a/scripts/chickn.py +++ b/scripts/chickn.py @@ -23,7 +23,7 @@ class InternalError(Exception): """Raised internally on error.""" -async def _exec(cmd) -> Tuple[str, str]: +async def _exec2(cmd) -> Tuple[str, str]: _LOGGER.debug("Run command: %s", cmd) proc = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE @@ -42,6 +42,25 @@ async def _exec(cmd) -> Tuple[str, str]: return stdout, stderr +async def _exec(cmd) -> Tuple[str, str]: + _LOGGER.debug("Run command: %s", cmd) + proc = await asyncio.create_subprocess_shell( + cmd # , stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE + ) + + await proc.wait() + + stdout = "" + stderr = "" + + if proc.returncode != 0: + raise InternalError( + f"Command failed: {cmd}\n[STDOUT]\n{stdout}\n\n[STDERR]\n{stderr}" + ) + + return stdout, stderr + + async def run_step(step, variables) -> None: """Run a step with given variables.""" _LOGGER.info("Running step %s", step["name"]) @@ -67,7 +86,7 @@ async def run_step(step, variables) -> None: async def run_pip(dependency_files, variables, force_reinstall=False) -> None: """Run pip and try to figure out if dependencies needs to be installed.""" # Figure out which packages are installed - stdout, _ = await _exec("pip list --format json") + stdout, _ = await _exec2("pip list --format json") installed_packages = { package["name"]: package["version"] for package in json.loads(stdout) } @@ -108,7 +127,7 @@ async def run_pip(dependency_files, variables, force_reinstall=False) -> None: ), ) - await _exec( + await _exec2( "pip install --upgrade " + ("--force-reinstall " if force_reinstall else "") + " ".join( @@ -140,7 +159,7 @@ async def parse_variable_value(value: Union[str, Sequence[str]]) -> str: # Execute command and use stdout as value if format is $(command) if value.startswith("$(") and value.endswith(")"): - return (await _exec(value[2:-1]))[0].rstrip() # Only stdout + return (await _exec2(value[2:-1]))[0].rstrip() # Only stdout return value diff --git a/tests/protocols/dmap/test_dmap_functional.py b/tests/protocols/dmap/test_dmap_functional.py index 49d82f9c6..c5561d914 100644 --- a/tests/protocols/dmap/test_dmap_functional.py +++ b/tests/protocols/dmap/test_dmap_functional.py @@ -58,7 +58,7 @@ async def setUpAsync(self): async def tearDownAsync(self): await asyncio.gather(*self.atv.close()) - super().tearDown() + await super().tearDownAsync() async def get_application(self, loop=None): self.fake_atv = FakeAppleTV(self.loop)