From 7d50580f1a58da15a3382419836e27e3eae41d6d Mon Sep 17 00:00:00 2001 From: xudan Date: Sat, 14 Jan 2017 01:27:09 +0000 Subject: 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 --- dovetail/utils/dovetail_utils.py | 27 +++++++++++---------------- 1 file 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 -- cgit 1.2.3-korg