[docs]classProgressBase:""" Base class for progress indicators. This is *only* a base class, and should not be used directly. For simple console use, see :class:`ConsoleProgress`. Progress indicators are created via factory from various places in the code. The factory is called with ``(message, maximum)`` args and it must return a progress instance with these methods: * :meth:`update()` * :meth:`finish()` Code may call ``update()`` several times while its operation continues; it then ultimately should call ``finish()``. See also :func:`wuttjamaican.util.progress_loop()` and :meth:`wuttjamaican.app.AppHandler.progress_loop()` for a way to do these things automatically from code. :param message: Info message to be displayed along with the progress bar. :param maximum: Max progress value. """def__init__(self,message,maximum):self.message=messageself.maximum=maximum
[docs]defupdate(self,value):""" Update the current progress value. :param value: New progress value to be displayed. """
[docs]deffinish(self):""" Wrap things up for the progress display etc. """
[docs]classConsoleProgress(ProgressBase):""" Provides a console-based progress bar. This is a subclass of :class:`ProgressBase`. Simple usage is like:: from wuttjamaican.progress import ConsoleProgress def action(obj, i): print(obj) items = [1, 2, 3, 4, 5] app = config.get_app() app.progress_loop(action, items, ConsoleProgress, message="printing items") See also :func:`~wuttjamaican.util.progress_loop()`. """def__init__(self,*args,**kwargs):super().__init__(*args)self.stderr=kwargs.get('stderr',sys.stderr)self.stderr.write(f"\n{self.message}...\n")self.bar=Bar(message='',max=self.maximum,width=70,suffix='%(index)d/%(max)d%(percent)d%% ETA %(eta)ds')defupdate(self,value):""" """self.bar.next()deffinish(self):""" """self.bar.finish()