add config_bag and convert some tests
This commit is contained in:
@ -22,7 +22,7 @@ from copy import copy
|
||||
|
||||
|
||||
from ..i18n import _
|
||||
from ..setting import groups, undefined, owners
|
||||
from ..setting import ConfigBag, groups, undefined, owners
|
||||
from .baseoption import BaseOption
|
||||
from .option import ALLOWED_CONST_LIST, DynSymLinkOption
|
||||
from .syndynoptiondescription import SynDynOptionDescription
|
||||
@ -54,7 +54,7 @@ class CacheOptionDescription(BaseOption):
|
||||
else:
|
||||
init = False
|
||||
|
||||
for option in self.impl_getchildren(setting_properties=undefined,
|
||||
for option in self.impl_getchildren(config_bag=undefined,
|
||||
dyn=False):
|
||||
cache_option.append(option)
|
||||
if path == '':
|
||||
@ -83,7 +83,8 @@ class CacheOptionDescription(BaseOption):
|
||||
'must be a master/slaves').format(
|
||||
option.impl_getname()))
|
||||
masterslaves = option.impl_get_master_slaves()
|
||||
for opt in all_cons_opts:
|
||||
for weak_opt in all_cons_opts:
|
||||
opt = weak_opt()
|
||||
if func not in ALLOWED_CONST_LIST and is_multi:
|
||||
if not opt.impl_is_master_slaves():
|
||||
raise ConfigError(_('malformed consistency option "{0}" '
|
||||
@ -93,7 +94,7 @@ class CacheOptionDescription(BaseOption):
|
||||
raise ConfigError(_('malformed consistency option "{0}" '
|
||||
'must be in same master/slaves for "{1}"').format(
|
||||
option.impl_getname(), opt.impl_getname()))
|
||||
_consistencies.setdefault(opt,
|
||||
_consistencies.setdefault(weak_opt,
|
||||
[]).append((func,
|
||||
all_cons_opts,
|
||||
params))
|
||||
@ -133,8 +134,9 @@ class CacheOptionDescription(BaseOption):
|
||||
raise ConflictError(_('duplicate option: {0}').format(opt))
|
||||
if _consistencies != {}:
|
||||
self._cache_consistencies = {}
|
||||
for opt, cons in _consistencies.items():
|
||||
if opt() not in cache_option: # pragma: optional cover
|
||||
for weak_opt, cons in _consistencies.items():
|
||||
opt = weak_opt()
|
||||
if opt not in cache_option: # pragma: optional cover
|
||||
raise ConfigError(_('consistency with option {0} '
|
||||
'which is not in Config').format(
|
||||
opt.impl_getname()))
|
||||
@ -165,12 +167,10 @@ class CacheOptionDescription(BaseOption):
|
||||
if force_store_values is False:
|
||||
raise Exception('ok ca existe ...')
|
||||
if force_store_values and not values._p_.hasvalue(subpath):
|
||||
value = values.getvalue(option,
|
||||
subpath,
|
||||
index=None,
|
||||
setting_properties=None,
|
||||
self_properties=None,
|
||||
validate=False)
|
||||
config_bag = ConfigBag(config=context, option=option)
|
||||
value = values.getvalue(subpath,
|
||||
None,
|
||||
config_bag)
|
||||
value_setted = True
|
||||
values._p_.setvalue(subpath,
|
||||
value,
|
||||
@ -197,7 +197,7 @@ class CacheOptionDescription(BaseOption):
|
||||
if cache_path is None:
|
||||
cache_path = []
|
||||
cache_option = []
|
||||
for option in self.impl_getchildren(setting_properties=undefined,
|
||||
for option in self.impl_getchildren(config_bag=undefined,
|
||||
dyn=False):
|
||||
attr = option.impl_getname()
|
||||
path = str('.'.join(_currpath + [attr]))
|
||||
@ -221,8 +221,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
byname,
|
||||
_subpath,
|
||||
only_first,
|
||||
context,
|
||||
setting_properties):
|
||||
config_bag):
|
||||
find_results = []
|
||||
|
||||
def _rebuild_dynpath(path,
|
||||
@ -250,8 +249,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
found = False
|
||||
if byname.startswith(name):
|
||||
subdyn = option._subdyn()
|
||||
for suffix in subdyn._impl_get_suffixes(context,
|
||||
setting_properties):
|
||||
for suffix in subdyn._impl_get_suffixes(config_bag):
|
||||
if byname == name + suffix:
|
||||
found = True
|
||||
path = _rebuild_dynpath(path,
|
||||
@ -282,8 +280,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
if byname is None:
|
||||
if option._is_subdyn():
|
||||
name = option.impl_getname()
|
||||
for suffix in option._subdyn._impl_get_suffixes(context,
|
||||
setting_properties):
|
||||
for suffix in option._subdyn._impl_get_suffixes(config_bag):
|
||||
path = _rebuild_dynpath(path,
|
||||
suffix,
|
||||
option._subdyn)
|
||||
@ -318,8 +315,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
if bytype == byname is None:
|
||||
if option._is_subdyn():
|
||||
name = option.impl_getname()
|
||||
for suffix in option._subdyn._impl_get_suffixes(context,
|
||||
setting_properties):
|
||||
for suffix in option._subdyn._impl_get_suffixes(config_bag):
|
||||
path = _rebuild_dynpath(path,
|
||||
suffix,
|
||||
option._subdyn)
|
||||
@ -342,7 +338,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
|
||||
def impl_getchild(self,
|
||||
name,
|
||||
setting_properties,
|
||||
config_bag,
|
||||
subconfig):
|
||||
if name in self._children[0]:
|
||||
child = self._children[1][self._children[0].index(name)]
|
||||
@ -350,8 +346,8 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
return child
|
||||
else:
|
||||
child = self._impl_search_dynchild(name,
|
||||
subconfig=subconfig,
|
||||
setting_properties=setting_properties)
|
||||
subconfig,
|
||||
config_bag)
|
||||
if child:
|
||||
return child
|
||||
raise AttributeError(_('unknown Option {0} '
|
||||
@ -375,14 +371,14 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
return self._cache_paths[1][self._cache_paths[0].index(opt)]
|
||||
|
||||
def impl_getchildren(self,
|
||||
setting_properties,
|
||||
dyn=True,
|
||||
context=undefined):
|
||||
config_bag,
|
||||
dyn=True):
|
||||
for child in self._impl_st_getchildren():
|
||||
cname = child.impl_getname()
|
||||
if dyn and child.impl_is_dynoptiondescription():
|
||||
for value in child._impl_get_suffixes(context,
|
||||
setting_properties):
|
||||
sconfig_bag = config_bag.copy('nooption')
|
||||
sconfig_bag.option = child
|
||||
for value in child._impl_get_suffixes(sconfig_bag):
|
||||
yield SynDynOptionDescription(child,
|
||||
cname + value,
|
||||
value)
|
||||
@ -398,12 +394,13 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
def _impl_search_dynchild(self,
|
||||
name,
|
||||
subconfig,
|
||||
setting_properties):
|
||||
config_bag):
|
||||
for child in self._impl_st_getchildren(only_dyn=True):
|
||||
sconfig_bag = config_bag.copy('nooption')
|
||||
sconfig_bag.option = child
|
||||
cname = child.impl_getname()
|
||||
if name.startswith(cname):
|
||||
for value in child._impl_get_suffixes(subconfig._cfgimpl_get_context(),
|
||||
setting_properties):
|
||||
for value in child._impl_get_suffixes(sconfig_bag):
|
||||
if name == cname + value:
|
||||
return SynDynOptionDescription(child,
|
||||
subconfig.cfgimpl_get_path(),
|
||||
@ -507,7 +504,6 @@ class OptionDescription(OptionDescriptionWalk):
|
||||
return self._group_type
|
||||
|
||||
def impl_validate_value(self,
|
||||
option,
|
||||
value,
|
||||
context):
|
||||
*args,
|
||||
**kwargs):
|
||||
pass
|
||||
|
Reference in New Issue
Block a user