dovetail tool: show progress during executing test cases 53/26053/1
authorxudan <xudan16@huawei.com>
Fri, 16 Dec 2016 00:41:25 +0000 (00:41 +0000)
committerxudan <xudan16@huawei.com>
Fri, 16 Dec 2016 00:55:03 +0000 (00:55 +0000)
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>
dovetail/utils/dovetail_utils.py

index e4f9198..2d5f0dd 100644 (file)
@@ -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()