remove _cache_paths (path is now directly in option)

better TiramisuAPI support
This commit is contained in:
2018-09-08 20:17:20 +02:00
parent e0cab0063e
commit aa9aef6e78
13 changed files with 627 additions and 633 deletions

View File

@ -30,7 +30,7 @@ from ..error import ConfigError, ConflictError
class CacheOptionDescription(BaseOption):
__slots__ = ('_cache_paths', '_cache_consistencies', '_cache_force_store_values')
__slots__ = ('_cache_consistencies', '_cache_force_store_values')
def _build_cache(self,
config,
@ -154,7 +154,7 @@ class CacheOptionDescription(BaseOption):
self._set_readonly()
def impl_already_build_caches(self):
if hasattr(self, '_cache_paths'):
if hasattr(self, '_cache_consistencies'):
return True
return False
@ -192,11 +192,10 @@ class CacheOptionDescription(BaseOption):
values._p_.commit()
def _build_cache_option(self,
_currpath=None,
cache_path=None,
cache_option=None):
_currpath=None):
if self.impl_is_readonly() or (_currpath is None and getattr(self, '_cache_paths', None) is not None):
if self.impl_is_readonly() or \
(_currpath is None and getattr(self, '_cache_consistencies', None) is not None):
# cache already set
return
if _currpath is None:
@ -204,24 +203,17 @@ class CacheOptionDescription(BaseOption):
_currpath = []
else:
save = False
if cache_path is None:
cache_path = []
cache_option = []
for option in self.impl_getchildren(config_bag=undefined,
dyn=False):
attr = option.impl_getname()
path = str('.'.join(_currpath + [attr]))
cache_option.append(option)
cache_path.append(path)
option._path = path
if option.impl_is_optiondescription():
_currpath.append(attr)
option._build_cache_option(_currpath,
cache_path,
cache_option)
option._build_cache_option(_currpath)
_currpath.pop()
if save:
self._cache_paths = (tuple(cache_option), tuple(cache_path))
if save and not hasattr(self, '_cache_consistencies'):
self._cache_consistencies = None
class OptionDescriptionWalk(CacheOptionDescription):
@ -248,57 +240,43 @@ class OptionDescriptionWalk(CacheOptionDescription):
bytype,
byname,
_subpath,
config_bag):
def _filter_by_type(path,
option):
if isinstance(option,
bytype):
return _filter_by_name(path, option)
config_bag,
self_opt=None):
if self_opt is None:
self_opt = self
def _filter_by_name(option):
return byname is None or option.impl_getname() == byname
def _filter_by_name(path,
option):
name = option.impl_getname()
if option.issubdyn():
if byname.startswith(name):
option_bag = OptionBag()
option_bag.set_option(option,
path,
None,
config_bag)
for doption in self.build_dynoptions(option_bag):
if byname == doption.impl_getname():
dpath = doption.impl_getpath()
return (dpath, doption)
elif byname == name:
return (path, option)
def _filter(path, option):
if bytype is not None:
return _filter_by_type(path, option)
return _filter_by_name(path, option)
opts, paths = self._cache_paths
for index, option in enumerate(opts):
for option in self_opt.impl_getchildren(config_bag):
if _subpath is None:
path = option.impl_getname()
else:
path = _subpath + '.' + option.impl_getname()
if option.impl_is_optiondescription():
continue
path = paths[index]
if _subpath is not None and not path.startswith(_subpath + '.'):
continue
ret = _filter(path, option)
if ret:
yield ret
for subopt in option.impl_get_options_paths(bytype,
byname,
path,
config_bag):
yield subopt
else:
if bytype is not None:
if isinstance(option, bytype) and \
_filter_by_name(option):
yield (path, option)
elif _filter_by_name(option):
yield (path, option)
def impl_getchild(self,
name,
config_bag,
subconfig):
subpath):
if name in self._children[0]:
child = self._children[1][self._children[0].index(name)]
if not child.impl_is_dynoptiondescription():
return child
else:
child = self._impl_search_dynchild(name,
subconfig,
subpath,
config_bag)
if child:
return child
@ -307,12 +285,19 @@ class OptionDescriptionWalk(CacheOptionDescription):
'').format(name, self.impl_getname()))
def impl_get_opt_by_path(self,
path):
return self._cache_paths[0][self._cache_paths[1].index(path)]
def impl_get_path_by_opt(self,
opt):
return self._cache_paths[1][self._cache_paths[0].index(opt)]
path,
config_bag):
opt = self
subpath = None
for step in path.split('.'):
opt = opt.impl_getchild(step,
config_bag,
subpath)
if subpath is None:
subpath = step
else:
subpath += '.' + step
return opt
def impl_getchildren(self,
config_bag,
@ -347,7 +332,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
def _impl_search_dynchild(self,
name,
subconfig,
subpath,
config_bag):
for child in self._impl_st_getchildren(only_dyn=True):
#sconfig_bag = config_bag.copy('nooption')
@ -356,13 +341,13 @@ class OptionDescriptionWalk(CacheOptionDescription):
if name.startswith(cname):
option_bag = OptionBag()
option_bag.set_option(child,
subconfig.cfgimpl_get_path(),
subpath,
None,
config_bag)
for value in child.impl_get_suffixes(option_bag):
if name == cname + value:
return SynDynOptionDescription(child,
subconfig.cfgimpl_get_path(),
subpath,
value)
def _impl_get_dynchild(self,
@ -424,7 +409,7 @@ class OptionDescription(OptionDescriptionWalk):
'the dynoptiondescription\'s name "{}"').format(child, dynopt))
old = child
self._children = children_
self._cache_consistencies = None
#self._cache_consistencies = None
# the group_type is useful for filtering OptionDescriptions in a config
self._group_type = groups.default