setting_properties > properties
This commit is contained in:
parent
ee1f07ce7e
commit
493cec1b80
|
@ -457,7 +457,7 @@ def test_cache_master_and_slaves_master():
|
|||
#has value
|
||||
idx_val2 = 0
|
||||
val_val2 = None
|
||||
val_val2_props = {idx_val2: (val1_val2_props, None)}
|
||||
val_val2_props = {idx_val2: (val1_val2_props, None), None: (set(), None)}
|
||||
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)},
|
||||
'val1': {None: (val1_props, None)},
|
||||
'val1.val1': {None: (val1_val1_props, None)},
|
||||
|
|
|
@ -118,7 +118,6 @@ class CommonTiramisu(TiramisuHelp):
|
|||
self.option_bag.path,
|
||||
self.option_bag.index,
|
||||
self.option_bag.config_bag)
|
||||
if self.option_bag.config_bag.setting_properties:
|
||||
self.option_bag.config_bag.context.cfgimpl_get_settings().validate_properties(self.option_bag)
|
||||
index = self.option_bag.index
|
||||
if index is not None:
|
||||
|
@ -594,7 +593,7 @@ class TiramisuOption(CommonTiramisu):
|
|||
groups.GroupType):
|
||||
raise TypeError(_("unknown group_type: {0}").format(group_type))
|
||||
def _filter(opt):
|
||||
if self.config_bag.setting_properties:
|
||||
if self.config_bag.properties:
|
||||
name = opt.impl_getname()
|
||||
path = subconfig._get_subpath(name)
|
||||
option_bag = OptionBag()
|
||||
|
@ -731,7 +730,7 @@ class TiramisuContextProperty(TiramisuContext):
|
|||
settings = self.config_bag.context.cfgimpl_get_settings()
|
||||
settings.read_only()
|
||||
try:
|
||||
del self.config_bag.setting_properties
|
||||
del self.config_bag.properties
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
|
@ -742,7 +741,7 @@ class TiramisuContextProperty(TiramisuContext):
|
|||
# #FIXME ?
|
||||
settings.set_context_permissive(frozenset(['hidden']))
|
||||
try:
|
||||
del self.config_bag.setting_properties
|
||||
del self.config_bag.properties
|
||||
except AttributeError:
|
||||
pass
|
||||
#/FIXME ?
|
||||
|
@ -762,7 +761,7 @@ class TiramisuContextProperty(TiramisuContext):
|
|||
|
||||
def get(self):
|
||||
"""get all configuration properties"""
|
||||
return set(self.config_bag.setting_properties)
|
||||
return set(self.config_bag.properties)
|
||||
|
||||
def set(self, props):
|
||||
"""personalise configuration properties"""
|
||||
|
@ -850,11 +849,11 @@ class TiramisuContextOption(TiramisuContext):
|
|||
withoption=None,
|
||||
fullpath=False):
|
||||
"""return dict with path as key and value"""
|
||||
if not self.config_bag.setting_properties:
|
||||
if not self.config_bag.properties:
|
||||
config_bag = self.config_bag
|
||||
else:
|
||||
config_bag = self.config_bag.copy()
|
||||
config_bag.setting_properties = self.config_bag.setting_properties - {'warnings'}
|
||||
config_bag.properties = self.config_bag.properties - {'warnings'}
|
||||
return config_bag.context.make_dict(config_bag,
|
||||
flatten=flatten,
|
||||
fullpath=fullpath,
|
||||
|
@ -867,7 +866,7 @@ class TiramisuContextOption(TiramisuContext):
|
|||
recursive=False):
|
||||
"""list content of an optiondescription"""
|
||||
def _filter(opt):
|
||||
if self.config_bag.setting_properties:
|
||||
if self.config_bag.properties:
|
||||
name = opt.impl_getname()
|
||||
option_bag = OptionBag()
|
||||
option_bag.set_option(opt,
|
||||
|
@ -885,7 +884,7 @@ class TiramisuContextOption(TiramisuContext):
|
|||
if recursive:
|
||||
if group_type:
|
||||
raise APIError(_('recursive with group_type is not implemented yet'))
|
||||
if self.config_bag.setting_properties:
|
||||
if self.config_bag.properties:
|
||||
raise APIError(_('not implemented yet'))
|
||||
for option in self.config_bag.context.cfgimpl_get_description()._cache_paths[1]:
|
||||
if type == 'optiondescription' and not isinstance(option, OptionDescription):
|
||||
|
@ -976,14 +975,14 @@ class TiramisuAPI(TiramisuHelp):
|
|||
if subfunc == 'forcepermissive':
|
||||
if isinstance(self._config, ConfigBag):
|
||||
config = self._config.config
|
||||
force = not self._config.setting_properties
|
||||
force = not self._config.properties
|
||||
else:
|
||||
config = self._config
|
||||
force = None
|
||||
config_bag = ConfigBag(context=config,
|
||||
force_permissive=True)
|
||||
if force is True:
|
||||
config_bag.setting_properties = frozenset()
|
||||
config_bag.properties = frozenset()
|
||||
return TiramisuAPI(config_bag)
|
||||
elif subfunc == 'unrestraint':
|
||||
if isinstance(self._config, ConfigBag):
|
||||
|
@ -993,7 +992,7 @@ class TiramisuAPI(TiramisuHelp):
|
|||
config = self._config
|
||||
force = None
|
||||
config_bag = ConfigBag(context=config)
|
||||
config_bag.setting_properties = frozenset()
|
||||
config_bag.properties = frozenset()
|
||||
if force is not None:
|
||||
config_bag.force_permissive = force
|
||||
return TiramisuAPI(config_bag)
|
||||
|
|
|
@ -83,7 +83,7 @@ def manager_callback(callbk: Union[ParamOption, ParamValue],
|
|||
if option_bag.fromconsistency:
|
||||
soption_bag.fromconsistency = option_bag.fromconsistency.copy()
|
||||
if opt == option:
|
||||
soption_bag.config_bag.setting_properties = frozenset()
|
||||
soption_bag.config_bag.properties = frozenset()
|
||||
soption_bag.config_bag.remove_validation()
|
||||
try:
|
||||
# get value
|
||||
|
|
|
@ -252,7 +252,6 @@ class SubConfig(object):
|
|||
if option_bag.option.impl_is_symlinkoption():
|
||||
raise ConfigError(_("can't assign to a SymLinkOption"))
|
||||
context = option_bag.config_bag.context
|
||||
if option_bag.config_bag.setting_properties:
|
||||
context.cfgimpl_get_settings().validate_properties(option_bag)
|
||||
self.cfgimpl_get_description().impl_validate_value(option_bag.option,
|
||||
value,
|
||||
|
@ -295,7 +294,6 @@ class SubConfig(object):
|
|||
else:
|
||||
fromconsistency = None
|
||||
|
||||
if option_bag.config_bag.setting_properties:
|
||||
self.cfgimpl_get_settings().validate_properties(option_bag)
|
||||
return SubConfig(option_bag.option,
|
||||
self._impl_context,
|
||||
|
@ -334,7 +332,6 @@ class SubConfig(object):
|
|||
return context.getattr(soption_bag.path,
|
||||
soption_bag)
|
||||
|
||||
if config_bag.setting_properties:
|
||||
self.cfgimpl_get_settings().validate_properties(option_bag)
|
||||
|
||||
if option.impl_is_master_slaves('slave'):
|
||||
|
@ -405,7 +402,7 @@ class SubConfig(object):
|
|||
config_bag)
|
||||
if byvalue is not undefined and not _filter_by_value(option_bag):
|
||||
continue
|
||||
elif config_bag.setting_properties:
|
||||
elif config_bag.properties:
|
||||
#remove option with propertyerror, ...
|
||||
try:
|
||||
if '.' in path:
|
||||
|
@ -566,7 +563,6 @@ class SubConfig(object):
|
|||
option_bag.config_bag)
|
||||
ret.append(self.getattr(name,
|
||||
soption_bag))
|
||||
elif option_bag.config_bag.setting_properties:
|
||||
self.cfgimpl_get_settings().validate_properties(option_bag)
|
||||
else:
|
||||
ret = self.getattr(name,
|
||||
|
|
|
@ -197,7 +197,7 @@ class Option(OnlyOption):
|
|||
force_index = None
|
||||
|
||||
if check_error and config_bag is not undefined and \
|
||||
not 'validator' in config_bag.setting_properties:
|
||||
not 'validator' in config_bag.properties:
|
||||
# just to check propertieserror
|
||||
self.valid_consistency(option_bag,
|
||||
value,
|
||||
|
@ -620,7 +620,7 @@ class Option(OnlyOption):
|
|||
else:
|
||||
all_cons_vals.append((is_multi, opt_value))
|
||||
all_cons_opts.append(opt)
|
||||
if config_bag is not undefined and not 'validator' in config_bag.setting_properties:
|
||||
if config_bag is not undefined and not 'validator' in config_bag.properties:
|
||||
return
|
||||
all_values = []
|
||||
if length is None:
|
||||
|
|
|
@ -159,8 +159,9 @@ class OptionBag:
|
|||
|
||||
|
||||
class ConfigBag:
|
||||
__slots__ = ('context', # link to the current config (context)
|
||||
'setting_properties', # properties for current config
|
||||
__slots__ = ('context', # link to the current context
|
||||
'properties', # properties for current context
|
||||
#'permissives', # permissives for current context
|
||||
'force_permissive', # force permissive
|
||||
'_validate', # validate
|
||||
)
|
||||
|
@ -172,19 +173,19 @@ class ConfigBag:
|
|||
setattr(self, key, value)
|
||||
|
||||
def __getattr__(self, key):
|
||||
if key == 'setting_properties':
|
||||
self.setting_properties = self.context.cfgimpl_get_settings().get_context_properties()
|
||||
return self.setting_properties
|
||||
if key == 'properties':
|
||||
self.properties = self.context.cfgimpl_get_settings().get_context_properties()
|
||||
return self.properties
|
||||
raise KeyError('unknown key {} for ConfigBag'.format(key))
|
||||
|
||||
def remove_validation(self):
|
||||
self._validate = 'validator' in self.setting_properties
|
||||
self._validate = 'validator' in self.properties
|
||||
if self._validate:
|
||||
self.setting_properties = frozenset(self.setting_properties - {'validator'})
|
||||
self.properties = frozenset(self.properties - {'validator'})
|
||||
|
||||
def restore_validation(self):
|
||||
if self._validate:
|
||||
self.setting_properties = frozenset(self.setting_properties | {'validator'})
|
||||
self.properties = frozenset(self.properties | {'validator'})
|
||||
|
||||
def copy(self):
|
||||
kwargs = {}
|
||||
|
@ -341,7 +342,7 @@ class Settings(object):
|
|||
is_cached, props = self._p_.getcache(None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
{},
|
||||
None,
|
||||
'context_props')
|
||||
if not is_cached:
|
||||
|
@ -372,7 +373,7 @@ class Settings(object):
|
|||
path = opt.impl_getpath(self._getcontext())
|
||||
|
||||
if apply_requires:
|
||||
props = config_bag.setting_properties
|
||||
props = config_bag.properties
|
||||
is_cached, props = self._p_.getcache(path,
|
||||
expires_time,
|
||||
index,
|
||||
|
@ -398,8 +399,9 @@ class Settings(object):
|
|||
self._p_.setcache(path,
|
||||
index,
|
||||
props,
|
||||
config_bag.setting_properties,
|
||||
config_bag.setting_properties)
|
||||
config_bag.properties,
|
||||
#FIXME
|
||||
config_bag.properties)
|
||||
return props
|
||||
|
||||
def get_context_permissive(self):
|
||||
|
@ -502,7 +504,7 @@ class Settings(object):
|
|||
idx,
|
||||
config_bag)
|
||||
if option_bag.option == option:
|
||||
soption_bag.config_bag.setting_properties = frozenset()
|
||||
soption_bag.config_bag.properties = frozenset()
|
||||
soption_bag.config_bag.remove_validation()
|
||||
soption_bag.apply_requires = False
|
||||
try:
|
||||
|
@ -694,13 +696,15 @@ class Settings(object):
|
|||
:param force_permissive: behaves as if the permissive property
|
||||
was present
|
||||
"""
|
||||
# calc properties
|
||||
config_bag = option_bag.config_bag
|
||||
properties = option_bag.properties & config_bag.setting_properties - {'frozen', 'mandatory', 'empty'}
|
||||
if not config_bag.properties:
|
||||
return
|
||||
# calc properties
|
||||
properties = option_bag.properties & config_bag.properties - {'frozen', 'mandatory', 'empty'}
|
||||
|
||||
# remove permissive properties
|
||||
if (config_bag.force_permissive is True or \
|
||||
'permissive' in config_bag.setting_properties) and properties:
|
||||
'permissive' in config_bag.properties) and properties:
|
||||
# remove global permissive if need
|
||||
properties -= self.get_context_permissive()
|
||||
# at this point an option should not remain in properties
|
||||
|
@ -712,11 +716,11 @@ class Settings(object):
|
|||
def validate_mandatory(self,
|
||||
value,
|
||||
option_bag):
|
||||
if 'mandatory' in option_bag.config_bag.setting_properties:
|
||||
if 'mandatory' in option_bag.config_bag.properties:
|
||||
values = self._getcontext().cfgimpl_get_values()
|
||||
is_mandatory = False
|
||||
if (option_bag.config_bag.force_permissive is True or \
|
||||
'permissive' in option_bag.config_bag.setting_properties) and \
|
||||
'permissive' in option_bag.config_bag.properties) and \
|
||||
'mandatory' in self.get_context_permissive():
|
||||
pass
|
||||
elif 'mandatory' in option_bag.properties and values.isempty(option_bag.option,
|
||||
|
@ -735,11 +739,11 @@ class Settings(object):
|
|||
|
||||
def validate_frozen(self,
|
||||
option_bag):
|
||||
if option_bag.config_bag.setting_properties and \
|
||||
('everything_frozen' in option_bag.config_bag.setting_properties or
|
||||
if option_bag.config_bag.properties and \
|
||||
('everything_frozen' in option_bag.config_bag.properties or
|
||||
'frozen' in option_bag.properties) and \
|
||||
not ((option_bag.config_bag.force_permissive is True or
|
||||
'permissive' in option_bag.config_bag.setting_properties) and
|
||||
'permissive' in option_bag.config_bag.properties) and
|
||||
'frozen' in self.get_context_permissive()):
|
||||
raise PropertiesOptionError(option_bag,
|
||||
['frozen'],
|
||||
|
|
|
@ -37,7 +37,8 @@ class Cache(DictCache):
|
|||
"""add val in cache for a specified path
|
||||
if slave, add index
|
||||
"""
|
||||
if props is None or 'cache' in props or \
|
||||
#FIXME self_props n'est pas None !
|
||||
if 'cache' in props or \
|
||||
(self_props is not None and 'cache' in self_props):
|
||||
if DEBUG:
|
||||
print('setcache {} with index {} and value {} in {} ({})'.format(path, index, val,
|
||||
|
@ -61,7 +62,7 @@ class Cache(DictCache):
|
|||
self_props,
|
||||
type_):
|
||||
no_cache = False, None
|
||||
if props is None or 'cache' in props:
|
||||
if 'cache' in props:
|
||||
indexed = self._getcache(path, index)
|
||||
if indexed is None:
|
||||
return no_cache
|
||||
|
@ -74,7 +75,7 @@ class Cache(DictCache):
|
|||
# so value is self_props
|
||||
self_props = value
|
||||
# recheck "cache" value
|
||||
if props is None or 'cache' in props or (self_props is not None and 'cache' in props):
|
||||
if 'cache' in props or (self_props is not None and 'cache' in props):
|
||||
if expires_time and timestamp and \
|
||||
(props is not None and 'expire' in props or \
|
||||
self_props is not None and 'expire' in self_props):
|
||||
|
|
|
@ -67,19 +67,10 @@ class Values(object):
|
|||
"""get value directly in cache if set
|
||||
otherwise calculated value and set it in cache
|
||||
|
||||
:param opt: the `Option` that we want to get value
|
||||
:param path: the path of the `Option`
|
||||
:param validate: the value must be valid
|
||||
:param force_permissive: force permissive when check properties
|
||||
:param setting_properties: global properties
|
||||
:param self_properties: properties for this `Option`
|
||||
:param index: index for a slave `Option`
|
||||
:param display_warnings: display warnings or not
|
||||
|
||||
:returns: value
|
||||
"""
|
||||
# try to retrive value in cache
|
||||
setting_properties = option_bag.config_bag.setting_properties
|
||||
setting_properties = option_bag.config_bag.properties
|
||||
is_cached, value = self._p_.getcache(option_bag.path,
|
||||
expires_time,
|
||||
option_bag.index,
|
||||
|
@ -97,7 +88,7 @@ class Values(object):
|
|||
option_bag,
|
||||
context=context,
|
||||
check_error=True)
|
||||
if setting_properties and 'warnings' in setting_properties:
|
||||
if 'warnings' in setting_properties:
|
||||
opt.impl_validate(value,
|
||||
option_bag,
|
||||
context=context,
|
||||
|
@ -172,7 +163,7 @@ class Values(object):
|
|||
is_cache, cache_value = self._p_.getcache(option_bag.path,
|
||||
expires_time,
|
||||
index,
|
||||
config_bag.setting_properties,
|
||||
config_bag.properties,
|
||||
option_bag.properties,
|
||||
'value')
|
||||
if is_cache and cache_value == _value:
|
||||
|
@ -295,7 +286,7 @@ class Values(object):
|
|||
|
||||
context = self._getcontext()
|
||||
owner = context.cfgimpl_get_settings().getowner()
|
||||
if 'validator' in option_bag.config_bag.setting_properties:
|
||||
if 'validator' in option_bag.config_bag.properties:
|
||||
if option_bag.index is not None or option_bag.option._has_consistencies(context):
|
||||
# set value to a fake config when option has dependency
|
||||
# validation will be complet in this case (consistency, ...)
|
||||
|
@ -336,8 +327,7 @@ class Values(object):
|
|||
option_bag,
|
||||
context,
|
||||
check_error=True)
|
||||
if option_bag.config_bag.setting_properties and \
|
||||
'warnings' in option_bag.config_bag.setting_properties:
|
||||
if 'warnings' in option_bag.config_bag.properties:
|
||||
# No error found so emit warnings
|
||||
opt.impl_validate(value,
|
||||
option_bag,
|
||||
|
@ -468,7 +458,7 @@ class Values(object):
|
|||
setting = context.cfgimpl_get_settings()
|
||||
hasvalue = self._p_.hasvalue(option_bag.path)
|
||||
|
||||
if hasvalue and 'validator' in option_bag.config_bag.setting_properties:
|
||||
if hasvalue and 'validator' in option_bag.config_bag.properties:
|
||||
option_bag.config_bag.remove_validation()
|
||||
fake_context = context._gen_fake_values()
|
||||
fake_value = fake_context.cfgimpl_get_values()
|
||||
|
@ -503,7 +493,7 @@ class Values(object):
|
|||
|
||||
if self._p_.hasvalue(option_bag.path, index=option_bag.index):
|
||||
context = self._getcontext()
|
||||
if 'validator' in option_bag.config_bag.setting_properties:
|
||||
if 'validator' in option_bag.config_bag.properties:
|
||||
fake_context = context._gen_fake_values()
|
||||
fake_value = fake_context.cfgimpl_get_values()
|
||||
option_bag.config_bag.remove_validation()
|
||||
|
@ -576,8 +566,8 @@ class Values(object):
|
|||
path = '.'.join(currpath + [name])
|
||||
|
||||
if option.impl_is_optiondescription():
|
||||
ori_setting_properties = config_bag.setting_properties
|
||||
config_bag.setting_properties = od_setting_properties
|
||||
ori_setting_properties = config_bag.properties
|
||||
config_bag.properties = od_setting_properties
|
||||
try:
|
||||
option_bag = OptionBag()
|
||||
option_bag.set_option(option,
|
||||
|
@ -589,7 +579,7 @@ class Values(object):
|
|||
except PropertiesOptionError as err:
|
||||
pass
|
||||
else:
|
||||
config_bag.setting_properties = ori_setting_properties
|
||||
config_bag.properties = ori_setting_properties
|
||||
for path in self._mandatory_warnings(context,
|
||||
config_bag,
|
||||
option,
|
||||
|
@ -635,11 +625,11 @@ class Values(object):
|
|||
"""
|
||||
context = self._getcontext()
|
||||
# copy
|
||||
od_setting_properties = config_bag.setting_properties - {'mandatory', 'empty'}
|
||||
setting_properties = set(config_bag.setting_properties) - {'warnings'}
|
||||
od_setting_properties = config_bag.properties - {'mandatory', 'empty'}
|
||||
setting_properties = set(config_bag.properties) - {'warnings'}
|
||||
setting_properties.update(['mandatory', 'empty'])
|
||||
config_bag = ConfigBag(context=config_bag.context)
|
||||
config_bag.setting_properties = frozenset(setting_properties)
|
||||
config_bag.properties = frozenset(setting_properties)
|
||||
config_bag.force_permissive = True
|
||||
|
||||
descr = context.cfgimpl_get_description()
|
||||
|
|
Loading…
Reference in New Issue