requirement are now a dictionary (not anymore a tuple)

This commit is contained in:
2013-06-29 18:41:14 +02:00
parent e501c6d12d
commit 9b134c3aa7
8 changed files with 252 additions and 142 deletions

View File

@ -334,6 +334,9 @@ class Setting(object):
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 = {}
@ -341,74 +344,42 @@ def apply_requires(opt, config):
action = require[2]
trigger_actions.setdefault(action, []).append(require)
return trigger_actions
#for symlink
if hasattr(opt, '_requires') and opt._requires is not None:
# 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:
if len(require) == 3:
option, expected, action = require
inverse = False
transitive = True
same_action = True
elif len(require) == 4:
option, expected, action, inverse = require
transitive = True
same_action = True
elif len(require) == 5:
option, expected, action, inverse, transitive = require
same_action = True
elif len(require) == 6:
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 value == expected:
matches = True
if inverse:
#temporary remove, definitive if no value != expected
#matches
setting.remove(action)
else:
setting.append(action)
## the calculation cannot be carried out
break
if value != expected:
matches = True
if inverse:
setting.append(action)
# the calculation cannot be carried out
break
else:
#temporary remove, definitive if no value != expected
#matches
setting.remove(action)
# no requirement has been triggered, then just reverse the action
if not matches:
if inverse:
setting.append(action)
else:
setting.remove(action)
# 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)