diff options
| author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2016-06-23 22:59:05 +1200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-07-08 09:57:26 +0100 |
| commit | ac5e720575dd3c8f86514a7a646de82c8cc28e17 (patch) | |
| tree | 9c0cec5d764f1b9fb8f33d5f094d87a8fbc89ab5 /bitbake/lib/progressbar | |
| parent | 1cf6e14a6c5ddb4daec1c1e0cce113eea8570545 (diff) | |
| download | poky-ac5e720575dd3c8f86514a7a646de82c8cc28e17.tar.gz | |
bitbake: lib: implement basic task progress support
For long-running tasks where we have some output from the task that
gives us some idea of the progress of the task (such as a percentage
complete), provide the means to scrape the output for that progress
information and show it to the user in the default knotty terminal
output in the form of a progress bar. This is implemented using a new
TaskProgress event as well as some code we can insert to do output
scanning/filtering.
Any task can fire TaskProgress events; however, if you have a shell task
whose output you wish to scan for progress information, you just need to
set the "progress" varflag on the task. This can be set to:
* "percent" to just look for a number followed by a % sign
* "percent:<regex>" to specify your own regex matching a percentage
value (must have a single group which matches the percentage number)
* "outof:<regex>" to look for the specified regex matching x out of y
items completed (must have two groups - first group needs to be x,
second y).
We can potentially extend this in future but this should be a good
start.
Part of the implementation for [YOCTO #5383].
(Bitbake rev: 0d275fc5b6531957a6189069b04074065bb718a0)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/progressbar')
| -rw-r--r-- | bitbake/lib/progressbar/progressbar.py | 16 | ||||
| -rw-r--r-- | bitbake/lib/progressbar/widgets.py | 36 |
2 files changed, 48 insertions, 4 deletions
diff --git a/bitbake/lib/progressbar/progressbar.py b/bitbake/lib/progressbar/progressbar.py index 0b9dcf763e..2873ad6cae 100644 --- a/bitbake/lib/progressbar/progressbar.py +++ b/bitbake/lib/progressbar/progressbar.py | |||
| @@ -3,6 +3,8 @@ | |||
| 3 | # progressbar - Text progress bar library for Python. | 3 | # progressbar - Text progress bar library for Python. |
| 4 | # Copyright (c) 2005 Nilton Volpato | 4 | # Copyright (c) 2005 Nilton Volpato |
| 5 | # | 5 | # |
| 6 | # (With some small changes after importing into BitBake) | ||
| 7 | # | ||
| 6 | # This library is free software; you can redistribute it and/or | 8 | # This library is free software; you can redistribute it and/or |
| 7 | # modify it under the terms of the GNU Lesser General Public | 9 | # modify it under the terms of the GNU Lesser General Public |
| 8 | # License as published by the Free Software Foundation; either | 10 | # License as published by the Free Software Foundation; either |
| @@ -261,12 +263,14 @@ class ProgressBar(object): | |||
| 261 | now = time.time() | 263 | now = time.time() |
| 262 | self.seconds_elapsed = now - self.start_time | 264 | self.seconds_elapsed = now - self.start_time |
| 263 | self.next_update = self.currval + self.update_interval | 265 | self.next_update = self.currval + self.update_interval |
| 264 | self.fd.write(self._format_line() + '\r') | 266 | output = self._format_line() |
| 267 | self.fd.write(output + '\r') | ||
| 265 | self.fd.flush() | 268 | self.fd.flush() |
| 266 | self.last_update_time = now | 269 | self.last_update_time = now |
| 270 | return output | ||
| 267 | 271 | ||
| 268 | 272 | ||
| 269 | def start(self): | 273 | def start(self, update=True): |
| 270 | """Starts measuring time, and prints the bar at 0%. | 274 | """Starts measuring time, and prints the bar at 0%. |
| 271 | 275 | ||
| 272 | It returns self so you can use it like this: | 276 | It returns self so you can use it like this: |
| @@ -289,8 +293,12 @@ class ProgressBar(object): | |||
| 289 | self.update_interval = self.maxval / self.num_intervals | 293 | self.update_interval = self.maxval / self.num_intervals |
| 290 | 294 | ||
| 291 | 295 | ||
| 292 | self.start_time = self.last_update_time = time.time() | 296 | self.start_time = time.time() |
| 293 | self.update(0) | 297 | if update: |
| 298 | self.last_update_time = self.start_time | ||
| 299 | self.update(0) | ||
| 300 | else: | ||
| 301 | self.last_update_time = 0 | ||
| 294 | 302 | ||
| 295 | return self | 303 | return self |
| 296 | 304 | ||
diff --git a/bitbake/lib/progressbar/widgets.py b/bitbake/lib/progressbar/widgets.py index 6434ad5591..77285ca7a3 100644 --- a/bitbake/lib/progressbar/widgets.py +++ b/bitbake/lib/progressbar/widgets.py | |||
| @@ -353,3 +353,39 @@ class BouncingBar(Bar): | |||
| 353 | if not self.fill_left: rpad, lpad = lpad, rpad | 353 | if not self.fill_left: rpad, lpad = lpad, rpad |
| 354 | 354 | ||
| 355 | return '%s%s%s%s%s' % (left, lpad, marker, rpad, right) | 355 | return '%s%s%s%s%s' % (left, lpad, marker, rpad, right) |
| 356 | |||
| 357 | |||
| 358 | class BouncingSlider(Bar): | ||
| 359 | """ | ||
| 360 | A slider that bounces back and forth in response to update() calls | ||
| 361 | without reference to the actual value. Based on a combination of | ||
| 362 | BouncingBar from a newer version of this module and RotatingMarker. | ||
| 363 | """ | ||
| 364 | def __init__(self, marker='<=>'): | ||
| 365 | self.curmark = -1 | ||
| 366 | self.forward = True | ||
| 367 | Bar.__init__(self, marker=marker) | ||
| 368 | def update(self, pbar, width): | ||
| 369 | left, marker, right = (format_updatable(i, pbar) for i in | ||
| 370 | (self.left, self.marker, self.right)) | ||
| 371 | |||
| 372 | width -= len(left) + len(right) | ||
| 373 | if width < 0: | ||
| 374 | return '' | ||
| 375 | |||
| 376 | if pbar.finished: return '%s%s%s' % (left, width * '=', right) | ||
| 377 | |||
| 378 | self.curmark = self.curmark + 1 | ||
| 379 | position = int(self.curmark % (width * 2 - 1)) | ||
| 380 | if position + len(marker) > width: | ||
| 381 | self.forward = not self.forward | ||
| 382 | self.curmark = 1 | ||
| 383 | position = 1 | ||
| 384 | lpad = ' ' * (position - 1) | ||
| 385 | rpad = ' ' * (width - len(marker) - len(lpad)) | ||
| 386 | |||
| 387 | if not self.forward: | ||
| 388 | temp = lpad | ||
| 389 | lpad = rpad | ||
| 390 | rpad = temp | ||
| 391 | return '%s%s%s%s%s' % (left, lpad, marker, rpad, right) | ||
