1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
5import time
6import logging
9logger = logging.getLogger('pyrocko.progress')
12class ProgressBar(object):
13 def __init__(self, widgets=['progress'], maxval=1, *args, **kwargs):
14 self._widgets = widgets
15 self._maxval = maxval
16 self._val = 0
17 self._time = time.time()
19 def label(self):
20 for widget in self._widgets:
21 if isinstance(widget, str):
22 return widget
24 def start(self):
25 logger.info('%s...' % self.label())
26 return self
28 def update(self, val):
29 self._val = val
30 t = time.time()
31 if t - self._time > 5.0:
32 logger.info('%s: %i/%i %3.0f%%' % (
33 self.label(),
34 self._val,
35 self._maxval,
36 100.*float(self._val) / float(self._maxval)))
38 self._time = t
40 def finish(self):
41 logger.info('%s: done.' % self.label())
44class Bar(object):
45 def __init__(self, *args, **kwargs):
46 pass
49class Percentage(object):
50 def __init__(self, *args, **kwargs):
51 pass
54class ETA(object):
55 def __init__(self, *args, **kwargs):
56 pass