summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2016-12-16 00:41:25 +0000
committerxudan <xudan16@huawei.com>2016-12-16 00:55:03 +0000
commitd00342734b1f200dc14185306997991435660cb3 (patch)
tree23e672f4267a35c5455734c678c3179b7b950c17
parent004634d4ce99da007228293877e3dd1e179b02ec (diff)
dovetail tool: show progress during executing test cases
1. the utils exec_cmd() will take a long time for some cmds such as executing test cases and pull images. 2. if the time is longer than 3 seconds, progress bar will be shown on the screen. JIRA: DOVETAIL-159 Change-Id: I4ae04d6e884853d843baf8f547394247f4165377 Signed-off-by: xudan <xudan16@huawei.com>
-rw-r--r--dovetail/utils/dovetail_utils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py
index e4f91987..2d5f0dd1 100644
--- a/dovetail/utils/dovetail_utils.py
+++ b/dovetail/utils/dovetail_utils.py
@@ -10,6 +10,7 @@
#
import sys
+import time
import subprocess
from collections import Mapping, Set, Sequence
@@ -29,6 +30,15 @@ def exec_cmd(cmd, logger=None, exit_on_error=True, info=False,
print(msg_exec)
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
+
+ # show progress bar
+ seconds = 0
+ while p.poll() is None:
+ seconds += 1
+ if seconds > 3:
+ show_progress_bar(seconds)
+ time.sleep(1)
+
output = p.communicate()
for line in output[0].strip().split('\n'):
line = line.replace('\n', '')
@@ -89,3 +99,12 @@ def get_obj_by_path(obj, dst_path):
for path, obj in objwalk(obj):
if path == dst_path:
return obj
+
+
+def show_progress_bar(length):
+ max_len = 50
+ length %= max_len
+ sys.stdout.write('Running ' + ' ' * max_len + '\r')
+ sys.stdout.flush()
+ sys.stdout.write('Running ' + '=' * length + '>' + '\r')
+ sys.stdout.flush()