aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/utils.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/modules/utils.py b/modules/utils.py
index dac77c5..4e779d8 100644
--- a/modules/utils.py
+++ b/modules/utils.py
@@ -1,11 +1,13 @@
-from subprocess import CalledProcessError
-from subprocess import check_output
+from subprocess import PIPE
+from subprocess import Popen
from subprocess import STDOUT
+from subprocess import SubprocessError
import re
from linaropy.git.worktree import Worktree
+
class CommandPrinter(object):
"""Command consumer that just prints the commands that it receives."""
@@ -22,12 +24,15 @@ class CommandRunner(object):
stderr. If an exception is thrown while running the command, it will be
rethrown as a RuntimeError.
"""
- # FIXME: This prints the results after the command has finished running.
- # For long-running commands (e.g. an LLVM build) we'll want live
- # output.
try:
- print(str(check_output(command, stderr=STDOUT, cwd=directory), 'utf-8'))
- except CalledProcessError as exc:
+ with Popen(command, stdout=PIPE, stderr=STDOUT, cwd=directory) as process:
+ for line in process.stdout:
+ print(str(line, 'utf-8'), end='')
+ if process.returncode != 0:
+ raise RuntimeError(
+ "Command failed with return code: {}\n".format(
+ process.returncode))
+ except SubprocessError as exc:
raise RuntimeError(
"Error while running command\n{}".format(str(exc.output, 'utf-8'))) from exc