2
class Progress(object):
3
def __init__(self, units, current, total=None):
8
if self.total is not None:
9
self.percent = 100.0 * current / total
12
if self.total is not None:
13
return "%i of %i %s %.1f%%" % (self.current, self.total, self.units,
16
return "%i %s" (self.current, self.units)
19
def progress_bar(progress):
20
fmt = " %i of %i %s (%.1f%%)"
21
f = fmt % (progress.total, progress.total, progress.units, 100.0)
24
markers = int (float(cols) * progress.current / progress.total)
25
txt = fmt % (progress.current, progress.total, progress.units,
27
sys.stdout.write("\r[%s%s]%s" % ('='*markers, ' '*(cols-markers), txt))
29
def clear_progress_bar():
30
sys.stdout.write('\r%s\r' % (' '*79))