From e2ec79063e067216e2b2fff047a55560f975fcca Mon Sep 17 00:00:00 2001 From: gwen Date: Tue, 11 Sep 2012 13:28:37 +0200 Subject: [PATCH] mandatory options --- tiramisu/option.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tiramisu/option.py b/tiramisu/option.py index 284f830..fed7c5d 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -185,22 +185,26 @@ class Option(HiddenBaseType, DisabledBaseType): "who is **not necessarily** a owner because it cannot be a list" 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 if who == "default" and value is None: self.default = None return if not self.validate(value): 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": # changes the default value (and therefore resets the previous value) if self._validate(value): @@ -240,7 +244,7 @@ class Option(HiddenBaseType, DisabledBaseType): def unfreeze(self): self._frozen = False - def isfrozen(self): + def is_frozen(self): return self._frozen # ____________________________________________________________ def is_multi(self): @@ -527,6 +531,7 @@ def apply_requires(opt, config): if action not in available_actions: raise RequiresError("malformed requirements" " for option: {0}".format(opt._name)) + # FIXME generic programming opt.property_launch(action, False) getattr(opt, action)() #.hide() or show() or... matches = True else: # option doesn't exist ! should not happen...