Skip to content
Snippets Groups Projects
Commit 168f927c authored by Vekhir's avatar Vekhir
Browse files

Add compatibility for progressbar 2.5 as available on Debian

parent 828a33ab
No related branches found
No related tags found
No related merge requests found
...@@ -207,9 +207,11 @@ class ProgressBar: ...@@ -207,9 +207,11 @@ class ProgressBar:
def __init__(self): def __init__(self):
try: try:
from progressbar.widgets import WidgetBase from progressbar.widgets import WidgetBase
self.compatibility_mode = False
except ImportError: except ImportError:
# Fallback to the older Debian version # Fallback to the older Debian version
from progressbar import Widget as WidgetBase from progressbar import Widget as WidgetBase
self.compatibility_mode = True
self.msg = "" self.msg = ""
...@@ -224,6 +226,10 @@ class ProgressBar: ...@@ -224,6 +226,10 @@ class ProgressBar:
# Print the last `width` characters with an ellipsis. # Print the last `width` characters with an ellipsis.
return "…{}".format(msg[-width + 1 :]) return "…{}".format(msg[-width + 1 :])
def update(self, pbar, _observer=self):
"""Compatibility method for progressbar 2.5"""
return self(pbar, None, _observer)
class OurProgressBar(progressbar.ProgressBar): class OurProgressBar(progressbar.ProgressBar):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# Remove after https://github.com/niltonvolpato/python-progressbar/pull/57 is fixed. # Remove after https://github.com/niltonvolpato/python-progressbar/pull/57 is fixed.
...@@ -235,12 +241,21 @@ class ProgressBar: ...@@ -235,12 +241,21 @@ class ProgressBar:
def _needs_update(self): def _needs_update(self):
return True return True
def _need_update(self):
"""Compatibility method for progressbar 2.5"""
return self._needs_update()
def erase_line(self): def erase_line(self):
if self.erase_to_eol: if self.erase_to_eol:
self.fd.buffer.write(self.erase_to_eol) self.fd.buffer.write(self.erase_to_eol)
self.fd.flush() self.fd.flush()
def finish(self): def finish(self):
if self.compatibility_mode:
# setting self.finished = True makes super().finish() a noop
self.finished = True
self.update(self.maxval)
super().finish() super().finish()
# Clear the progress bar after completion # Clear the progress bar after completion
self.erase_line() self.erase_line()
...@@ -260,10 +275,18 @@ class ProgressBar: ...@@ -260,10 +275,18 @@ class ProgressBar:
" ", " ",
) )
) )
if self.compatibility_mode:
self.bar.start()
def notify(self, current, total, msg): def notify(self, current, total, msg):
self.msg = msg self.msg = msg
if self.compatibility_mode:
self.bar.maxval = total
self.bar.value = current
self.bar.update()
return
self.bar.max_value = total self.bar.max_value = total
self.bar.update(current) self.bar.update(current)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment