forked from pyrocko/pyrocko
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.2 KiB
Python
57 lines
1.2 KiB
Python
# http://pyrocko.org - GPLv3
|
|
#
|
|
# The Pyrocko Developers, 21st Century
|
|
# ---|P------/S----------~Lg----------
|
|
import time
|
|
import logging
|
|
|
|
|
|
logger = logging.getLogger('pyrocko.progress')
|
|
|
|
|
|
class ProgressBar(object):
|
|
def __init__(self, widgets=['progress'], maxval=1, *args, **kwargs):
|
|
self._widgets = widgets
|
|
self._maxval = maxval
|
|
self._val = 0
|
|
self._time = time.time()
|
|
|
|
def label(self):
|
|
for widget in self._widgets:
|
|
if isinstance(widget, str):
|
|
return widget
|
|
|
|
def start(self):
|
|
logger.info('%s...' % self.label())
|
|
return self
|
|
|
|
def update(self, val):
|
|
self._val = val
|
|
t = time.time()
|
|
if t - self._time > 5.0:
|
|
logger.info('%s: %i/%i %3.0f%%' % (
|
|
self.label(),
|
|
self._val,
|
|
self._maxval,
|
|
100.*float(self._val) / float(self._maxval)))
|
|
|
|
self._time = t
|
|
|
|
def finish(self):
|
|
logger.info('%s: done.' % self.label())
|
|
|
|
|
|
class Bar(object):
|
|
def __init__(self, *args, **kwargs):
|
|
pass
|
|
|
|
|
|
class Percentage(object):
|
|
def __init__(self, *args, **kwargs):
|
|
pass
|
|
|
|
|
|
class ETA(object):
|
|
def __init__(self, *args, **kwargs):
|
|
pass
|