MEGA -- DB
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
import re
|
||||
|
||||
# https://stackoverflow.com/questions/3160699/python-progress-bar
|
||||
|
||||
class ProgressBar(object):
|
||||
DEFAULT = 'Progress: %(bar)s %(percent)3d%%'
|
||||
FULL = '%(bar)s %(current)d/%(total)d (%(percent)3d%%) %(remaining)d to go'
|
||||
|
||||
def __init__(self, title, total, width=40, fmt=DEFAULT, symbol='=',
|
||||
output=sys.stderr):
|
||||
assert len(symbol) == 1
|
||||
|
||||
self.title = title
|
||||
self.total = total
|
||||
self.width = width
|
||||
self.symbol = symbol
|
||||
self.output = output
|
||||
self.fmt = re.sub(r'(?P<name>%\(.+?\))d',
|
||||
r'\g<name>%dd' % len(str(total)), fmt)
|
||||
|
||||
self.current = 0
|
||||
|
||||
def __call__(self):
|
||||
percent = self.current / float(self.total)
|
||||
size = int(self.width * percent)
|
||||
remaining = self.total - self.current
|
||||
bar = self.title + ' [' + self.symbol * size + ' ' * (self.width - size) + ']'
|
||||
|
||||
args = {
|
||||
'total': self.total,
|
||||
'bar': bar,
|
||||
'current': self.current,
|
||||
'percent': percent * 100,
|
||||
'remaining': remaining
|
||||
}
|
||||
print('\r' + self.fmt % args, file=self.output, end='')
|
||||
|
||||
def done(self):
|
||||
self.current = self.total
|
||||
self()
|
||||
print('', file=self.output)
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
def y_n_question(question_str):
|
||||
|
||||
yes = {'yes','y', 'ye', ''}
|
||||
no = {'no','n'}
|
||||
|
||||
while True:
|
||||
sys.stdout.write(question_str + " [Y/n]: ")
|
||||
choice = input().lower()
|
||||
if choice in yes:
|
||||
return True
|
||||
elif choice in no:
|
||||
return False
|
||||
else:
|
||||
sys.stdout.write("\nPlease respond with 'yes' or 'no'\n")
|
||||
continue
|
||||
Reference in New Issue
Block a user