[PATCH] knotty: show elapsed time on the task progress bar

WXbet <[email protected]>
Newsgroups org.openembedded.lists.bitbake-devel
Message-ID <[email protected]>
The progress bar for the overall build shows a percentage and a bar but no
elapsed time, even though the individual running-task lines below it each
show one.

Add a Timer widget to the bar. The time formatting in
TerminalFilter.elapsed() is hoisted to a module-level bb_elapsed() helper and
reused by a small progressbar.Timer subclass, so the bar prints the same
"%dh%dm%ds" style as the rest of the UI.

Signed-off-by: WXbet <[email protected]>
---
 lib/bb/ui/knotty.py | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py
index 15025e8dd..343045881 100644
--- a/lib/bb/ui/knotty.py
+++ b/lib/bb/ui/knotty.py
@@ -37,6 +37,21 @@ featureSet = [bb.cooker.CookerFeatures.SEND_SANITYEVENTS, bb.cooker.CookerFeatur
 logger = logging.getLogger("BitBake")
 interactive = sys.stdout.isatty()
 
+def bb_elapsed(sec):
+    hrs = int(sec / 3600.0)
+    sec -= hrs * 3600
+    min = int(sec / 60.0)
+    sec -= min * 60
+    if hrs > 0:
+        return "%dh%dm%ds" % (hrs, min, sec)
+    elif min > 0:
+        return "%dm%ds" % (min, sec)
+    else:
+        return "%ds" % (sec)
+
+class BBTimer(progressbar.Timer):
+    format_time = staticmethod(bb_elapsed)
+
 class BBProgress(progressbar.ProgressBar):
     def __init__(self, msg, maxval, widgets=None, extrapos=-1, resize_handler=None):
         self.id = msg
@@ -250,16 +265,7 @@ class TerminalFilter(object):
         self._footer_lines = None
 
     def elapsed(self, sec):
-        hrs = int(sec / 3600.0)
-        sec -= hrs * 3600
-        min = int(sec / 60.0)
-        sec -= min * 60
-        if hrs > 0:
-            return "%dh%dm%ds" % (hrs, min, sec)
-        elif min > 0:
-            return "%dm%ds" % (min, sec)
-        else:
-            return "%ds" % (sec)
+        return bb_elapsed(sec)
 
     def keepAlive(self, t):
         if not self.cuu:
@@ -354,7 +360,7 @@ class TerminalFilter(object):
                 msg = "Currently %2s running tasks (%s)" % (len(activetasks), cur_tasks)
             maxtask = self.helper.tasknumber_total
             if not self.main_progress or self.main_progress.maxval != maxtask:
-                widgets = [' ', progressbar.Percentage(), ' ', progressbar.Bar()]
+                widgets = [' ', progressbar.Percentage(), ' ', progressbar.Bar(), ' ', BBTimer(format='Elapsed: %s')]
                 self.main_progress = BBProgress("Running tasks", maxtask, widgets=widgets, resize_handler=self.sigwinch_handle)
                 self.main_progress.fd = self._footer_buf
                 self.main_progress.start(False)
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.