Skip to contentSkip to conversation

knotty.py: Improve the message while waiting for running tasks to finish

PATCH New Peter Kjellerstedt 1 participant 4 messages Mar 8, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/4 knotty.py: Improve the message while waiting for running tasks to finish

From: Peter Kjellerstedt <[email protected]>

Use pluralise() to correct the grammar, and drop the colon at the end if runnning in quiet mode.

---

PATCHv2: No changes.
PATCHv3: No changes.

 bitbake/lib/bb/ui/knotty.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
bitbake/lib/bb/ui/knotty.py +4 -1
index b02e59c1fe..a520895da2 100644
@@ -272,7 +272,10 @@ class TerminalFilter(object):
                     tasks.append("%s (pid %s)" % (activetasks[t]["title"], activetasks[t]["pid"]))
 
         if self.main.shutdown:
-            content = "Waiting for %s running tasks to finish:" % len(activetasks)
+            content = pluralise("Waiting for %s running task to finish",
+                                "Waiting for %s running tasks to finish", len(activetasks))
+            if not self.quiet:
+                content += ':'
             print(content)
         else:
             if self.quiet:
#1 lore raw

PATCH v3 2/4 knotty.py: Correct the width of the progress bar for the real tasks

From: Peter Kjellerstedt <[email protected]>

In commit 8055ec36 (knotty: Improve setscene task display) the setscene tasks got their own line in the task output. However, the progress bar code does not handle newlines in its widgets, so the length of the setscene line was included when calculating how much space is available for the progress bar of the running tasks, making it much too short.

Instead of trying to teach the progress bar code to handle newlines, separate the output of the setscene tasks from the progress bar for the real tasks.

---

PATCHv2: Corrected so that there are no changes to the output except
that the progress bar now fills the width of the terminal as expected.
PATCHv3: Extracted two minor code clean ups to a separate patch.

 bitbake/lib/bb/ui/knotty.py | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
bitbake/lib/bb/ui/knotty.py +14 -5
index a520895da2..52e6eb96fe 100644
@@ -278,22 +278,31 @@ class TerminalFilter(object):
                 content += ':'
             print(content)
         else:
+            scene_tasks = "%s of %s" % (self.helper.setscene_current, self.helper.setscene_total)
+            cur_tasks = "%s of %s" % (self.helper.tasknumber_current, self.helper.tasknumber_total)
+
+            content = ''
+            if not self.quiet:
+                msg = "Setscene tasks: %s" % scene_tasks
+                content += msg + "\n"
+                print(msg)
+
             if self.quiet:
-                content = "Running tasks (%s of %s, %s of %s)" % (self.helper.setscene_current, self.helper.setscene_total, self.helper.tasknumber_current, self.helper.tasknumber_total)
+                msg = "Running tasks (%s, %s)" % (scene_tasks, cur_tasks)
             elif not len(activetasks):
-                content = "Setscene tasks: %s of %s\nNo currently running tasks (%s of %s)" % (self.helper.setscene_current, self.helper.setscene_total, self.helper.tasknumber_current, self.helper.tasknumber_total)
+                msg = "No currently running tasks (%s)" % cur_tasks
             else:
-                content = "Setscene tasks: %s of %s\nCurrently %2s running tasks (%s of %s)" % (self.helper.setscene_current, self.helper.setscene_total, len(activetasks), self.helper.tasknumber_current, self.helper.tasknumber_total)
+                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()]
                 self.main_progress = BBProgress("Running tasks", maxtask, widgets=widgets, resize_handler=self.sigwinch_handle)
                 self.main_progress.start(False)
-            self.main_progress.setmessage(content)
+            self.main_progress.setmessage(msg)
             progress = self.helper.tasknumber_current - 1
             if progress < 0:
                 progress = 0
-            content = self.main_progress.update(progress)
+            content += self.main_progress.update(progress)
             print('')
         lines = self.getlines(content)
         if self.quiet == 0:
#2 lore raw

PATCH v3 3/4 knotty.py: A little clean up of TerminalFilter::updateFooter()

In reply to Peter Kjellerstedt

* Use max() to clamp progress to >= 0.
* Be consistent when evaluating self.quiet (treat it as a boolean).

---

PATCHv3: New. This was previously part of the preceding patch.

 bitbake/lib/bb/ui/knotty.py | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
bitbake/lib/bb/ui/knotty.py +2 -4
index 52e6eb96fe..78888f8bdd 100644
@@ -299,13 +299,11 @@ class TerminalFilter(object):
                 self.main_progress = BBProgress("Running tasks", maxtask, widgets=widgets, resize_handler=self.sigwinch_handle)
                 self.main_progress.start(False)
             self.main_progress.setmessage(msg)
-            progress = self.helper.tasknumber_current - 1
-            if progress < 0:
-                progress = 0
+            progress = max(0, self.helper.tasknumber_current - 1)
             content += self.main_progress.update(progress)
             print('')
         lines = self.getlines(content)
-        if self.quiet == 0:
+        if not self.quiet:
             for tasknum, task in enumerate(tasks[:(self.rows - 1 - lines)]):
                 if isinstance(task, tuple):
                     pbar, progress, rate, start_time = task
#3 lore raw

PATCH v3 4/4 knotty.py: Unify quiet and non-quiet output for the running tasks

In reply to Peter Kjellerstedt

From: Peter Kjellerstedt <[email protected]>

This adds the number of currently running tasks to the output in quiet mode, and removes the word "currently" from the output for the non-quiet output. Removing "currently" avoids having the text "jump around" depending on whether any tasks are running or not, and it also gives a little bit more space to the progress bar.

---

PATCHv2: New.
PATCHv3: No changes.

 bitbake/lib/bb/ui/knotty.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
bitbake/lib/bb/ui/knotty.py +3 -4
index 78888f8bdd..704e688f48 100644
@@ -287,12 +287,11 @@ class TerminalFilter(object):
                 content += msg + "\n"
                 print(msg)
 
+            msg = "%2s running tasks" % (len(activetasks) or "No")
             if self.quiet:
-                msg = "Running tasks (%s, %s)" % (scene_tasks, cur_tasks)
-            elif not len(activetasks):
-                msg = "No currently running tasks (%s)" % cur_tasks
+                msg += " (%s, %s)" % (scene_tasks, cur_tasks)
             else:
-                msg = "Currently %2s running tasks (%s)" % (len(activetasks), cur_tasks)
+                msg += " (%s)" % cur_tasks
             maxtask = self.helper.tasknumber_total
             if not self.main_progress or self.main_progress.maxval != maxtask:
                 widgets = [' ', progressbar.Percentage(), ' ', progressbar.Bar()]