simplify find() in api and PropertiesOptionError
This commit is contained in:
@ -373,6 +373,7 @@ class Settings(object):
|
||||
apply_requires)
|
||||
if apply_requires:
|
||||
props |= self.apply_requires(path,
|
||||
opt.impl_getrequires(),
|
||||
index,
|
||||
False,
|
||||
config_bag)
|
||||
@ -405,9 +406,11 @@ class Settings(object):
|
||||
|
||||
def apply_requires(self,
|
||||
path,
|
||||
current_requires,
|
||||
index,
|
||||
debug,
|
||||
config_bag):
|
||||
readable,
|
||||
config_bag,
|
||||
name=None):
|
||||
"""carries out the jit (just in time) requirements between options
|
||||
|
||||
a requirement is a tuple of this form that comes from the option's
|
||||
@ -451,11 +454,10 @@ class Settings(object):
|
||||
:param path: the option's path in the config
|
||||
:type path: str
|
||||
"""
|
||||
opt = config_bag.option
|
||||
current_requires = opt.impl_getrequires()
|
||||
#current_requires = opt.impl_getrequires()
|
||||
|
||||
# filters the callbacks
|
||||
if debug:
|
||||
if readable:
|
||||
calc_properties = {}
|
||||
else:
|
||||
calc_properties = set()
|
||||
@ -467,25 +469,21 @@ class Settings(object):
|
||||
all_properties = None
|
||||
for requires in current_requires:
|
||||
for require in requires:
|
||||
exps, action, inverse, \
|
||||
transitive, same_action, operator = require
|
||||
exps, action, inverse, transitive, same_action, operator = require
|
||||
breaked = False
|
||||
for exp in exps:
|
||||
option, expected = exp
|
||||
for option, expected in exps:
|
||||
reqpath = option.impl_getpath(context)
|
||||
if reqpath == path or reqpath.startswith(path + '.'): # pragma: optional cover
|
||||
#FIXME c'est un peut tard !
|
||||
if reqpath == path or reqpath.startswith(path + '.'):
|
||||
raise RequirementError(_("malformed requirements "
|
||||
"imbrication detected for option:"
|
||||
" '{0}' with requirement on: "
|
||||
"'{1}'").format(path, reqpath))
|
||||
if not option.impl_is_multi():
|
||||
idx = None
|
||||
is_indexed = False
|
||||
elif option.impl_is_master_slaves('slave'):
|
||||
idx = None
|
||||
is_indexed = False
|
||||
if option.impl_is_master_slaves('slave'):
|
||||
idx = index
|
||||
is_indexed = False
|
||||
else:
|
||||
idx = None
|
||||
elif option.impl_is_multi():
|
||||
is_indexed = True
|
||||
sconfig_bag = config_bag.copy('nooption')
|
||||
sconfig_bag.option = option
|
||||
@ -497,40 +495,44 @@ class Settings(object):
|
||||
if is_indexed:
|
||||
value = value[index]
|
||||
except PropertiesOptionError as err:
|
||||
properties = err.proptype
|
||||
if not transitive:
|
||||
if all_properties is None:
|
||||
all_properties = []
|
||||
for requires_ in opt.impl_getrequires():
|
||||
for requires_ in current_requires:
|
||||
for require_ in requires_:
|
||||
all_properties.append(require_[1])
|
||||
if not set(err.proptype) - set(all_properties):
|
||||
if not set(properties) - set(all_properties):
|
||||
continue
|
||||
properties = err.proptype
|
||||
if same_action and action not in properties: # pragma: optional cover
|
||||
if same_action and action not in properties:
|
||||
if len(properties) == 1:
|
||||
prop_msg = _('property')
|
||||
else:
|
||||
prop_msg = _('properties')
|
||||
raise RequirementError(_('cannot access to option "{0}" because '
|
||||
'required option "{1}" has {2} {3}'
|
||||
'').format(opt.impl_get_display_name(),
|
||||
'').format(name,
|
||||
option.impl_get_display_name(),
|
||||
prop_msg,
|
||||
display_list(list(properties))))
|
||||
orig_value = err
|
||||
# transitive action, force expected
|
||||
value = expected[0]
|
||||
inverse = False
|
||||
else:
|
||||
orig_value = value
|
||||
if (not inverse and value in expected or
|
||||
inverse and value not in expected):
|
||||
# transitive action, add action
|
||||
if operator != 'and':
|
||||
if debug:
|
||||
if isinstance(orig_value, PropertiesOptionError):
|
||||
for msg in orig_value._settings.apply_requires(**orig_value._datas).values():
|
||||
calc_properties.setdefault(action, []).extend(msg)
|
||||
else:
|
||||
if readable:
|
||||
for msg in self.apply_requires(err.path,
|
||||
err.requires,
|
||||
err.index,
|
||||
True,
|
||||
err.config_bag).values():
|
||||
calc_properties.setdefault(action, []).extend(msg)
|
||||
else:
|
||||
calc_properties.add(action)
|
||||
breaked = True
|
||||
break
|
||||
else:
|
||||
if (not inverse and value in expected or
|
||||
inverse and value not in expected):
|
||||
if operator != 'and':
|
||||
if readable:
|
||||
if not inverse:
|
||||
msg = _('the value of "{0}" is {1}')
|
||||
else:
|
||||
@ -538,12 +540,12 @@ class Settings(object):
|
||||
calc_properties.setdefault(action, []).append(
|
||||
msg.format(option.impl_get_display_name(),
|
||||
display_list(expected, 'or', add_quote=True)))
|
||||
else:
|
||||
calc_properties.add(action)
|
||||
breaked = True
|
||||
break
|
||||
elif operator == 'and':
|
||||
break
|
||||
else:
|
||||
calc_properties.add(action)
|
||||
breaked = True
|
||||
break
|
||||
elif operator == 'and':
|
||||
break
|
||||
else:
|
||||
if operator == 'and':
|
||||
calc_properties.add(action)
|
||||
@ -691,11 +693,6 @@ class Settings(object):
|
||||
config_bag)
|
||||
config_bag.properties = self_properties
|
||||
properties = self_properties & config_bag.setting_properties - {'frozen', 'mandatory', 'empty'}
|
||||
if not opt.impl_is_optiondescription():
|
||||
opt_type = 'option'
|
||||
else:
|
||||
opt_type = 'optiondescription'
|
||||
|
||||
|
||||
# remove permissive properties
|
||||
if (config_bag.force_permissive is True or 'permissive' in config_bag.setting_properties) and properties:
|
||||
@ -703,15 +700,11 @@ class Settings(object):
|
||||
properties -= self.get_context_permissive()
|
||||
# at this point an option should not remain in properties
|
||||
if properties != frozenset():
|
||||
datas = {'path': path,
|
||||
'config_bag': config_bag,
|
||||
'index': index,
|
||||
'debug': True}
|
||||
raise PropertiesOptionError(None,
|
||||
raise PropertiesOptionError(path,
|
||||
index,
|
||||
config_bag,
|
||||
properties,
|
||||
self,
|
||||
datas,
|
||||
opt_type)
|
||||
self)
|
||||
|
||||
def validate_mandatory(self,
|
||||
path,
|
||||
@ -735,17 +728,15 @@ class Settings(object):
|
||||
index=index):
|
||||
is_mandatory = True
|
||||
if is_mandatory:
|
||||
datas = {'path': path,
|
||||
'config_bag': config_bag,
|
||||
'index': index,
|
||||
'debug': True}
|
||||
raise PropertiesOptionError(None,
|
||||
raise PropertiesOptionError(path,
|
||||
index,
|
||||
config_bag,
|
||||
['mandatory'],
|
||||
self,
|
||||
datas,
|
||||
'option')
|
||||
self)
|
||||
|
||||
def validate_frozen(self,
|
||||
path,
|
||||
index,
|
||||
config_bag):
|
||||
if config_bag.setting_properties and \
|
||||
('everything_frozen' in config_bag.setting_properties or
|
||||
@ -753,7 +744,11 @@ class Settings(object):
|
||||
not ((config_bag.force_permissive is True or
|
||||
'permissive' in config_bag.setting_properties) and
|
||||
'frozen' in self.get_context_permissive()):
|
||||
return True
|
||||
raise PropertiesOptionError(path,
|
||||
index,
|
||||
config_bag,
|
||||
['frozen'],
|
||||
self)
|
||||
return False
|
||||
#____________________________________________________________
|
||||
# read only/read write
|
||||
|
Reference in New Issue
Block a user