mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
chore: Refactor run_command function in build.py to handle exceptions
```
This commit is contained in:
parent
a4d4c563b5
commit
43142134e8
1 changed files with 13 additions and 9 deletions
|
|
@ -40,16 +40,20 @@ def set_setup():
|
|||
def run_command(command: List[str]) -> int:
|
||||
"""Utils to run a subprocess command. This is usefull to run npm commands to build vite project"""
|
||||
print(f"Running command: {command}", flush=True)
|
||||
process = Popen(command, stdout=PIPE, stderr=PIPE, cwd=current_directory, text=True)
|
||||
while process.poll() is None:
|
||||
if process.stdout is not None:
|
||||
for line in process.stdout:
|
||||
print(line.strip(), flush=True)
|
||||
try:
|
||||
process = Popen(command, stdout=PIPE, stderr=PIPE, cwd=current_directory, text=True)
|
||||
while process.poll() is None:
|
||||
if process.stdout is not None:
|
||||
for line in process.stdout:
|
||||
print(line.strip(), flush=True)
|
||||
|
||||
if process.returncode != 0:
|
||||
print("Error while running command", flush=True)
|
||||
print(process.stdout, flush=True)
|
||||
print(process.stderr, flush=True)
|
||||
if process.returncode != 0:
|
||||
print("Error while running command", flush=True)
|
||||
print(process.stdout, flush=True)
|
||||
print(process.stderr, flush=True)
|
||||
return 1
|
||||
except BaseException as e:
|
||||
print(f"Error while running command: {e}", flush=True)
|
||||
return 1
|
||||
|
||||
print("Command executed successfully", flush=True)
|
||||
|
|
|
|||
Loading…
Reference in a new issue