refactor masterslaves
This commit is contained in:
@ -24,7 +24,7 @@ from copy import copy
|
||||
from ..i18n import _
|
||||
from ..setting import groups, undefined, owners
|
||||
from .baseoption import BaseOption
|
||||
from .option import ALLOWED_CONST_LIST
|
||||
from .option import ALLOWED_CONST_LIST, DynSymLinkOption
|
||||
from .syndynoptiondescription import SynDynOptionDescription
|
||||
from ..error import ConfigError, ConflictError
|
||||
|
||||
@ -145,7 +145,9 @@ class CacheOptionDescription(BaseOption):
|
||||
self._set_readonly()
|
||||
|
||||
def impl_already_build_caches(self):
|
||||
return getattr(self, '_cache_paths', None) is not None
|
||||
if hasattr(self, '_cache_paths'):
|
||||
return True
|
||||
return False
|
||||
|
||||
def impl_build_force_store_values(self,
|
||||
config,
|
||||
@ -202,8 +204,7 @@ class CacheOptionDescription(BaseOption):
|
||||
cache_option)
|
||||
_currpath.pop()
|
||||
if save:
|
||||
_setattr = object.__setattr__
|
||||
_setattr(self, '_cache_paths', (tuple(cache_option), tuple(cache_path)))
|
||||
self._cache_paths = (tuple(cache_option), tuple(cache_path))
|
||||
|
||||
|
||||
class OptionDescriptionWalk(CacheOptionDescription):
|
||||
@ -250,8 +251,13 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
path = _rebuild_dynpath(path,
|
||||
suffix,
|
||||
subdyn)
|
||||
option = option._impl_to_dyn(name + suffix,
|
||||
path)
|
||||
if '.' in path:
|
||||
subpath = path.rsplit('.', 1)[0]
|
||||
else:
|
||||
subpath = ''
|
||||
option = DynSymLinkOption(option,
|
||||
subpath,
|
||||
suffix)
|
||||
break
|
||||
if not found:
|
||||
return False
|
||||
@ -272,11 +278,17 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
name = option.impl_getname()
|
||||
for suffix in option._subdyn._impl_get_suffixes(context,
|
||||
setting_properties):
|
||||
spath = _rebuild_dynpath(path,
|
||||
suffix,
|
||||
option._subdyn)
|
||||
find_results.append((spath, option._impl_to_dyn(
|
||||
name + suffix, spath)))
|
||||
path = _rebuild_dynpath(path,
|
||||
suffix,
|
||||
option._subdyn)
|
||||
if '.' in path:
|
||||
subpath = path.rsplit('.', 1)[0]
|
||||
else:
|
||||
subpath = ''
|
||||
doption = DynSymLinkOption(option,
|
||||
subpath,
|
||||
suffix)
|
||||
find_results.append((subpath, doption))
|
||||
else:
|
||||
find_results.append((path, option))
|
||||
return True
|
||||
@ -302,11 +314,17 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
name = option.impl_getname()
|
||||
for suffix in option._subdyn._impl_get_suffixes(context,
|
||||
setting_properties):
|
||||
spath = _rebuild_dynpath(path,
|
||||
suffix,
|
||||
path = _rebuild_dynpath(path,
|
||||
suffix,
|
||||
option._subdyn)
|
||||
find_results.append((spath, option._impl_to_dyn(name + suffix,
|
||||
spath)))
|
||||
if '.' in path:
|
||||
subpath = path.rsplit('.', 1)[0]
|
||||
else:
|
||||
subpath = ''
|
||||
doption = DynSymLinkOption(option,
|
||||
subpath,
|
||||
suffix)
|
||||
find_results.append((path, doption))
|
||||
else:
|
||||
find_results.append((path, option))
|
||||
else:
|
||||
@ -319,18 +337,17 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
def impl_getchild(self,
|
||||
name,
|
||||
setting_properties,
|
||||
context=undefined,
|
||||
dyn=True):
|
||||
if name not in self._children[0]:
|
||||
child = self._impl_search_dynchild(name,
|
||||
context=context,
|
||||
setting_properties=setting_properties)
|
||||
if child:
|
||||
return child
|
||||
else:
|
||||
subconfig):
|
||||
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=subconfig,
|
||||
setting_properties=setting_properties)
|
||||
if child:
|
||||
return child
|
||||
raise AttributeError(_('unknown Option {0} '
|
||||
'in OptionDescription {1}'
|
||||
'').format(name, self.impl_getname()))
|
||||
@ -340,7 +357,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
if getattr(self, '_cache_paths', None) is None:
|
||||
raise ConfigError(_('use impl_get_opt_by_path only with root OptionDescription'))
|
||||
if path not in self._cache_paths[1]:
|
||||
raise AttributeError(_('no option for path {0}').format(path))
|
||||
raise AttributeError(_('no option for path "{}"').format(path))
|
||||
return self._cache_paths[0][self._cache_paths[1].index(path)]
|
||||
|
||||
def impl_get_path_by_opt(self,
|
||||
@ -348,7 +365,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
if getattr(self, '_cache_paths', None) is None:
|
||||
raise ConfigError(_('use impl_get_path_by_opt only with root OptionDescription'))
|
||||
if opt not in self._cache_paths[0]:
|
||||
raise AttributeError(_('no option {0} found').format(opt))
|
||||
raise AttributeError(_('no option "{}" found').format(opt))
|
||||
return self._cache_paths[1][self._cache_paths[0].index(opt)]
|
||||
|
||||
def impl_getchildren(self,
|
||||
@ -374,37 +391,30 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
|
||||
def _impl_search_dynchild(self,
|
||||
name,
|
||||
context,
|
||||
subconfig,
|
||||
setting_properties):
|
||||
for child in self._impl_st_getchildren(only_dyn=True):
|
||||
cname = child.impl_getname()
|
||||
if name.startswith(cname):
|
||||
for value in child._impl_get_suffixes(context,
|
||||
for value in child._impl_get_suffixes(subconfig._cfgimpl_get_context(),
|
||||
setting_properties):
|
||||
if name == cname + value:
|
||||
return SynDynOptionDescription(child,
|
||||
name,
|
||||
subconfig.cfgimpl_get_path(),
|
||||
value)
|
||||
|
||||
def __getattr__(self,
|
||||
name,
|
||||
context=undefined,
|
||||
setting_properties=undefined):
|
||||
if name.startswith('_'):
|
||||
return object.__getattribute__(self,
|
||||
name)
|
||||
def _impl_get_dynchild(self,
|
||||
child,
|
||||
suffix):
|
||||
name = child.impl_getname() + suffix
|
||||
path = self.impl_getname() + suffix + '.' + name
|
||||
suffix,
|
||||
subpath):
|
||||
if isinstance(child, OptionDescription):
|
||||
return SynDynOptionDescription(child,
|
||||
name,
|
||||
subpath,
|
||||
suffix)
|
||||
else:
|
||||
return child._impl_to_dyn(name,
|
||||
path)
|
||||
return DynSymLinkOption(child,
|
||||
subpath,
|
||||
suffix)
|
||||
|
||||
|
||||
class OptionDescription(OptionDescriptionWalk):
|
||||
@ -456,6 +466,9 @@ class OptionDescription(OptionDescriptionWalk):
|
||||
# the group_type is useful for filtering OptionDescriptions in a config
|
||||
self._group_type = groups.default
|
||||
|
||||
def is_masterslaves(self):
|
||||
return False
|
||||
|
||||
def impl_getdoc(self):
|
||||
return self.impl_get_information('doc')
|
||||
|
||||
|
Reference in New Issue
Block a user