0

fix configurable observer

This commit is contained in:
aheadley
2012-03-22 21:19:56 -04:00
parent 863c6b1154
commit 99f2cae7a8
2 changed files with 15 additions and 5 deletions

View File

@@ -46,6 +46,8 @@
from settingsValidators import * from settingsValidators import *
import util import util
from observer import ProgressBarObserver, LoggingObserver from observer import ProgressBarObserver, LoggingObserver
import platform
import sys
# renders is a dictionary mapping strings to dicts. These dicts describe the # renders is a dictionary mapping strings to dicts. These dicts describe the
# configuration for that render. Therefore, the validator for 'renders' is set # 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) memcached_host = Setting(required=False, validator=str, default=None)
if platform.system() == 'Windows' or not sys.stderr.isatty(): if platform.system() == 'Windows' or not sys.stderr.isatty():
observer = LoggingObserver() obs = LoggingObserver()
else: else:
observer = ProgressBarObserver() obs = ProgressBarObserver()
observer = Setting(required=True, validator=validateObserver, default=obs)

View File

@@ -71,7 +71,7 @@ def validateRenderMode(mode):
if isinstance(mode, rendermodes.RenderPrimitive): if isinstance(mode, rendermodes.RenderPrimitive):
mode = [mode] mode = [mode]
if not isinstance(mode, list): if not isinstance(mode, list):
raise ValidationException("%r is not a valid list of rendermodes. It should be a list"% mode) 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): def validateBGColor(color):
"""BG color must be an HTML color, with an option leading # (hash symbol) """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 type(color) == str:
if color[0] != "#": if color[0] != "#":
@@ -182,13 +182,19 @@ def validateCrop(value):
value[1],value[3] = value[3],value[1] value[1],value[3] = value[3],value[1]
return value 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): def make_dictValidator(keyvalidator, valuevalidator):
"""Compose and return a dict validator -- a validator that validates each """Compose and return a dict validator -- a validator that validates each
key and value in a dictionary. key and value in a dictionary.
The arguments are the validator function to use for the keys, and the The arguments are the validator function to use for the keys, and the
validator function to use for the values. validator function to use for the values.
""" """
def v(d): def v(d):
newd = util.OrderedDict() newd = util.OrderedDict()