first version with sqlalchemy option's storage
[tiramisu.git] / tiramisu / autolib.py
index efb7c0e..eea1c62 100644 (file)
@@ -28,7 +28,7 @@ def carry_out_calculation(name, config, callback, callback_params,
                           index=None, max_len=None):
     """a function that carries out a calculation for an option's value
 
-    :param name: the option name (`opt._name`)
+    :param name: the option name (`opt.impl_getname()`)
     :param config: the context config in order to have
                    the whole options available
     :param callback: the name of the callback function
@@ -129,38 +129,41 @@ def carry_out_calculation(name, config, callback, callback_params,
     # multi's option should have same value for all option
     len_multi = None
 
-    for key, callbacks in callback_params.items():
-        for callbk in callbacks:
-            if isinstance(callbk, tuple):
-                # callbk is something link (opt, True|False)
-                option, force_permissive = callbk
-                path = config.cfgimpl_get_description().impl_get_path_by_opt(
-                    option)
-                # get value
-                try:
-                    value = config._getattr(path, force_permissive=True)
-                except PropertiesOptionError as err:
-                    if force_permissive:
-                        continue
-                    raise ConfigError(_('unable to carry out a calculation, '
-                                        'option {0} has properties: {1} for: '
-                                        '{2}').format(option._name,
-                                                      err.proptype,
-                                                      name))
-                is_multi = option.impl_is_multi()
-                if is_multi:
-                    len_value = len(value)
-                    if len_multi is not None and len_multi != len_value:
-                        raise ConfigError(_('unable to carry out a '
-                                            'calculation, option value with'
-                                            ' multi types must have same '
-                                            'length for: {0}').format(name))
-                    len_multi = len_value
-                    one_is_multi = True
-                tcparams.setdefault(key, []).append((value, is_multi))
-            else:
-                # callbk is a value and not a multi
-                tcparams.setdefault(key, []).append((callbk, False))
+    if callback_params != []:
+        for callbacks in callback_params:
+            key = callbacks.name
+            for callbk in callbacks.params:
+                if callbk.option is not None:
+                    # callbk is something link (opt, True|False)
+                    option = callbk.get_option(config)
+                    force_permissive = callbk.force_permissive
+                    path = config.cfgimpl_get_description().impl_get_path_by_opt(
+                        option)
+                    # get value
+                    try:
+                        value = config._getattr(path, force_permissive=True)
+                    except PropertiesOptionError as err:
+                        if force_permissive:
+                            continue
+                        raise ConfigError(_('unable to carry out a calculation, '
+                                            'option {0} has properties: {1} for: '
+                                            '{2}').format(option.impl_getname(),
+                                                        err.proptype,
+                                                        name))
+                    is_multi = option.impl_is_multi()
+                    if is_multi:
+                        len_value = len(value)
+                        if len_multi is not None and len_multi != len_value:
+                            raise ConfigError(_('unable to carry out a '
+                                                'calculation, option value with'
+                                                ' multi types must have same '
+                                                'length for: {0}').format(name))
+                        len_multi = len_value
+                        one_is_multi = True
+                    tcparams.setdefault(key, []).append((value, is_multi))
+                else:
+                    # callbk is a value and not a multi
+                    tcparams.setdefault(key, []).append((callbk.value, False))
 
     # if one value is a multi, launch several time calculate
     # if index is set, return a value