support symlink with a slave
This commit is contained in:
@ -168,11 +168,12 @@ class CommonTiramisu(TiramisuHelp):
|
||||
if self.index is not None:
|
||||
if option.impl_is_optiondescription() or not option.impl_is_master_slaves('slave'):
|
||||
raise APIError('index must be set only with a slave option')
|
||||
if self.index >= self.subconfig.cfgimpl_get_length():
|
||||
self._length = self.subconfig.cfgimpl_get_length_slave(option, self.config_bag)
|
||||
if self.index >= self._length:
|
||||
raise SlaveError(_('index "{}" is higher than the master length "{}" '
|
||||
'for option "{}"').format(self.index,
|
||||
self.subconfig.cfgimpl_get_length(),
|
||||
option.impl_get_display_name()))
|
||||
self._length,
|
||||
option.impl_get_display_name()))
|
||||
if not self.allow_optiondescription and option.impl_is_optiondescription():
|
||||
raise APIError(_('option must not be an optiondescription'))
|
||||
return option
|
||||
@ -573,17 +574,11 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
@count
|
||||
def _len(self):
|
||||
"""length of slave option (only for slave option)"""
|
||||
self._get_option()
|
||||
subconfig_path = self._path.rsplit('.', 1)[0]
|
||||
if self.config_bag.setting_properties is not None:
|
||||
self.config_bag.config.cfgimpl_get_settings().validate_properties(self._path,
|
||||
self.index,
|
||||
self.config_bag)
|
||||
config_bag = self.config_bag.copy('nooption')
|
||||
subconfig = config_bag.config.getattr(subconfig_path,
|
||||
None,
|
||||
config_bag)
|
||||
return subconfig.cfgimpl_get_length()
|
||||
option = self._get_option()
|
||||
# for example if index is None
|
||||
if '_length' not in vars(self):
|
||||
self._length = self.subconfig.cfgimpl_get_length_slave(option, self.config_bag)
|
||||
return self._length
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name == 'list' and isinstance(self._get_option(), ChoiceOption):
|
||||
|
@ -83,6 +83,16 @@ class SubConfig(object):
|
||||
def cfgimpl_get_length(self):
|
||||
return self._impl_length
|
||||
|
||||
def cfgimpl_get_length_slave(self, option, config_bag):
|
||||
if option.impl_is_symlinkoption():
|
||||
context = self.cfgimpl_get_context()
|
||||
sconfig_bag = config_bag.copy('nooption')
|
||||
subconfig, _ = context.cfgimpl_get_home_by_path(option.impl_getopt().impl_getpath(context),
|
||||
sconfig_bag)
|
||||
return subconfig.cfgimpl_get_length()
|
||||
else:
|
||||
return self.cfgimpl_get_length()
|
||||
|
||||
def reset_one_option_cache(self,
|
||||
desc,
|
||||
values,
|
||||
@ -354,7 +364,7 @@ class SubConfig(object):
|
||||
subpath)
|
||||
|
||||
if option.impl_is_master_slaves('slave'):
|
||||
length = self.cfgimpl_get_length()
|
||||
length = self.cfgimpl_get_length_slave(option, config_bag)
|
||||
slave_len = self.cfgimpl_get_values()._p_.get_max_length(subpath)
|
||||
if slave_len > length:
|
||||
raise SlaveError(_('slave option "{}" has higher length "{}" than the master '
|
||||
@ -364,7 +374,6 @@ class SubConfig(object):
|
||||
subpath))
|
||||
if option.impl_is_master_slaves('slave') and index is None:
|
||||
value = []
|
||||
length = self.cfgimpl_get_length()
|
||||
for idx in range(length):
|
||||
config_bag.properties = None
|
||||
value.append(self.getattr(name,
|
||||
@ -551,7 +560,7 @@ class SubConfig(object):
|
||||
option = config_bag.option
|
||||
if not option.impl_is_optiondescription() and option.impl_is_master_slaves('slave'):
|
||||
ret = []
|
||||
length = self.cfgimpl_get_length()
|
||||
length = self.cfgimpl_get_length_slave(option, config_bag)
|
||||
if length:
|
||||
for idx in range(length):
|
||||
config_bag.properties = None
|
||||
|
Reference in New Issue
Block a user