blob: 5c325060625885154a1e59b3519ba880297fd279 [file] [log] [blame]
Alex41485522019-04-12 17:26:18 -05001import sys
2
3
4class Progress(object):
5 def __init__(self, max_index, bar_size=21):
6 self.total = max_index
7 # bar size in symbols
8 self.bar_size = bar_size
9
10 def write_progress(self, index, note=''):
Alex3ebc5632019-04-18 16:47:18 -050011 # calc index and percent values
Alex41485522019-04-12 17:26:18 -050012 _percent = (100 * index) / self.total
13 _index = (self.bar_size * index) / self.total
14 # clear the line
15 sys.stdout.write('\r')
16 # print new progress
17 _format = "[{:"+str(self.bar_size-1)+"}] {}/{} ({}%) {}"
18 sys.stdout.write(_format.format(
19 '='*_index,
20 index,
21 self.total,
22 _percent,
23 note
24 ))
25 sys.stdout.flush()
Alex3ebc5632019-04-18 16:47:18 -050026
Alex41485522019-04-12 17:26:18 -050027 @staticmethod
28 def newline():
29 sys.stdout.write('\n')