fix configurable observer
This commit is contained in:
@@ -46,6 +46,8 @@
|
||||
from settingsValidators import *
|
||||
import util
|
||||
from observer import ProgressBarObserver, LoggingObserver
|
||||
import platform
|
||||
import sys
|
||||
|
||||
# renders is a dictionary mapping strings to dicts. These dicts describe the
|
||||
# configuration for that render. Therefore, the validator for 'renders' is set
|
||||
@@ -96,6 +98,8 @@ processes = Setting(required=True, validator=int, default=-1)
|
||||
memcached_host = Setting(required=False, validator=str, default=None)
|
||||
|
||||
if platform.system() == 'Windows' or not sys.stderr.isatty():
|
||||
observer = LoggingObserver()
|
||||
obs = LoggingObserver()
|
||||
else:
|
||||
observer = ProgressBarObserver()
|
||||
obs = ProgressBarObserver()
|
||||
|
||||
observer = Setting(required=True, validator=validateObserver, default=obs)
|
||||
|
||||
@@ -71,7 +71,7 @@ def validateRenderMode(mode):
|
||||
|
||||
if isinstance(mode, rendermodes.RenderPrimitive):
|
||||
mode = [mode]
|
||||
|
||||
|
||||
if not isinstance(mode, list):
|
||||
raise ValidationException("%r is not a valid list of rendermodes. It should be a list"% mode)
|
||||
|
||||
@@ -119,7 +119,7 @@ def validateImgQuality(qual):
|
||||
|
||||
def validateBGColor(color):
|
||||
"""BG color must be an HTML color, with an option leading # (hash symbol)
|
||||
returns an (r,b,g) 3-tuple
|
||||
returns an (r,b,g) 3-tuple
|
||||
"""
|
||||
if type(color) == str:
|
||||
if color[0] != "#":
|
||||
@@ -182,13 +182,19 @@ def validateCrop(value):
|
||||
value[1],value[3] = value[3],value[1]
|
||||
return value
|
||||
|
||||
def validateObserver(observer):
|
||||
if all(map(lambda m: hasattr(observer, m), ['start', 'add', 'update', 'finish'])):
|
||||
return observer
|
||||
else:
|
||||
raise ValidationException("%r does not look like an observer" % repr(observer))
|
||||
|
||||
def make_dictValidator(keyvalidator, valuevalidator):
|
||||
"""Compose and return a dict validator -- a validator that validates each
|
||||
key and value in a dictionary.
|
||||
|
||||
The arguments are the validator function to use for the keys, and the
|
||||
validator function to use for the values.
|
||||
|
||||
|
||||
"""
|
||||
def v(d):
|
||||
newd = util.OrderedDict()
|
||||
|
||||
Reference in New Issue
Block a user