values are in value objects now
[tiramisu.git] / tiramisu / option.py
index e805213..2dc6221 100644 (file)
@@ -26,7 +26,7 @@ from tiramisu.error import (ConfigError, ConflictConfigError, NotFoundError,
     RequiresError, RequirementRecursionError, MandatoryError,
     PropertiesOptionError)
 from tiramisu.autolib import carry_out_calculation
-from tiramisu.setting import settings, groups, owners
+from tiramisu.setting import groups, owners
 
 requires_actions = [('hide', 'show'), ('enable', 'disable'), ('freeze', 'unfreeze')]
 
@@ -53,13 +53,15 @@ class Multi(list):
         super(Multi, self).__init__(lst)
 
     def __setitem__(self, key, value):
-        self._setvalue(value, key, who=settings.get_owner())
+        self._setvalue(value, key,
+                who=self.config._cfgimpl_context._cfgimpl_settings.get_owner())
 
     def append(self, value):
         """the list value can be updated (appened)
         only if the option is a master
         """
-        self._setvalue(value, who=settings.get_owner())
+        self._setvalue(value,
+                who=self.config._cfgimpl_context._cfgimpl_settings.get_owner())
 
     def _setvalue(self, value, key=None, who=None):
         if value != None:
@@ -76,7 +78,7 @@ class Multi(list):
                 raise TypeError("invalid owner {0} for the value {1}".format(
                                 str(who), str(value)))
             self.opt.setowner(self.config, getattr(owners, who))
-        self.config._cfgimpl_previous_values[self.opt._name] = oldvalue
+        self.config._cfgimpl_context._cfgimpl_values.previous_values[self.opt] = oldvalue
 
     def pop(self, key):
         """the list value can be updated (poped)
@@ -86,8 +88,9 @@ class Multi(list):
         :return: the requested element
 
         """
-        self.opt.setowner(self.config, settings.get_owner())
-        self.config._cfgimpl_previous_values[self.opt._name] = list(self)
+        self.opt.setowner(self.config,
+                    self.config._cfgimpl_context._cfgimpl_settings.get_owner())
+        self.config._cfgimpl_context._cfgimpl_values.previous_values[self.opt] = list(self)
         return super(Multi, self).pop(key)
 # ____________________________________________________________
 #
@@ -260,11 +263,11 @@ class Option(HiddenBaseType, DisabledBaseType):
         if not isinstance(owner, owners.Owner):
             raise ConfigError("invalid type owner for option: {0}".format(
                     str(name)))
-        config._cfgimpl_value_owners[name] = owner
+        config._cfgimpl_context._cfgimpl_values.owners[self] = owner
 
     def getowner(self, config):
         "config *must* be only the **parent** config (not the toplevel config)"
-        return config._cfgimpl_value_owners[self._name]
+        return config._cfgimpl_context._cfgimpl_values.owners[self]
 
     def reset(self, config):
         """resets the default value and owner
@@ -285,7 +288,8 @@ class Option(HiddenBaseType, DisabledBaseType):
         """
         name = self._name
         rootconfig = config._cfgimpl_get_toplevel()
-        if not self.validate(value, settings.validator):
+        if not self.validate(value,
+                        config._cfgimpl_context._cfgimpl_settings.validator):
             raise ConfigError('invalid value %s for option %s' % (value, name))
         if self.is_mandatory():
             # value shall not be '' for a mandatory option
@@ -294,26 +298,28 @@ class Option(HiddenBaseType, DisabledBaseType):
                 value = None
             if self.is_multi() and '' in value:
                 value = Multi([{'': None}.get(i, i) for i in value], config, self)
-            if settings.is_mandatory() and ((self.is_multi() and value == []) or \
+            if config._cfgimpl_context._cfgimpl_settings.is_mandatory() \
+                and ((self.is_multi() and value == []) or \
                 (not self.is_multi() and value is None)):
                 raise MandatoryError('cannot change the value to %s for '
               'option %s' % (value, name))
-        if name not in config._cfgimpl_values:
+        if self not in config._cfgimpl_context._cfgimpl_values:
             raise AttributeError('unknown option %s' % (name))
 
-        if settings.is_frozen_for_everything():
+        if config._cfgimpl_context._cfgimpl_settings.is_frozen_for_everything():
             raise TypeError("cannot set a value to the option {} if the whole "
             "config has been frozen".format(name))
 
-        if settings.is_frozen() and self.is_frozen():
+        if config._cfgimpl_context._cfgimpl_settings.is_frozen() \
+                                                        and self.is_frozen():
             raise TypeError('cannot change the value to %s for '
                'option %s this option is frozen' % (str(value), name))
         apply_requires(self, config)
-        if type(config._cfgimpl_values[name]) == Multi:
-            config._cfgimpl_previous_values[name] = list(config._cfgimpl_values[name])
+        if type(config._cfgimpl_context._cfgimpl_values[self]) == Multi:
+            config._cfgimpl_context._cfgimpl_values.previous_values[self] = list(config._cfgimpl_context._cfgimpl_values[self])
         else:
-            config._cfgimpl_previous_values[name] = config._cfgimpl_values[name]
-        config._cfgimpl_values[name] = value
+            config._cfgimpl_context._cfgimpl_values.previous_values[self] = config._cfgimpl_context._cfgimpl_values[self]
+        config._cfgimpl_context._cfgimpl_values[self] = value
 
     def getkey(self, value):
         return value
@@ -577,7 +583,8 @@ def apply_requires(opt, config, permissive=False):
                 except PropertiesOptionError, err:
                     properties = err.proptype
                     if permissive:
-                        for perm in settings.permissive:
+                        for perm in \
+                                config._cfgimpl_context._cfgimpl_settings.permissive:
                             if perm in properties:
                                 properties.remove(perm)
                     if properties != []: