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.
This commit is contained in:
2018-08-02 17:38:10 +02:00
parent de682f8e8e
commit 7f42fdf5e8
40 changed files with 391 additions and 8998 deletions

View File

@@ -1,34 +1,77 @@
import shutil
import sys
from foundation import logger
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=""):
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()
"""
Report new progress status of the current task.
"""
PROGRESS_PROVIDER.progress(count, total, prefix, suffix)
def progressClear():
if logger.VERBOSE:
return
"""
Clear all possible progress bar lines in the ocnsole.
"""
PROGRESS_PROVIDER.clear()
size = shutil.get_terminal_size((80, 20))
sys.stdout.write(" " * size.columns + "\r")
sys.stdout.flush()
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()