Initial commit
This commit is contained in:
34
benchmark/foundation/progress.py
Normal file
34
benchmark/foundation/progress.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from foundation import logger
|
||||
|
||||
|
||||
def progress(count, total, prefix="", suffix=""):
|
||||
if logger.VERBOSE:
|
||||
return
|
||||
|
||||
size = shutil.get_terminal_size((80, 20))
|
||||
|
||||
if prefix != "":
|
||||
prefix = prefix + " "
|
||||
if suffix != "":
|
||||
suffix = " " + suffix
|
||||
|
||||
bar_len = size.columns - len(prefix) - len(suffix) - 10
|
||||
filled_len = int(round(bar_len * count / float(total)))
|
||||
|
||||
percents = round(100.0 * count / float(total), 1)
|
||||
bar = '=' * filled_len + '-' * (bar_len - filled_len)
|
||||
|
||||
sys.stdout.write('%s[%s] %s%%%s\r' % (prefix, bar, percents, suffix))
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def progressClear():
|
||||
if logger.VERBOSE:
|
||||
return
|
||||
|
||||
size = shutil.get_terminal_size((80, 20))
|
||||
sys.stdout.write(" " * size.columns + "\r")
|
||||
sys.stdout.flush()
|
Reference in New Issue
Block a user