From 52bc3f6507b367976ab5e8020757d370b41ea6ba Mon Sep 17 00:00:00 2001 From: gwen Date: Wed, 4 Jul 2012 17:00:28 +0200 Subject: [PATCH] fill for multi types --- autolib.py | 2 -- config.py | 30 ++++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/autolib.py b/autolib.py index e339829..b4df145 100644 --- a/autolib.py +++ b/autolib.py @@ -26,8 +26,6 @@ special_owners = ['auto', 'fill'] def special_owner_factory(name, owner, value, 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, # we have to carry out a calculation return calc_factory(name, callback, callback_params, config) diff --git a/config.py b/config.py index f9610ff..7684b77 100644 --- a/config.py +++ b/config.py @@ -197,11 +197,37 @@ class Config(object): owner = self._cfgimpl_value_owners[name] # 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_params=opt_or_descr.getcallback_params(), 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 if not isinstance(opt_or_descr, OptionDescription): homeconfig = self._cfgimpl_get_toplevel()