refactor masterslaves
This commit is contained in:
@ -634,15 +634,17 @@ class SymLinkOption(OnlyOption):
|
||||
|
||||
|
||||
class DynSymLinkOption(object):
|
||||
__slots__ = ('_dyn', '_opt', '_name')
|
||||
__slots__ = ('_rootpath',
|
||||
'_opt',
|
||||
'_suffix')
|
||||
|
||||
def __init__(self,
|
||||
name,
|
||||
opt,
|
||||
dyn):
|
||||
self._name = name
|
||||
self._dyn = dyn
|
||||
rootpath,
|
||||
suffix):
|
||||
self._opt = opt
|
||||
self._rootpath = rootpath
|
||||
self._suffix = suffix
|
||||
|
||||
def __getattr__(self,
|
||||
name,
|
||||
@ -650,7 +652,7 @@ class DynSymLinkOption(object):
|
||||
return getattr(self.impl_getopt(), name)
|
||||
|
||||
def impl_getname(self):
|
||||
return self._name
|
||||
return self._opt.impl_getname() + self._suffix
|
||||
|
||||
def impl_get_display_name(self):
|
||||
return self.impl_getopt().impl_get_display_name(dyn_name=self.impl_getname())
|
||||
@ -659,18 +661,13 @@ class DynSymLinkOption(object):
|
||||
return self._opt
|
||||
|
||||
def impl_getsuffix(self):
|
||||
return self._dyn.split('.')[-1][len(self.impl_getopt().impl_getname()):]
|
||||
return self._suffix
|
||||
|
||||
def impl_getpath(self,
|
||||
context):
|
||||
path = self.impl_getopt().impl_getpath(context)
|
||||
base_path = '.'.join(path.split('.')[:-2])
|
||||
if self.impl_is_master_slaves() and base_path is not '':
|
||||
base_path = base_path + self.impl_getsuffix()
|
||||
if base_path == '':
|
||||
return self._dyn
|
||||
else:
|
||||
return base_path + '.' + self._dyn
|
||||
if self._rootpath == '':
|
||||
return self.impl_getname()
|
||||
return self._rootpath + '.' + self.impl_getname()
|
||||
|
||||
def impl_validate(self,
|
||||
value,
|
||||
|
@ -91,4 +91,3 @@ class DynOptionDescription(OptionDescription):
|
||||
'').format(val,
|
||||
self.impl_get_display_name()))
|
||||
return values
|
||||
|
||||
|
@ -49,30 +49,32 @@ class MasterSlaves(OptionDescription):
|
||||
master = children[0]
|
||||
if not children:
|
||||
raise ValueError(_('children is mandatory in masterslaves "{}"').format(name))
|
||||
for child in children[1:]:
|
||||
if child.impl_getdefault() != []:
|
||||
raise ValueError(_("not allowed default value for option {0} "
|
||||
"in master/slave object {1}").format(child.impl_getname(),
|
||||
name))
|
||||
slaves.append(child)
|
||||
child._add_dependency(self)
|
||||
for idx, child in enumerate(children):
|
||||
if idx != 0 and child.impl_getdefault() != []:
|
||||
raise ValueError(_('not allowed default value for option "{0}" '
|
||||
'in master/slave object "{1}"'
|
||||
'').format(child.impl_get_display_name(),
|
||||
self.impl_get_display_name()))
|
||||
if child.impl_is_symlinkoption(): # pragma: optional cover
|
||||
raise ValueError(_("master group {0} shall not have "
|
||||
"a symlinkoption").format(self.impl_getname()))
|
||||
raise ValueError(_('master group "{0}" shall not have '
|
||||
"a symlinkoption").format(self.impl_get_display_name()))
|
||||
if not isinstance(child, Option): # pragma: optional cover
|
||||
raise ValueError(_("master group {0} shall not have "
|
||||
"a subgroup").format(self.impl_getname()))
|
||||
raise ValueError(_('master group "{0}" shall not have '
|
||||
'a subgroup').format(self.impl_get_display_name()))
|
||||
if not child.impl_is_multi(): # pragma: optional cover
|
||||
raise ValueError(_("not allowed option {0} "
|
||||
"in group {1}"
|
||||
": this option is not a multi"
|
||||
"").format(child.impl_getname(), self.impl_getname()))
|
||||
raise ValueError(_('not allowed option "{0}" '
|
||||
'in group "{1}"'
|
||||
': this option is not a multi'
|
||||
'').format(child.impl_get_display_name(),
|
||||
self.impl_get_display_name()))
|
||||
# no empty property for save
|
||||
if idx != 0:
|
||||
properties = list(child._properties)
|
||||
properties.remove('empty')
|
||||
child._properties = tuple(properties)
|
||||
slaves.append(child)
|
||||
child._add_dependency(self)
|
||||
child._master_slaves = weakref.ref(self)
|
||||
callback, callback_params = master.impl_get_callback()
|
||||
if callback is not None and callback_params != {}:
|
||||
for callbacks in callback_params.values():
|
||||
@ -81,37 +83,18 @@ class MasterSlaves(OptionDescription):
|
||||
if callbk[0] in slaves:
|
||||
raise ValueError(_("callback of master's option shall "
|
||||
"not refered a slave's ones"))
|
||||
#everything is ok, store references
|
||||
for child in children:
|
||||
child._master_slaves = weakref.ref(self)
|
||||
master._add_dependency(self)
|
||||
|
||||
def is_master(self, opt):
|
||||
master = self._children[0][0]
|
||||
return opt.impl_getname() == master or (opt.impl_is_dynsymlinkoption() and
|
||||
opt._opt.impl_getname() == master)
|
||||
|
||||
def getmaster(self, opt):
|
||||
master = self._children[1][0]
|
||||
if opt is not None and opt.impl_is_dynsymlinkoption():
|
||||
suffix = opt.impl_getsuffix()
|
||||
name = master.impl_getname() + suffix
|
||||
base_path = opt._dyn.split('.')[0] + '.'
|
||||
path = base_path + name
|
||||
master = master._impl_to_dyn(name, path)
|
||||
return master
|
||||
def getmaster(self):
|
||||
return self._children[1][0]
|
||||
|
||||
def getslaves(self, opt):
|
||||
if opt.impl_is_dynsymlinkoption():
|
||||
for slave in self._children[1][1:]:
|
||||
suffix = opt.impl_getsuffix()
|
||||
name = slave.impl_getname() + suffix
|
||||
base_path = opt._dyn.split('.')[0] + '.'
|
||||
path = base_path + name
|
||||
yield slave._impl_to_dyn(name, path)
|
||||
else:
|
||||
for slave in self._children[1][1:]:
|
||||
yield slave
|
||||
def getslaves(self):
|
||||
for slave in self._children[1][1:]:
|
||||
yield slave
|
||||
|
||||
def in_same_group(self, opt):
|
||||
if opt.impl_is_dynsymlinkoption():
|
||||
@ -127,7 +110,7 @@ class MasterSlaves(OptionDescription):
|
||||
_commit=True,
|
||||
force_permissive=False):
|
||||
|
||||
for slave in self.getslaves(opt):
|
||||
for slave in self.getslaves():
|
||||
slave_path = slave.impl_getpath(values._getcontext())
|
||||
values.reset(slave,
|
||||
slave_path,
|
||||
@ -137,15 +120,17 @@ class MasterSlaves(OptionDescription):
|
||||
force_permissive=force_permissive)
|
||||
|
||||
def pop(self,
|
||||
opt,
|
||||
path,
|
||||
values,
|
||||
index,
|
||||
setting_properties,
|
||||
force_permissive=False):
|
||||
force_permissive,
|
||||
slaves=undefined):
|
||||
|
||||
for slave in self.getslaves(opt):
|
||||
slave_path = slave.impl_getpath(values._getcontext())
|
||||
context = values._getcontext()
|
||||
if slaves is undefined:
|
||||
slaves = self.getslaves()
|
||||
for slave in slaves:
|
||||
slave_path = slave.impl_getpath(context)
|
||||
slavelen = values._p_.get_max_length(slave_path)
|
||||
if not values.is_default_owner(slave,
|
||||
slave_path,
|
||||
@ -153,13 +138,6 @@ class MasterSlaves(OptionDescription):
|
||||
validate_meta=False,
|
||||
index=index,
|
||||
force_permissive=force_permissive):
|
||||
#FIXME # just for raise if needed
|
||||
#multi = values.get_cached_value(slave,
|
||||
# validate=False,
|
||||
# validate_properties=False,
|
||||
# )
|
||||
#if isinstance(multi, Exception):
|
||||
# raise multi
|
||||
if slavelen > index:
|
||||
values._p_.resetvalue_index(slave_path,
|
||||
index)
|
||||
@ -168,214 +146,6 @@ class MasterSlaves(OptionDescription):
|
||||
values._p_.reduce_index(slave_path,
|
||||
idx)
|
||||
|
||||
|
||||
def getitem(self,
|
||||
values,
|
||||
opt,
|
||||
path,
|
||||
validate,
|
||||
force_permissive,
|
||||
trusted_cached_properties,
|
||||
validate_properties,
|
||||
setting_properties=undefined,
|
||||
self_properties=undefined,
|
||||
index=None,
|
||||
check_frozen=False):
|
||||
if self.is_master(opt):
|
||||
return self._getmaster(values,
|
||||
opt,
|
||||
path,
|
||||
validate,
|
||||
force_permissive,
|
||||
validate_properties,
|
||||
self_properties,
|
||||
index,
|
||||
setting_properties,
|
||||
check_frozen)
|
||||
else:
|
||||
return self._getslave(values,
|
||||
opt,
|
||||
path,
|
||||
validate,
|
||||
force_permissive,
|
||||
trusted_cached_properties,
|
||||
validate_properties,
|
||||
setting_properties,
|
||||
self_properties,
|
||||
index,
|
||||
check_frozen)
|
||||
|
||||
def _getmaster(self,
|
||||
values,
|
||||
opt,
|
||||
path,
|
||||
validate,
|
||||
force_permissive,
|
||||
validate_properties,
|
||||
self_properties,
|
||||
index,
|
||||
setting_properties,
|
||||
check_frozen):
|
||||
return values.get_cached_value(opt,
|
||||
path=path,
|
||||
validate=validate,
|
||||
force_permissive=force_permissive,
|
||||
self_properties=self_properties,
|
||||
index=index,
|
||||
setting_properties=setting_properties)
|
||||
|
||||
def _getslave(self, values, opt, path, validate, force_permissive,
|
||||
trusted_cached_properties, validate_properties, setting_properties,
|
||||
self_properties, index, check_frozen):
|
||||
"""
|
||||
if master has length 0:
|
||||
return []
|
||||
if master has length bigger than 0:
|
||||
if default owner:
|
||||
if has callback:
|
||||
if return a list:
|
||||
list same length as master: return list
|
||||
list is smaller than master: return list + None
|
||||
list is greater than master: raise SlaveError
|
||||
if has default value:
|
||||
list same length as master: return list
|
||||
list is smaller than master: return list + None
|
||||
list is greater than master: raise SlaveError
|
||||
if has default_multi value:
|
||||
return default_multi * master's length
|
||||
if has value:
|
||||
list same length as master: return list
|
||||
list is smaller than master: return list + None
|
||||
list is greater than master: raise SlaveError
|
||||
"""
|
||||
master = self.getmaster(opt)
|
||||
context = values._getcontext()
|
||||
masterp = master.impl_getpath(context)
|
||||
try:
|
||||
mastervalue = values.get_cached_value(master,
|
||||
path=masterp,
|
||||
validate=validate,
|
||||
force_permissive=force_permissive,
|
||||
validate_properties=validate_properties,
|
||||
self_properties=self_properties,
|
||||
from_masterslave=True,
|
||||
setting_properties=setting_properties,
|
||||
check_frozen=check_frozen)
|
||||
except PropertiesOptionError as mastervalue:
|
||||
mastervalue.set_orig_opt(opt)
|
||||
raise mastervalue
|
||||
masterlen = len(mastervalue)
|
||||
#self._master_is_meta = values._is_meta(master, masterp, force_permissive=force_permissive)
|
||||
multi = list() # values._get_multi(opt, path)
|
||||
if validate_properties:
|
||||
props = context.cfgimpl_get_settings().validate_properties(opt, False,
|
||||
check_frozen,
|
||||
value=multi,
|
||||
path=path,
|
||||
force_permissive=force_permissive,
|
||||
setting_properties=setting_properties)
|
||||
if props:
|
||||
return props
|
||||
#FIXME shouldn't have index!!!
|
||||
if index is None:
|
||||
indexes = range(0, masterlen)
|
||||
else:
|
||||
indexes = [index]
|
||||
for idx in indexes:
|
||||
try:
|
||||
value = values.get_cached_value(opt,
|
||||
path,
|
||||
validate,
|
||||
force_permissive,
|
||||
trusted_cached_properties,
|
||||
validate_properties,
|
||||
index=idx,
|
||||
# not self_properties,
|
||||
# depends to index
|
||||
#self_properties=self_properties,
|
||||
setting_properties=setting_properties,
|
||||
from_masterslave=True,
|
||||
check_frozen=check_frozen)
|
||||
except PropertiesOptionError as perr:
|
||||
err = perr
|
||||
if index is None:
|
||||
multi.append(err)
|
||||
else:
|
||||
multi = err
|
||||
if index is None:
|
||||
multi.append(value)
|
||||
else:
|
||||
multi = value
|
||||
return multi
|
||||
|
||||
def validate(self,
|
||||
values,
|
||||
opt,
|
||||
index,
|
||||
path,
|
||||
setitem):
|
||||
if self.is_master(opt):
|
||||
#for regen slave path
|
||||
base_path = '.'.join(path.split('.')[:-1]) + '.'
|
||||
for slave in self.getslaves(opt):
|
||||
slave_path = base_path + slave.impl_getname()
|
||||
slavelen = values._p_.get_max_length(slave_path)
|
||||
self.validate_slave_length(index,
|
||||
slavelen,
|
||||
slave.impl_getname(),
|
||||
opt)
|
||||
else:
|
||||
val_len = self.get_length(values)
|
||||
if isinstance(val_len, Exception):
|
||||
return val_len
|
||||
self.validate_slave_length(val_len,
|
||||
index,
|
||||
opt.impl_getname(),
|
||||
opt,
|
||||
setitem=setitem)
|
||||
|
||||
def get_length(self,
|
||||
values,
|
||||
validate=True,
|
||||
force_permissive=False,
|
||||
master=None,
|
||||
masterp=None,
|
||||
setting_properties=undefined):
|
||||
"""get master len with slave option"""
|
||||
if master is None:
|
||||
master = self.getmaster(None)
|
||||
if masterp is None:
|
||||
masterp = master.impl_getpath(values._getcontext())
|
||||
value = self._getmaster(values,
|
||||
master,
|
||||
masterp,
|
||||
validate,
|
||||
force_permissive,
|
||||
validate,
|
||||
undefined,
|
||||
None,
|
||||
setting_properties,
|
||||
False)
|
||||
if isinstance(value, Exception):
|
||||
return value
|
||||
return len(value)
|
||||
|
||||
def validate_slave_length(self,
|
||||
masterlen,
|
||||
valuelen,
|
||||
name,
|
||||
opt,
|
||||
setitem=False):
|
||||
if valuelen > masterlen or (valuelen < masterlen and setitem):
|
||||
if debug: # pragma: no cover
|
||||
log.debug('validate_slave_length: masterlen: {0}, valuelen: {1}, '
|
||||
'setitem: {2}'.format(masterlen, valuelen, setitem))
|
||||
if not opt.impl_is_master_slaves('master'):
|
||||
opt = self.getmaster(opt)
|
||||
raise SlaveError(_("invalid len for the slave: {0}"
|
||||
" which has {1} as master").format(
|
||||
name, opt.impl_getname()))
|
||||
|
||||
def reset_cache(self,
|
||||
opt,
|
||||
path,
|
||||
@ -384,14 +154,14 @@ class MasterSlaves(OptionDescription):
|
||||
resetted_opts):
|
||||
context = obj._getcontext()
|
||||
#FIXME pb avec dyn, devrait etre une option
|
||||
mopt = self.getmaster(None)
|
||||
mopt = self.getmaster()
|
||||
mpath = mopt.impl_getpath(context)
|
||||
mopt.reset_cache(mopt,
|
||||
mpath,
|
||||
obj,
|
||||
type_,
|
||||
resetted_opts)
|
||||
for slave in self.getslaves(mopt):
|
||||
for slave in self.getslaves():
|
||||
spath = slave.impl_getpath(context)
|
||||
slave.reset_cache(slave,
|
||||
spath,
|
||||
@ -399,45 +169,6 @@ class MasterSlaves(OptionDescription):
|
||||
type_,
|
||||
resetted_opts)
|
||||
|
||||
def impl_getchild(self,
|
||||
name,
|
||||
setting_properties,
|
||||
context=undefined,
|
||||
dyn=True):
|
||||
return super(MasterSlaves, self).impl_getchild(name,
|
||||
setting_properties,
|
||||
context,
|
||||
dyn)
|
||||
|
||||
def impl_validate(self,
|
||||
context,
|
||||
force_permissive,
|
||||
setting_properties,
|
||||
masterlen=None,
|
||||
slavelen=None,
|
||||
opt=None,
|
||||
setitem=False):
|
||||
values = context.cfgimpl_get_values()
|
||||
if masterlen is None:
|
||||
master = self.getmaster(opt)
|
||||
masterp = master.impl_getpath(context)
|
||||
|
||||
mastervalue = values.get_cached_value(master, path=masterp,
|
||||
force_permissive=force_permissive,
|
||||
setting_properties=setting_properties)
|
||||
if isinstance(mastervalue, Exception):
|
||||
return mastervalue
|
||||
masterlen = len(mastervalue)
|
||||
else:
|
||||
master = opt
|
||||
if slavelen is not None:
|
||||
self.validate_slave_length(masterlen, slavelen, opt.impl_getname(), master, setitem=setitem)
|
||||
else:
|
||||
for slave in self.getslaves(master):
|
||||
slave_path = slave.impl_getpath(context)
|
||||
slavelen = values._p_.get_max_length(slave_path)
|
||||
self.validate_slave_length(masterlen, slavelen, slave.impl_getname(), master)
|
||||
|
||||
def impl_validate_value(self,
|
||||
option,
|
||||
value,
|
||||
@ -446,3 +177,6 @@ class MasterSlaves(OptionDescription):
|
||||
if len(value) < context._impl_length:
|
||||
return ValueError(_('cannot reduce length of master "{}"'
|
||||
'').format(option.impl_get_display_name()))
|
||||
|
||||
def is_masterslaves(self):
|
||||
return True
|
||||
|
@ -629,9 +629,9 @@ class Option(OnlyOption):
|
||||
suffix = option.impl_getname()[namelen:]
|
||||
opts = []
|
||||
for opt in all_cons_opts:
|
||||
name = opt.impl_getname() + suffix
|
||||
path = subpath + '.' + name
|
||||
opts.append(opt._impl_to_dyn(name, path))
|
||||
opts.append(DynSymLinkOption(opt,
|
||||
subpath,
|
||||
suffix))
|
||||
else:
|
||||
opts = all_cons_opts
|
||||
err = opts[0]()._launch_consistency(self,
|
||||
@ -685,13 +685,6 @@ class Option(OnlyOption):
|
||||
warnings_only):
|
||||
pass
|
||||
|
||||
def _impl_to_dyn(self,
|
||||
name,
|
||||
path):
|
||||
return DynSymLinkOption(name,
|
||||
self,
|
||||
dyn=path)
|
||||
|
||||
def impl_getdefault_multi(self):
|
||||
"accessing the default value for a multi"
|
||||
if self.impl_is_submulti():
|
||||
|
@ -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')
|
||||
|
||||
|
@ -20,20 +20,21 @@
|
||||
# ____________________________________________________________
|
||||
from ..i18n import _
|
||||
from ..setting import undefined
|
||||
from .baseoption import DynSymLinkOption
|
||||
|
||||
|
||||
class SynDynOptionDescription(object):
|
||||
__slots__ = ('_opt',
|
||||
'_name',
|
||||
'_subpath',
|
||||
'_suffix')
|
||||
|
||||
def __init__(self,
|
||||
opt,
|
||||
name,
|
||||
subpath,
|
||||
suffix):
|
||||
|
||||
self._opt = opt
|
||||
self._name = name
|
||||
self._subpath = subpath
|
||||
self._suffix = suffix
|
||||
|
||||
def __getattr__(self, name):
|
||||
@ -42,18 +43,19 @@ class SynDynOptionDescription(object):
|
||||
def impl_getchild(self,
|
||||
name,
|
||||
setting_properties,
|
||||
context):
|
||||
subconfig):
|
||||
if name.endswith(self._suffix):
|
||||
oname = name[:-len(self._suffix)]
|
||||
child = self._children[1][self._children[0].index(oname)]
|
||||
return self._impl_get_dynchild(child,
|
||||
self._suffix)
|
||||
self._suffix,
|
||||
subconfig.cfgimpl_get_path())
|
||||
raise AttributeError(_('unknown Option {0} '
|
||||
'in SynDynOptionDescription {1}'
|
||||
'').format(name, self.impl_getname()))
|
||||
|
||||
def impl_getname(self):
|
||||
return self._name
|
||||
return self._opt.impl_getname() + self._suffix
|
||||
|
||||
def impl_getchildren(self,
|
||||
setting_properties,
|
||||
@ -62,13 +64,39 @@ class SynDynOptionDescription(object):
|
||||
children = []
|
||||
for child in self._opt.impl_getchildren(setting_properties):
|
||||
yield(self._opt._impl_get_dynchild(child,
|
||||
self._suffix))
|
||||
self._suffix,
|
||||
self._subpath))
|
||||
|
||||
def impl_getpath(self, context):
|
||||
path = self.impl_getopt().impl_getpath(context).split('.')
|
||||
path[-1] += self._suffix
|
||||
path.append(self._name)
|
||||
return '.'.join(path)
|
||||
def impl_getpath(self):
|
||||
subpath = self._subpath
|
||||
if subpath != '':
|
||||
subpath += '.'
|
||||
return subpath + self.impl_getname()
|
||||
|
||||
def impl_getopt(self):
|
||||
return self._opt
|
||||
|
||||
def getmaster(self):
|
||||
master = self._opt.getmaster()
|
||||
return DynSymLinkOption(master,
|
||||
self.impl_getpath(),
|
||||
self._suffix)
|
||||
|
||||
def getslaves(self):
|
||||
subpath = self.impl_getpath()
|
||||
for slave in self._opt.getslaves():
|
||||
yield DynSymLinkOption(slave,
|
||||
subpath,
|
||||
self._suffix)
|
||||
|
||||
def pop(self,
|
||||
values,
|
||||
index,
|
||||
setting_properties,
|
||||
force_permissive,
|
||||
slaves=undefined):
|
||||
self._opt.pop(values,
|
||||
index,
|
||||
setting_properties,
|
||||
force_permissive,
|
||||
slaves=self.getslaves())
|
||||
|
Reference in New Issue
Block a user