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): def validate_requires_arg(requires, name):
"""check malformed requirements """check malformed requirements
and tranform dict to tuple""" and tranform dict to internal tuple
"""
if requires is None: if requires is None:
return None return None
ret_requires = [] ret_requires = {}
config_action = {} config_action = {}
for require in requires: for require in requires:
if not type(require) == dict: if not type(require) == dict:
raise ValueError(_("malformed requirements type for option:" raise ValueError(_("malformed requirements type for option:"
@ -868,7 +870,7 @@ def validate_requires_arg(requires, name):
else: else:
config_action[action] = inverse config_action[action] = inverse
ret_requires.append((option, expected, action, inverse, transitive, ret_requires.setdefault(action, []).append((option, expected, action,
same_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: if exp < created:
return props return props
if is_apply_req: if is_apply_req:
apply_requires(opt, self.context) self.apply_requires(opt)
props = self._properties.get(opt, opt._properties) props = self._properties.get(opt, opt._properties)
self._set_cache(opt, props, exp) self._set_cache(opt, props, exp)
return props return props
@ -331,27 +331,16 @@ class Setting(object):
else: else:
self._cache.clear() self._cache.clear()
def apply_requires(self, opt):
def apply_requires(opt, config):
"carries out the jit (just in time requirements between options" "carries out the jit (just in time requirements between options"
if opt._requires is None: if opt._requires is None:
return 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 # filters the callbacks
settings = config.cfgimpl_get_settings() setting = Property(self, self._get_properties(opt, False), opt)
setting = Property(settings, settings._get_properties(opt, False), opt) descr = self.context.cfgimpl_get_description()
trigger_actions = build_actions(opt._requires)
descr = config.cfgimpl_get_context().cfgimpl_get_description()
optpath = descr.impl_get_path_by_opt(opt) optpath = descr.impl_get_path_by_opt(opt)
for requires in trigger_actions.values(): for requires in opt._requires:
matches = False matches = False
for require in requires: for require in requires:
option, expected, action, inverse, transitive, same_action = require option, expected, action, inverse, transitive, same_action = require
@ -361,7 +350,7 @@ def apply_requires(opt, config):
"imbrication detected for option: '{0}' " "imbrication detected for option: '{0}' "
"with requirement on: '{1}'").format(optpath, path)) "with requirement on: '{1}'").format(optpath, path))
try: try:
value = config.cfgimpl_get_context()._getattr(path, force_permissive=True) value = self.context._getattr(path, force_permissive=True)
except PropertiesOptionError, err: except PropertiesOptionError, err:
if not transitive: if not transitive:
continue continue