bitbake: knotty: Simplify footer tasklist generation
PATCH 1/1 bitbake: knotty: Simplify footer tasklist generation
Instead of using a string for tasks without progressbar and a tuple for tasks with progressbar, collect the necessary state in a namedtuple.
Only have two string variants instead of three, and get elapsed time for tasks with progressbar.
Signed-off-by Ola x Nilsson <[email protected]>
--- bitbake/lib/bb/ui/knotty.py | 52 ++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 27 deletions(-)
bitbake/lib/bb/ui/knotty.py +25 -27
@@ -32,6 +32,7 @@ import fcntl import struct import copy import atexit +from collections import namedtuple from bb.ui import uihelper
@@ -239,29 +240,24 @@ class TerminalFilter(object): self.clearFooter() if (not self.helper.tasknumber_total or self.helper.tasknumber_current == self.helper.tasknumber_total) and not len(activetasks): return + Task = namedtuple('task', 'title pid starttime progress pbar rate') tasks = [] - for t in runningpids: - progress = activetasks[t].get("progress", None) + for pid in runningpids: + title = activetasks[pid]["title"] + start_time = activetasks[pid].get("starttime", None) + progress = activetasks[pid].get("progress", None) + pbar = progress and activetasks[pid].get("progressbar", None) + rate = progress and activetasks[pid].get("rate", None) if progress is not None: - pbar = activetasks[t].get("progressbar", None) - rate = activetasks[t].get("rate", None) - start_time = activetasks[t].get("starttime", None) if not pbar or pbar.bouncing != (progress < 0): if progress < 0: - pbar = BBProgress("0: %s (pid %s) " % (activetasks[t]["title"], t), 100, widgets=[progressbar.BouncingSlider(), ''], extrapos=2, resize_handler=self.sigwinch_handle) + pbar = BBProgress(title, 100, widgets=[progressbar.BouncingSlider(), ''], extrapos=2, resize_handler=self.sigwinch_handle) pbar.bouncing = True else: - pbar = BBProgress("0: %s (pid %s) " % (activetasks[t]["title"], t), 100, widgets=[progressbar.Percentage(), ' ', progressbar.Bar(), ''], extrapos=4, resize_handler=self.sigwinch_handle) + pbar = BBProgress(title, 100, widgets=[progressbar.Percentage(), ' ', progressbar.Bar(), ''], extrapos=4, resize_handler=self.sigwinch_handle) pbar.bouncing = False - activetasks[t]["progressbar"] = pbar - tasks.append((pbar, progress, rate, start_time)) - else: - start_time = activetasks[t].get("starttime", None) - if start_time: - tasks.append("%s - %ds (pid %s)" % (activetasks[t]["title"], currenttime - start_time, t)) - else: - tasks.append("%s (pid %s)" % (activetasks[t]["title"], t)) - + activetasks[pid]["progressbar"] = pbar + tasks.append(Task(title, pid, start_time, progress, pbar, rate)) if self.main.shutdown: content = "Waiting for %s running tasks to finish:" % len(activetasks) print(content)
@@ -286,21 +282,23 @@ class TerminalFilter(object): lines = 1 + int(len(content) / (self.columns + 1)) if self.quiet == 0: for tasknum, task in enumerate(tasks[:(self.rows - 2)]): - if isinstance(task, tuple): - pbar, progress, rate, start_time = task - if not pbar.start_time: - pbar.start(False) + if task.starttime: + content = "%s: %s - %ds (pid %d)" % (tasknum, task.title, currenttime - task.starttime, task.pid) + else: + content = "%s: %s (pid %d)" % (tasknum, task.title, task.pid) + if task.pbar: + if not task.pbar.start_time: + task.pbar.start(False) if start_time: - pbar.start_time = start_time - pbar.setmessage('%s:%s' % (tasknum, pbar.msg.split(':', 1)[1])) - if progress > -1: - pbar.setextra(rate) - content = pbar.update(progress) + task.pbar.start_time = start_time + task.pbar.setmessage(content) + if task.progress > -1: + task.pbar.setextra(task.rate) + content = task.pbar.update(task.progress) else: - content = pbar.update(1) + content = task.pbar.update(1) print('') else: - content = "%s: %s" % (tasknum, task) print(content) lines = lines + 1 + int(len(content) / (self.columns + 1)) self.footer_present = lines
Signature · 1 line
2.11.0