From: Michael Tremer Date: Wed, 7 Dec 2016 20:07:46 +0000 (+0100) Subject: progressbar: Add widget to show any errors X-Git-Tag: 0.9.28~1285^2~1395 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87981056ea4cb4266428b82a1758c202d000498e;p=pakfire.git progressbar: Add widget to show any errors Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/ui/progressbar.py b/src/pakfire/ui/progressbar.py index 8805ed362..143434b87 100644 --- a/src/pakfire/ui/progressbar.py +++ b/src/pakfire/ui/progressbar.py @@ -40,6 +40,7 @@ class ProgressBar(object): self.time_start = None self.finished = False + self.error = None # Use the error console as default output. self.fd = sys.stderr @@ -69,12 +70,15 @@ class ProgressBar(object): return self - def finish(self): + def finish(self, error=None): if self.finished: return self.finished = True + # Save an exception we could print + self.error = error + # Complete the progress bar. self.update(self.value_max) @@ -187,7 +191,7 @@ class ProgressBar(object): return self def __exit__(self, type, value, traceback): - self.finish() + self.finish(error=value) def format_updatable(widget, pbar): @@ -203,6 +207,15 @@ class Widget(object): def update(self, pbar): pass + +class WidgetError(Widget): + def update(self, pbar): + if pbar.finished and pbar.error: + return _("Error: %s") % pbar.error + + return "" + + class WidgetFill(Widget): expandable = True