pass force_properties to value's _setitem and remove config's setoption

This commit is contained in:
2013-04-17 23:19:53 +02:00
parent 5e67522f91
commit d5e1cb6576
5 changed files with 42 additions and 29 deletions

View File

@ -23,7 +23,7 @@
#from inspect import getmembers, ismethod
from tiramisu.error import PropertiesOptionError, ConflictOptionError
from tiramisu.option import OptionDescription, Option, SymLinkOption
from tiramisu.setting import groups, Setting, apply_requires
from tiramisu.setting import groups, Setting
from tiramisu.value import Values
from tiramisu.i18n import _
@ -78,7 +78,8 @@ class SubConfig(object):
return homeconfig.__setattr__(name, value)
child = getattr(self._cfgimpl_descr, name)
if type(child) != SymLinkOption:
self.setoption(name, child, value, force_permissive)
self.cfgimpl_get_values()._setitem(child, value,
force_permissive=force_permissive)
else:
child.setoption(self.cfgimpl_get_context(), value)
@ -127,22 +128,10 @@ class SubConfig(object):
name))
return SubConfig(opt_or_descr, self._cfgimpl_context)
else:
value = self.cfgimpl_get_values()._getitem(opt_or_descr,
validate=validate,
force_properties=force_properties,
force_permissive=force_permissive)
return value
def setoption(self, name, child, value, force_permissive=False):
"""effectively modifies the value of an Option()
(typically called by the __setattr__)
"""
#needed ?
apply_requires(child, self)
if child not in self._cfgimpl_descr._children[1]:
raise AttributeError(_('unknown option {0}').format(name))
self.cfgimpl_get_values()[child] = value
return self.cfgimpl_get_values()._getitem(opt_or_descr,
validate=validate,
force_properties=force_properties,
force_permissive=force_permissive)
def cfgimpl_get_home_by_path(self, path, force_permissive=False, force_properties=None):
""":returns: tuple (config, name)"""
@ -399,7 +388,7 @@ class Config(SubConfig):
#except PropertiesOptionError, e:
# raise e # HiddenOptionError or DisabledOptionError
child = getattr(homeconfig._cfgimpl_descr, name)
homeconfig.setoption(name, child, value)
self.cfgimpl_get_values()[child] = value
elif len(candidates) > 1:
raise ConflictOptionError(
_('more than one option that ends with {}').format(key))

View File

@ -144,10 +144,9 @@ class Values(object):
return value
def __setitem__(self, opt, value):
#valid config
#FIXME:
force_permissive = False
force_properties = None
self._setitem(opt, value)
def _setitem(self, opt, value, force_permissive=False, force_properties=None):
setting = self.context.cfgimpl_get_settings()
setting.validate_properties(opt, False, True,
value=value, force_permissive=force_permissive,