2021-05-19 18:07:42 +02:00
|
|
|
# coding: utf8
|
|
|
|
|
|
|
|
""" Progress bar """
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import progressbar
|
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2021-05-19 19:19:57 +02:00
|
|
|
|
|
|
|
class Pbar: # pylint: disable=useless-object-inheritance
|
2021-05-19 18:07:42 +02:00
|
|
|
"""
|
|
|
|
Progress bar
|
|
|
|
|
|
|
|
This class abstract a progress bar that could be enable/disable by
|
|
|
|
configuration/script parameters.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__pbar = None
|
|
|
|
__count = None
|
|
|
|
|
|
|
|
def __init__(self, name, maxval, enabled=True):
|
|
|
|
if enabled and maxval:
|
|
|
|
self.__count = 0
|
|
|
|
self.__pbar = progressbar.ProgressBar(
|
|
|
|
widgets=[
|
|
|
|
name + ': ',
|
|
|
|
progressbar.Percentage(),
|
|
|
|
' ',
|
|
|
|
progressbar.Bar(),
|
|
|
|
' ',
|
|
|
|
progressbar.SimpleProgress(),
|
|
|
|
progressbar.ETA()
|
|
|
|
],
|
|
|
|
maxval=maxval
|
|
|
|
).start()
|
|
|
|
else:
|
|
|
|
log.info(name)
|
|
|
|
|
|
|
|
def increment(self, step=None):
|
|
|
|
"""
|
|
|
|
Increment the progress bar
|
|
|
|
|
|
|
|
:param step: The step (optional, default: 1)
|
|
|
|
"""
|
|
|
|
if self.__pbar:
|
|
|
|
self.__count += step if step else 1
|
|
|
|
self.__pbar.update(self.__count)
|
|
|
|
|
|
|
|
def finish(self):
|
|
|
|
""" Finish the progress bar """
|
|
|
|
if self.__pbar:
|
|
|
|
self.__pbar.finish()
|