Remove 'build_actions' in 'apply_requires', now 'validate_requires_arg' build requires with tuple of tuple

New _requires format:
- requirement (like old format)
- tuple of requirements, each items are a tuple of requirement with same action
This commit is contained in:
Emmanuel Garette 2013-07-01 11:55:32 +02:00
parent 9b134c3aa7
commit b8bfa02e02
2 changed files with 48 additions and 57 deletions

View File

@ -813,11 +813,13 @@ class OptionDescription(BaseInformation):
def validate_requires_arg(requires, name):
"""check malformed requirements
and tranform dict to tuple"""
and tranform dict to internal tuple
"""
if requires is None:
return None
ret_requires = []
ret_requires = {}
config_action = {}
for require in requires:
if not type(require) == dict:
raise ValueError(_("malformed requirements type for option:"
@ -868,7 +870,7 @@ def validate_requires_arg(requires, name):
else:
config_action[action] = inverse
ret_requires.append((option, expected, action, inverse, transitive,
same_action))
ret_requires.setdefault(action, []).append((option, expected, action,
inverse, transitive, same_action))
return tuple(ret_requires)
return tuple(tuple(ret) for ret in ret_requires.values())

View File

@ -214,7 +214,7 @@ class Setting(object):
if exp < created:
return props
if is_apply_req:
apply_requires(opt, self.context)
self.apply_requires(opt)
props = self._properties.get(opt, opt._properties)
self._set_cache(opt, props, exp)
return props
@ -331,55 +331,44 @@ class Setting(object):
else:
self._cache.clear()
def apply_requires(self, opt):
"carries out the jit (just in time requirements between options"
if opt._requires is None:
return
def apply_requires(opt, config):
"carries out the jit (just in time requirements between options"
if opt._requires is None:
return
def build_actions(requires):
"action are hide, show, enable, disable..."
trigger_actions = {}
for require in requires:
action = require[2]
trigger_actions.setdefault(action, []).append(require)
return trigger_actions
# filters the callbacks
settings = config.cfgimpl_get_settings()
setting = Property(settings, settings._get_properties(opt, False), opt)
trigger_actions = build_actions(opt._requires)
descr = config.cfgimpl_get_context().cfgimpl_get_description()
optpath = descr.impl_get_path_by_opt(opt)
for requires in trigger_actions.values():
matches = False
for require in requires:
option, expected, action, inverse, transitive, same_action = require
path = descr.impl_get_path_by_opt(option)
if path == optpath or path.startswith(optpath + '.'):
raise RequirementError(_("malformed requirements "
"imbrication detected for option: '{0}' "
"with requirement on: '{1}'").format(optpath, path))
try:
value = config.cfgimpl_get_context()._getattr(path, force_permissive=True)
except PropertiesOptionError, err:
if not transitive:
continue
properties = err.proptype
if same_action and action not in properties:
raise RequirementError(_("option '{0}' has requirement's property error: "
"{1} {2}").format(opt._name, path, properties))
#transitive action, force expected
value = expected
inverse = False
except AttributeError:
raise AttributeError(_("required option not found: "
"{0}").format(path))
if not inverse and value == expected or inverse and value != expected:
matches = True
setting.append(action)
## the calculation cannot be carried out
break
# no requirement has been triggered, then just reverse the action
if not matches:
setting.remove(action)
# filters the callbacks
setting = Property(self, self._get_properties(opt, False), opt)
descr = self.context.cfgimpl_get_description()
optpath = descr.impl_get_path_by_opt(opt)
for requires in opt._requires:
matches = False
for require in requires:
option, expected, action, inverse, transitive, same_action = require
path = descr.impl_get_path_by_opt(option)
if path == optpath or path.startswith(optpath + '.'):
raise RequirementError(_("malformed requirements "
"imbrication detected for option: '{0}' "
"with requirement on: '{1}'").format(optpath, path))
try:
value = self.context._getattr(path, force_permissive=True)
except PropertiesOptionError, err:
if not transitive:
continue
properties = err.proptype
if same_action and action not in properties:
raise RequirementError(_("option '{0}' has requirement's property error: "
"{1} {2}").format(opt._name, path, properties))
#transitive action, force expected
value = expected
inverse = False
except AttributeError:
raise AttributeError(_("required option not found: "
"{0}").format(path))
if not inverse and value == expected or inverse and value != expected:
matches = True
setting.append(action)
## the calculation cannot be carried out
break
# no requirement has been triggered, then just reverse the action
if not matches:
setting.remove(action)