This repository has been archived on 2023-02-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-benchmark-bundle/benchmark/foundation/progress.py
Sergey Sharybin 7f42fdf5e8 Initial implementation of blender benchmark addon
Just some glue logic to query progress and results from benchmark.

Needed to move files around, so oth standalone and addon are happy.
2018-08-02 17:38:55 +02:00

78 lines
1.9 KiB
Python

import shutil
import sys
from . import logger
class DefaultProgressProvider:
"""
Default progress provider implementation, which draws progress
bar in the console, unless current logging is set to evrbose mode.
"""
def progress(self, 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 clear(self):
if logger.VERBOSE:
return
size = shutil.get_terminal_size((80, 20))
sys.stdout.write(" " * size.columns + "\r")
sys.stdout.flush()
def step(self, step_name):
pass
PROGRESS_PROVIDER = DefaultProgressProvider()
def progress(count, total, prefix="", suffix=""):
"""
Report new progress status of the current task.
"""
PROGRESS_PROVIDER.progress(count, total, prefix, suffix)
def progressClear():
"""
Clear all possible progress bar lines in the ocnsole.
"""
PROGRESS_PROVIDER.clear()
def step(step_name):
PROGRESS_PROVIDER.step(step_name)
def setProvider(provider):
"""
Override progress provider with a given name.
Is used by glue logic to hijack progress and do smart things.
"""
global PROGRESS_PROVIDER
PROGRESS_PROVIDER = provider
def restoreDefaultProvider():
"""
Restore default progress provider.
"""
global PROGRESS_PROVIDER
PROGRESS_PROVIDER = DefaultProgressProvider()