From d00342734b1f200dc14185306997991435660cb3 Mon Sep 17 00:00:00 2001 From: xudan Date: Fri, 16 Dec 2016 00:41:25 +0000 Subject: 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 --- dovetail/utils/dovetail_utils.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'dovetail') 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() -- cgit 1.2.3-korg