refactor
This commit is contained in:
@ -208,6 +208,12 @@ owners.user = owners.Owner('user')
|
||||
"""forced
|
||||
special owner when value is forced"""
|
||||
owners.forced = owners.Owner('forced')
|
||||
"""meta
|
||||
special owner when value comes from metaconfig"""
|
||||
owners.meta = owners.Owner('meta')
|
||||
|
||||
|
||||
forbidden_owners = (owners.default, owners.forced, owners.meta)
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
@ -298,8 +304,16 @@ class Settings(object):
|
||||
ntime,
|
||||
index)
|
||||
if not is_cached:
|
||||
props = self._p_.getproperties(path,
|
||||
opt.impl_getproperties())
|
||||
meta = self._getcontext().cfgimpl_get_meta()
|
||||
if meta is None:
|
||||
props = self._p_.getproperties(path,
|
||||
opt.impl_getproperties())
|
||||
else:
|
||||
props = meta.cfgimpl_get_settings().getproperties(opt,
|
||||
path,
|
||||
setting_properties,
|
||||
index=index,
|
||||
apply_requires=False)
|
||||
if apply_requires:
|
||||
requires = self.apply_requires(opt,
|
||||
path,
|
||||
@ -326,7 +340,10 @@ class Settings(object):
|
||||
|
||||
def getpermissive(self,
|
||||
path):
|
||||
return self._pp_.getpermissive(path)
|
||||
meta = self._getcontext().cfgimpl_get_meta()
|
||||
if meta is None:
|
||||
return self._pp_.getpermissive(path)
|
||||
return meta.cfgimpl_get_settings().getpermissive(path)
|
||||
|
||||
def apply_requires(self,
|
||||
opt,
|
||||
@ -481,13 +498,11 @@ class Settings(object):
|
||||
opt,
|
||||
path,
|
||||
properties):
|
||||
# force=False):
|
||||
"""save properties for specified path
|
||||
(never save properties if same has option properties)
|
||||
"""
|
||||
if self._getcontext().cfgimpl_get_meta() is not None:
|
||||
raise ConfigError(_('cannot change global property with metaconfig'))
|
||||
#if not force:
|
||||
raise ConfigError(_('cannot change property with metaconfig'))
|
||||
forbidden_properties = forbidden_set_properties & properties
|
||||
if forbidden_properties:
|
||||
raise ConfigError(_('cannot add those properties: {0}').format(
|
||||
@ -516,6 +531,8 @@ class Settings(object):
|
||||
it is better (faster) to set the path parameter
|
||||
instead of passing a :class:`tiramisu.option.Option()` object.
|
||||
"""
|
||||
if self._getcontext().cfgimpl_get_meta() is not None:
|
||||
raise ConfigError(_('cannot change permissive with metaconfig'))
|
||||
if not isinstance(permissives, frozenset):
|
||||
raise TypeError(_('permissive must be a frozenset'))
|
||||
forbidden_permissives = forbidden_set_permissives & permissives
|
||||
@ -529,7 +546,12 @@ class Settings(object):
|
||||
#____________________________________________________________
|
||||
# reset methods
|
||||
|
||||
def reset(self, opt=None, _path=None, all_properties=False):
|
||||
def reset(self,
|
||||
opt=None,
|
||||
_path=None,
|
||||
all_properties=False):
|
||||
if self._getcontext().cfgimpl_get_meta() is not None:
|
||||
raise ConfigError(_('cannot change property with metaconfig'))
|
||||
if all_properties and (_path or opt): # pragma: optional cover
|
||||
raise ValueError(_('opt and all_properties must not be set '
|
||||
'together in reset'))
|
||||
@ -547,105 +569,63 @@ class Settings(object):
|
||||
|
||||
def validate_properties(self,
|
||||
opt_or_descr,
|
||||
is_descr,
|
||||
check_frozen,
|
||||
path,
|
||||
value=None,
|
||||
force_permissive=False,
|
||||
setting_properties=undefined,
|
||||
self_properties=undefined,
|
||||
setting_properties,
|
||||
index=None,
|
||||
debug=False):
|
||||
force_permissive=False):
|
||||
"""
|
||||
validation upon the properties related to `opt_or_descr`
|
||||
|
||||
:param opt_or_descr: an option or an option description object
|
||||
:param force_permissive: behaves as if the permissive property
|
||||
was present
|
||||
:param is_descr: we have to know if we are in an option description,
|
||||
just because the mandatory property
|
||||
doesn't exist here
|
||||
|
||||
:param check_frozen: in the validation process, an option is to be modified,
|
||||
the behavior can be different
|
||||
(typically with the `frozen` property)
|
||||
"""
|
||||
# opt properties
|
||||
if self_properties is not undefined:
|
||||
if not isinstance(self_properties, frozenset):
|
||||
raise Exception('pouet')
|
||||
properties = self_properties
|
||||
else:
|
||||
properties = self.getproperties(opt_or_descr,
|
||||
path,
|
||||
setting_properties=setting_properties,
|
||||
index=index)
|
||||
properties = self.getproperties(opt_or_descr,
|
||||
path,
|
||||
setting_properties=setting_properties,
|
||||
index=index)
|
||||
# calc properties
|
||||
properties &= setting_properties
|
||||
if not is_descr:
|
||||
properties &= setting_properties - set(['frozen'])
|
||||
if not opt_or_descr.impl_is_optiondescription():
|
||||
#mandatory
|
||||
if 'mandatory' in properties and \
|
||||
not self._getcontext().cfgimpl_get_values().isempty(opt_or_descr,
|
||||
value,
|
||||
index=index):
|
||||
properties.remove('mandatory')
|
||||
elif 'empty' in properties and \
|
||||
'empty' in setting_properties and \
|
||||
self._getcontext().cfgimpl_get_values().isempty(opt_or_descr,
|
||||
value,
|
||||
force_allow_empty_list=True,
|
||||
index=index):
|
||||
properties.add('mandatory')
|
||||
# should return 'frozen' only when tried to modify a value
|
||||
if check_frozen and 'everything_frozen' in setting_properties:
|
||||
properties.add('frozen')
|
||||
elif 'frozen' in properties and not check_frozen:
|
||||
properties.remove('frozen')
|
||||
if 'empty' in properties:
|
||||
properties.remove('empty')
|
||||
if 'mandatory' in properties or 'empty' in properties:
|
||||
value = 'pouet'
|
||||
if self.validate_mandatory(opt_or_descr, index, value, properties):
|
||||
properties += set(['mandatory']) - set(['empty'])
|
||||
else:
|
||||
properties -= set(['mandatory', 'empty'])
|
||||
opt_type = 'option'
|
||||
else:
|
||||
opt_type = 'optiondescription'
|
||||
|
||||
# remove permissive properties
|
||||
if properties != frozenset() and (force_permissive is True or
|
||||
'permissive' in setting_properties):
|
||||
if force_permissive is True and properties:
|
||||
# remove global permissive if need
|
||||
properties -= self.get_context_permissive()
|
||||
|
||||
# at this point an option should not remain in properties
|
||||
if properties != frozenset():
|
||||
props = list(properties)
|
||||
datas = {'opt': opt_or_descr,
|
||||
'path': path,
|
||||
'setting_properties': setting_properties,
|
||||
'index': index,
|
||||
'debug': True}
|
||||
if is_descr:
|
||||
opt_type = 'optiondescription'
|
||||
else:
|
||||
opt_type = 'option'
|
||||
if 'frozen' in properties:
|
||||
raise PropertiesOptionError(_('cannot change the value for '
|
||||
'option "{0}" this option is'
|
||||
' frozen').format(
|
||||
opt_or_descr.impl_getname()),
|
||||
props,
|
||||
self,
|
||||
datas,
|
||||
opt_type)
|
||||
else:
|
||||
if len(props) == 1:
|
||||
prop_msg = _('property')
|
||||
else:
|
||||
prop_msg = _('properties')
|
||||
raise PropertiesOptionError(_('cannot access to {0} "{1}" '
|
||||
'because has {2} {3}'
|
||||
'').format(opt_type,
|
||||
opt_or_descr.impl_get_display_name(),
|
||||
prop_msg,
|
||||
display_list(props)),
|
||||
props,
|
||||
self,
|
||||
datas,
|
||||
opt_type)
|
||||
raise PropertiesOptionError(None,
|
||||
properties,
|
||||
self,
|
||||
datas,
|
||||
opt_type)
|
||||
|
||||
def validate_mandatory(self, opt, index, value, properties):
|
||||
values = self._getcontext().cfgimpl_get_values()
|
||||
return 'mandatory' in properties and values.isempty(opt,
|
||||
value,
|
||||
index=index) or \
|
||||
'empty' in properties and values.isempty(opt,
|
||||
value,
|
||||
force_allow_empty_list=True,
|
||||
index=index)
|
||||
|
||||
#____________________________________________________________
|
||||
# read only/read write
|
||||
|
Reference in New Issue
Block a user