fill for multi types
authorgwen <gremond@cadoles.com>
Wed, 4 Jul 2012 15:00:28 +0000 (17:00 +0200)
committergwen <gremond@cadoles.com>
Wed, 4 Jul 2012 15:00:28 +0000 (17:00 +0200)
autolib.py
config.py

index e339829..b4df145 100644 (file)
@@ -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)
index f9610ff..7684b77 100644 (file)
--- 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()