api for mandatory
This commit is contained in:
parent
3e8d16ece6
commit
5907f3e663
3 changed files with 38 additions and 29 deletions
|
@ -178,9 +178,13 @@ class Config(object):
|
||||||
if name.startswith('_cfgimpl_'):
|
if name.startswith('_cfgimpl_'):
|
||||||
self.__dict__[name] = value
|
self.__dict__[name] = value
|
||||||
return
|
return
|
||||||
if self._cfgimpl_frozen and getattr(self, name) != value:
|
if self.is_frozen() and getattr(self, name) != value:
|
||||||
raise TypeError("trying to change a value in a frozen config"
|
raise TypeError("trying to change a value in a frozen config"
|
||||||
": {0} {1}".format(name, value))
|
": {0} {1}".format(name, value))
|
||||||
|
if self.is_mandatory() and value == None:
|
||||||
|
raise MandatoryError("trying to reset option: {0} wich lives in a"
|
||||||
|
" mandatory group: {1}".format(name,
|
||||||
|
self._cfgimpl_descr._name))
|
||||||
if type(getattr(self._cfgimpl_descr, name)) != SymLinkOption:
|
if type(getattr(self._cfgimpl_descr, name)) != SymLinkOption:
|
||||||
self._validate(name, getattr(self._cfgimpl_descr, name))
|
self._validate(name, getattr(self._cfgimpl_descr, name))
|
||||||
self.setoption(name, value, self._cfgimpl_owner)
|
self.setoption(name, value, self._cfgimpl_owner)
|
||||||
|
@ -329,14 +333,6 @@ class Config(object):
|
||||||
else:
|
else:
|
||||||
newowner = who
|
newowner = who
|
||||||
if type(child) != SymLinkOption:
|
if type(child) != SymLinkOption:
|
||||||
if child.is_mandatory() and value is None:
|
|
||||||
raise MandatoryError('cannot override value to %s for '
|
|
||||||
'option %s' % (value, name))
|
|
||||||
if name not in self._cfgimpl_values:
|
|
||||||
raise AttributeError('unknown option %s' % (name,))
|
|
||||||
if child.has_callback() or child.isfrozen():
|
|
||||||
raise ConflictConfigError('cannot override value to %s for '
|
|
||||||
'option %s' % (value, name))
|
|
||||||
# if oldowner == who:
|
# if oldowner == who:
|
||||||
# oldvalue = getattr(self, name)
|
# oldvalue = getattr(self, name)
|
||||||
# if oldvalue == value:
|
# if oldvalue == value:
|
||||||
|
@ -442,6 +438,10 @@ class Config(object):
|
||||||
rootconfig = self._cfgimpl_get_toplevel()
|
rootconfig = self._cfgimpl_get_toplevel()
|
||||||
return rootconfig.__dict__['_cfgimpl_frozen']
|
return rootconfig.__dict__['_cfgimpl_frozen']
|
||||||
|
|
||||||
|
def is_mandatory(self):
|
||||||
|
rootconfig = self._cfgimpl_get_toplevel()
|
||||||
|
return rootconfig.__dict__['_cfgimpl_mandatory']
|
||||||
|
|
||||||
def cfgimpl_read_only(self):
|
def cfgimpl_read_only(self):
|
||||||
# hung up on freeze, hidden and disabled concepts
|
# hung up on freeze, hidden and disabled concepts
|
||||||
self.cfgimpl_freeze()
|
self.cfgimpl_freeze()
|
||||||
|
|
|
@ -184,8 +184,17 @@ class Option(HiddenBaseType, DisabledBaseType):
|
||||||
def setoption(self, config, value, who):
|
def setoption(self, config, value, who):
|
||||||
"who is **not necessarily** a owner because it cannot be a list"
|
"who is **not necessarily** a owner because it cannot be a list"
|
||||||
name = self._name
|
name = self._name
|
||||||
if self._frozen:
|
|
||||||
raise TypeError('trying to change a frozen option object: %s' % name)
|
if config.is_mandatory() and child.is_mandatory() and \
|
||||||
|
((self.is_multi() and value == []) or
|
||||||
|
(not self.is_multi() and value is None)):
|
||||||
|
raise MandatoryError('cannot override value to %s for '
|
||||||
|
'option %s' % (value, name))
|
||||||
|
if name not in config._cfgimpl_values:
|
||||||
|
raise AttributeError('unknown option %s' % (name))
|
||||||
|
if config.is_frozen() and (child.has_callback() or child.isfrozen()):
|
||||||
|
raise ConflictConfigError('cannot override value to %s for '
|
||||||
|
'option %s' % (value, name))
|
||||||
# we want the possibility to reset everything
|
# we want the possibility to reset everything
|
||||||
if who == "default" and value is None:
|
if who == "default" and value is None:
|
||||||
self.default = None
|
self.default = None
|
||||||
|
|
Loading…
Reference in a new issue