merge from master
authorEmmanuel Garette <egarette@cadoles.com>
Tue, 20 Aug 2013 14:33:32 +0000 (16:33 +0200)
committerEmmanuel Garette <egarette@cadoles.com>
Tue, 20 Aug 2013 14:33:32 +0000 (16:33 +0200)
1  2 
tiramisu/config.py
tiramisu/option.py
tiramisu/setting.py
tiramisu/value.py

Simple merge
Simple merge
@@@ -287,8 -281,8 +288,8 @@@ class Settings(object)
              properties -= frozenset(('mandatory', 'frozen'))
          else:
              if 'mandatory' in properties and \
-                     not self.context.cfgimpl_get_values()._isempty(opt_or_descr,
-                                                                    value):
 -                not self.context.cfgimpl_get_values()._is_empty(opt_or_descr,
 -                                                                    value):
++                    not self.context.cfgimpl_get_values()._isempty(
++                        opt_or_descr, value):
                  properties.remove('mandatory')
              if is_write and 'everything_frozen' in self_properties:
                  properties.add('frozen')
              else:
                  raise PropertiesOptionError(_("trying to access to an option "
                                                "named: {0} with properties {1}"
-                                               "").format(opt_or_descr._name, str(props)), props)
+                                               "").format(opt_or_descr._name,
+                                               str(props)), props)
  
 -    def _get_permissive(self, opt=None):
 -        return self._permissives.get(opt, frozenset())
 -
 +    #FIXME should be setpermissive
      def set_permissive(self, permissive, opt=None):
          if not isinstance(permissive, tuple):
              raise TypeError(_('permissive must be a tuple'))
@@@ -95,12 -78,13 +95,13 @@@ class Values(object)
              opt.impl_validate(opt.impl_getdefault(), self.context,
                                'validator' in setting)
              self.context.cfgimpl_reset_cache()
-             if opt.impl_is_multi() and opt.impl_get_multitype() == multitypes.master:
+             if (opt.impl_is_multi() and
 -                opt.impl_get_multitype() == multitypes.master):
++                    opt.impl_get_multitype() == multitypes.master):
                  for slave in opt.impl_get_master_slaves():
 -                    self._reset(slave)
 -            del(self._values[opt])
 +                    self.reset(slave)
 +            self._p_.resetvalue(key)
  
 -    def _is_empty(self, opt, value):
 +    def _isempty(self, opt, value):
          "convenience method to know if an option is empty"
          empty = opt._empty
          if (not opt.impl_is_multi() and (value is None or value == empty)) or \
          # options with callbacks
          setting = self.context.cfgimpl_get_settings()
          is_frozen = 'frozen' in setting[opt]
-         #if value is callback and is not set or frozen with force_default_on_freeze
-         if opt.impl_has_callback() and (self.is_default_owner(opt) or
-                                         (is_frozen and
-                                          'force_default_on_freeze' in setting[opt])):
+         # if value is callback and is not set
+         # or frozen with force_default_on_freeze
+         if opt.impl_has_callback() and (
 -           self.is_default_owner(opt) or
 -           (is_frozen and
 -           'force_default_on_freeze' in setting[opt])):
++                self.is_default_owner(opt) or
++                (is_frozen and 'force_default_on_freeze' in setting[opt])):
              no_value_slave = False
-             if opt.impl_is_multi() and opt.impl_get_multitype() == multitypes.slave:
-                 masterp = self.context.cfgimpl_get_description().impl_get_path_by_opt(
-                     opt.impl_get_master_slaves())
+             if (opt.impl_is_multi() and
 -                opt.impl_get_multitype() == multitypes.slave):
 -                masterp = self.context.cfgimpl_get_description(
 -                          ).impl_get_path_by_opt(
 -                          opt.impl_get_master_slaves())
++                    opt.impl_get_multitype() == multitypes.slave):
++                masterp = self._get_opt_path(opt.impl_get_master_slaves())
                  mastervalue = getattr(self.context, masterp)
                  lenmaster = len(mastervalue)
                  if lenmaster == 0:
  
              if not no_value_slave:
                  value = self._getcallback_value(opt)
-                 if opt.impl_is_multi() and opt.impl_get_multitype() == multitypes.slave:
+                 if (opt.impl_is_multi() and
 -                    opt.impl_get_multitype() == multitypes.slave):
++                        opt.impl_get_multitype() == multitypes.slave):
                      if not isinstance(value, list):
                          value = [value for i in range(lenmaster)]
              if opt.impl_is_multi():
          self._setvalue(opt, value, force_permissive=force_permissive,
                         is_write=is_write)
  
-     def _setvalue(self, opt, value, force_permissive=False, force_properties=None,
+     def _setvalue(self, opt, value, force_permissive=False,
+                   force_properties=None,
                    is_write=True, validate_properties=True):
          self.context.cfgimpl_reset_cache()
 -        setting = self.context.cfgimpl_get_settings()
          if validate_properties:
 +            setting = self.context.cfgimpl_get_settings()
              setting.validate_properties(opt, False, is_write,
                                          value=value,
                                          force_permissive=force_permissive,
@@@ -281,13 -273,13 +285,15 @@@ class Multi(list)
              self.opt.impl_get_master_slaves())
          mastervalue = getattr(self.context, masterp)
          masterlen = len(mastervalue)
--        if len(value) > masterlen or (len(value) < masterlen and
-                                       not self.context.cfgimpl_get_values().is_default_owner(self.opt)):
 -           not self.context.cfgimpl_get_values().is_default_owner(self.opt)):
++        valuelen = len(value)
++        if valuelen > masterlen or (valuelen < masterlen and
++                                    not self.context.cfgimpl_get_values(
++                                    ).is_default_owner(self.opt)):
              raise SlaveError(_("invalid len for the slave: {0}"
                                 " which has {1} as master").format(
                                     self.opt._name, masterp))
--        elif len(value) < masterlen:
--            for num in range(0, masterlen - len(value)):
++        elif valuelen < masterlen:
++            for num in range(0, masterlen - valuelen):
                  value.append(self.opt.impl_getdefault_multi())
          #else: same len so do nothing
          return value
                  self.opt._validate(value)
              except ValueError, err:
                  raise ValueError(_("invalid value {0} "
--                                   "for option {1}: {2}").format(str(value),
-                                                                  self.opt._name, err))
 -                                   self.opt._name, err))
++                                   "for option {1}: {2}"
++                                   "").format(str(value),
++                                              self.opt._name, err))
  
      def pop(self, key, force=False):
          """the list value can be updated (poped)
                      values = self.context.cfgimpl_get_values()
                      if not values.is_default_owner(slave):
                          #get multi without valid properties
-                         values.getitem(slave, validate_properties=False).pop(key, force=True)
+                         values.getitem(slave,
+                                        validate_properties=False
+                                        ).pop(key, force=True)
          #set value without valid properties
 -        self.context.cfgimpl_get_values(
 -            )._setvalue(self.opt,
 -                        self,
 -                        validate_properties=not force)
 -        return super(Multi, self).pop(key)
 +        ret = super(Multi, self).pop(key)
 +        self.context.cfgimpl_get_values()._setvalue(self.opt, self, validate_properties=not force)
 +        return ret