diff options
author | xudan <xudan16@huawei.com> | 2017-01-14 01:27:09 +0000 |
---|---|---|
committer | xudan <xudan16@huawei.com> | 2017-01-19 04:35:04 -0500 |
commit | 7d50580f1a58da15a3382419836e27e3eae41d6d (patch) | |
tree | 5e16d0cf25cdf817eab0cea5a9c0f85f5d7a56fb | |
parent | c2401cd1bf3898aebeef08ca699072b1dca683f0 (diff) |
dovetail tool: modify function exec_cmd to force it to flush the buffer
1. force to flush the buffer line by line
2. remove the progress bar since it will stay in the screen if using the cli
command JIRA: DOVETAIL-173, which will be ugly.
JIRA: DOVETAIL-172
Change-Id: I47b823c7e0bce955a50086613a656c83ab7707e3
Signed-off-by: xudan <xudan16@huawei.com>
-rw-r--r-- | dovetail/utils/dovetail_utils.py | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py index 960801a8..a54081f5 100644 --- a/dovetail/utils/dovetail_utils.py +++ b/dovetail/utils/dovetail_utils.py @@ -10,7 +10,6 @@ # import sys -import time import subprocess from collections import Mapping, Set, Sequence @@ -43,25 +42,21 @@ def exec_cmd(cmd, logger=None, exit_on_error=False, info=False, exec_log(verbose, logger, msg_exec, level) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - seconds = 0 - while p.poll() is None: - seconds += 1 - if seconds > 3: - show_progress_bar(seconds) - time.sleep(1) - - (stdout, stderr) = p.communicate() - if p.returncode == 0: - for line in stdout.strip().splitlines(): - exec_log(verbose, logger, line, level, True) - else: - exec_log(verbose, logger, stderr, 'error') + stderr=subprocess.STDOUT) + stdout = '' + for line in iter(p.stdout.readline, b''): + exec_log(verbose, logger, line.strip(), level, True) + stdout += line + stdout = stdout.strip() + returncode = p.wait() + p.stdout.close() + + if returncode != 0: exec_log(verbose, logger, msg_err, 'error') if exit_on_error: sys.exit(1) - return p.returncode, stdout.strip() + return returncode, stdout # walkthrough the object, yield path and value |