fill for multi types

This commit is contained in:
gwen 2012-07-04 17:00:28 +02:00
parent bc0061ca5b
commit 52bc3f6507
2 changed files with 28 additions and 4 deletions

View File

@ -26,8 +26,6 @@ special_owners = ['auto', 'fill']
def special_owner_factory(name, owner, value, def special_owner_factory(name, owner, value,
callback, callback_params=None, config=None): callback, callback_params=None, config=None):
if owner == 'fill' and value != None:
return value
# in case of an 'auto' and a 'fill' without a value, # in case of an 'auto' and a 'fill' without a value,
# we have to carry out a calculation # we have to carry out a calculation
return calc_factory(name, callback, callback_params, config) return calc_factory(name, callback, callback_params, config)

View File

@ -197,11 +197,37 @@ class Config(object):
owner = self._cfgimpl_value_owners[name] owner = self._cfgimpl_value_owners[name]
# special owners # special owners
if owner in special_owners: if owner in special_owners:
return special_owner_factory(name, owner, value = self._cfgimpl_values[name]
value=self._cfgimpl_values[name], if opt_or_descr.is_multi():
if owner == 'fill' and None not in value:
return value
else:
if owner == 'fill' and value != None:
return value
result = special_owner_factory(name, owner,
value=value,
callback=opt_or_descr.getcallback(), callback=opt_or_descr.getcallback(),
callback_params=opt_or_descr.getcallback_params(), callback_params=opt_or_descr.getcallback_params(),
config=self._cfgimpl_get_toplevel()) config=self._cfgimpl_get_toplevel())
# this result **shall not** be a list
# for example, [1, 2, 3, None] -> [1, 2, 3, result]
#
if type(result) == list:
raise ConfigError('invalid calculated value returned'
' for option {0} : shall not be a list'.format(name))
if not opt_or_descr._validate(result):
raise ConfigError('invalid calculated value returned'
' for option {0}'.format(name))
if opt_or_descr.is_multi():
_result = []
for val in value:
if val == None:
val = result
_result.append(val)
else:
_result = result
return _result
# mandatory options # mandatory options
if not isinstance(opt_or_descr, OptionDescription): if not isinstance(opt_or_descr, OptionDescription):
homeconfig = self._cfgimpl_get_toplevel() homeconfig = self._cfgimpl_get_toplevel()