From 3bcb615d4f1e2fd4caff9d8e3170529f867ba23a Mon Sep 17 00:00:00 2001 From: Brayan Ceron Date: Wed, 26 Jun 2024 18:14:45 -0500 Subject: [PATCH] fix: freeze when 'enable-themes' was execute twice If the command 'enable-themes' is already executed, in the second execution it shows a warning for overriding the already existing folder with the themes. --- .../infrastructure/tutor_commands.py | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tutordistro/distro/extra_commands/infrastructure/tutor_commands.py b/tutordistro/distro/extra_commands/infrastructure/tutor_commands.py index dbc78f3..8c92dba 100644 --- a/tutordistro/distro/extra_commands/infrastructure/tutor_commands.py +++ b/tutordistro/distro/extra_commands/infrastructure/tutor_commands.py @@ -69,17 +69,24 @@ def run_command(self, command: str): command (str): Tutor command. """ try: - process = subprocess.run( + print(f'Running "{command}"') + + with subprocess.Popen( command, shell=True, - check=True, - capture_output=True, executable="/bin/bash", - ) - # This print is left on purpose to show the command output - print(process.stdout.decode()) + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + ) as process: + + stdout, stderr = process.communicate(input="y") + + if process.returncode != 0 or "error" in stderr.lower(): + raise subprocess.CalledProcessError( + process.returncode, command, output=stdout, stderr=stderr + ) except subprocess.CalledProcessError as error: - raise CommandError( - f"Error running command '{error.cmd}':\n{error.stderr.decode()}" - ) from error + raise CommandError(f"\n{error.stderr}") from error