mandatory options

This commit is contained in:
gwen 2012-09-11 13:28:37 +02:00
parent 5907f3e663
commit e2ec79063e
1 changed files with 16 additions and 11 deletions

View File

@ -185,22 +185,26 @@ class Option(HiddenBaseType, DisabledBaseType):
"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 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
return return
if not self.validate(value): if not self.validate(value):
raise ConfigError('invalid value %s for option %s' % (value, name)) raise ConfigError('invalid value %s for option %s' % (value, name))
if self.is_mandatory():
# value shall not be '' for a mandatory option
# so '' is considered as being None
if value == '':
value = None
if config.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 (self.has_callback() or self.isfrozen()):
raise ConflictConfigError('cannot override value to %s for '
'option %s' % (value, name))
if who == "default": if who == "default":
# changes the default value (and therefore resets the previous value) # changes the default value (and therefore resets the previous value)
if self._validate(value): if self._validate(value):
@ -240,7 +244,7 @@ class Option(HiddenBaseType, DisabledBaseType):
def unfreeze(self): def unfreeze(self):
self._frozen = False self._frozen = False
def isfrozen(self): def is_frozen(self):
return self._frozen return self._frozen
# ____________________________________________________________ # ____________________________________________________________
def is_multi(self): def is_multi(self):
@ -527,6 +531,7 @@ def apply_requires(opt, config):
if action not in available_actions: if action not in available_actions:
raise RequiresError("malformed requirements" raise RequiresError("malformed requirements"
" for option: {0}".format(opt._name)) " for option: {0}".format(opt._name))
# FIXME generic programming opt.property_launch(action, False)
getattr(opt, action)() #.hide() or show() or... getattr(opt, action)() #.hide() or show() or...
matches = True matches = True
else: # option doesn't exist ! should not happen... else: # option doesn't exist ! should not happen...