dovetail tool: modify function exec_cmd to force it to flush the buffer 89/26989/5
authorxudan <xudan16@huawei.com>
Sat, 14 Jan 2017 01:27:09 +0000 (01:27 +0000)
committerxudan <xudan16@huawei.com>
Thu, 19 Jan 2017 09:35:04 +0000 (04:35 -0500)
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>
dovetail/utils/dovetail_utils.py

index 960801a..a54081f 100644 (file)
@@ -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