do not get value for an dynoptiondescript

This commit is contained in:
Emmanuel Garette 2021-12-10 22:23:38 +01:00
parent d6f1564744
commit 49ba56b6ec
3 changed files with 43 additions and 21 deletions

View file

@ -133,6 +133,8 @@ async def test_unknown_dyndescription():
await cfg.option('od.dodval1.novalue').value.get() await cfg.option('od.dodval1.novalue').value.get()
with pytest.raises(AttributeError): with pytest.raises(AttributeError):
await cfg.option('od.dodval1.stnoval1').value.get() await cfg.option('od.dodval1.stnoval1').value.get()
with pytest.raises(AttributeError):
await cfg.option('od.dod.st').value.get()
assert not await list_sessions() assert not await list_sessions()

View file

@ -95,7 +95,8 @@ class SubConfig:
context = self.cfgimpl_get_context() context = self.cfgimpl_get_context()
path = option_bag.option.impl_getopt().impl_getpath() path = option_bag.option.impl_getopt().impl_getpath()
subconfig, _ = await context.cfgimpl_get_home_by_path(path, subconfig, _ = await context.cfgimpl_get_home_by_path(path,
option_bag.config_bag) option_bag.config_bag,
)
return subconfig.cfgimpl_get_length() return subconfig.cfgimpl_get_length()
else: else:
return self.cfgimpl_get_length() return self.cfgimpl_get_length()
@ -200,20 +201,24 @@ class SubConfig:
async def cfgimpl_get_home_by_path(self, async def cfgimpl_get_home_by_path(self,
path: str, path: str,
config_bag: ConfigBag, config_bag: ConfigBag,
validate_properties=True) -> ('Subconfig', str): validate_properties=True,
) -> ('Subconfig', str):
""":returns: tuple (config, name)""" """:returns: tuple (config, name)"""
path = path.split('.') path = path.split('.')
for step in path[:-1]: for step in path[:-1]:
option_bag = OptionBag() option_bag = OptionBag()
option = await self.cfgimpl_get_description().get_child(step, option = await self.cfgimpl_get_description().get_child(step,
config_bag, config_bag,
self.cfgimpl_get_path()) self.cfgimpl_get_path(),
)
option_bag.set_option(option, option_bag.set_option(option,
None, None,
config_bag) config_bag,
)
option_bag.properties = await self.cfgimpl_get_settings().getproperties(option_bag) option_bag.properties = await self.cfgimpl_get_settings().getproperties(option_bag)
self = await self.get_subconfig(option_bag, self = await self.get_subconfig(option_bag,
validate_properties) validate_properties,
)
assert isinstance(self, SubConfig), _('unknown option {}').format(path[-1]) assert isinstance(self, SubConfig), _('unknown option {}').format(path[-1])
return self, path[-1] return self, path[-1]
@ -286,7 +291,8 @@ class SubConfig:
config_bag = option_bag.config_bag config_bag = option_bag.config_bag
if '.' in name: if '.' in name:
self, name = await self.cfgimpl_get_home_by_path(name, self, name = await self.cfgimpl_get_home_by_path(name,
config_bag) config_bag,
)
option = option_bag.option option = option_bag.option
if option.impl_is_symlinkoption(): if option.impl_is_symlinkoption():
@ -392,7 +398,8 @@ class SubConfig:
try: try:
if '.' in path: if '.' in path:
subconfig, subpath = await context.cfgimpl_get_home_by_path(path, subconfig, subpath = await context.cfgimpl_get_home_by_path(path,
config_bag) config_bag,
)
else: else:
subconfig = self subconfig = self
subpath = path subpath = path
@ -891,7 +898,8 @@ class KernelGroupConfig(_CommonConfig):
cconfig_bag.permissives = permissives cconfig_bag.permissives = permissives
try: try:
subconfig, name = await child.cfgimpl_get_home_by_path(path, subconfig, name = await child.cfgimpl_get_home_by_path(path,
cconfig_bag) cconfig_bag,
)
option = await subconfig.cfgimpl_get_description().get_child(name, option = await subconfig.cfgimpl_get_description().get_child(name,
cconfig_bag, cconfig_bag,
child.cfgimpl_get_path()) child.cfgimpl_get_path())
@ -988,7 +996,8 @@ class KernelGroupConfig(_CommonConfig):
config_bag.connection = connection config_bag.connection = connection
config_bag.remove_validation() config_bag.remove_validation()
subconfig, name = await child.cfgimpl_get_home_by_path(path, subconfig, name = await child.cfgimpl_get_home_by_path(path,
config_bag) config_bag,
)
option = await subconfig.cfgimpl_get_description().get_child(name, option = await subconfig.cfgimpl_get_description().get_child(name,
config_bag, config_bag,
subconfig.cfgimpl_get_path()) subconfig.cfgimpl_get_path())
@ -1079,7 +1088,8 @@ class KernelMixConfig(KernelGroupConfig):
only_config=only_config) only_config=only_config)
ret = [] ret = []
subconfig, name = await self.cfgimpl_get_home_by_path(path, subconfig, name = await self.cfgimpl_get_home_by_path(path,
config_bag) config_bag,
)
option = await subconfig.cfgimpl_get_description().get_child(name, option = await subconfig.cfgimpl_get_description().get_child(name,
config_bag, config_bag,
self.cfgimpl_get_path()) self.cfgimpl_get_path())
@ -1103,7 +1113,8 @@ class KernelMixConfig(KernelGroupConfig):
cconfig_bag.permissives = permissives cconfig_bag.permissives = permissives
try: try:
subconfig2, name = await child.cfgimpl_get_home_by_path(path, subconfig2, name = await child.cfgimpl_get_home_by_path(path,
cconfig_bag) cconfig_bag,
)
if self.impl_type == 'meta': if self.impl_type == 'meta':
moption_bag = option_bag.copy() moption_bag = option_bag.copy()
del moption_bag.properties del moption_bag.properties
@ -1169,7 +1180,8 @@ class KernelMixConfig(KernelGroupConfig):
rconfig_bag.remove_validation() rconfig_bag.remove_validation()
if self.impl_type == 'meta': if self.impl_type == 'meta':
subconfig, name = await self.cfgimpl_get_home_by_path(path, subconfig, name = await self.cfgimpl_get_home_by_path(path,
config_bag) config_bag,
)
option = await subconfig.cfgimpl_get_description().get_child(name, option = await subconfig.cfgimpl_get_description().get_child(name,
config_bag, config_bag,
subconfig.cfgimpl_get_path()) subconfig.cfgimpl_get_path())
@ -1181,7 +1193,8 @@ class KernelMixConfig(KernelGroupConfig):
elif not only_children: elif not only_children:
try: try:
subconfig, name = await self.cfgimpl_get_home_by_path(path, subconfig, name = await self.cfgimpl_get_home_by_path(path,
config_bag) config_bag,
)
option = await subconfig.cfgimpl_get_description().get_child(name, option = await subconfig.cfgimpl_get_description().get_child(name,
config_bag, config_bag,
subconfig.cfgimpl_get_path()) subconfig.cfgimpl_get_path())
@ -1200,7 +1213,8 @@ class KernelMixConfig(KernelGroupConfig):
moption_bag.config_bag = rconfig_bag moption_bag.config_bag = rconfig_bag
else: else:
subconfig, name = await child.cfgimpl_get_home_by_path(path, subconfig, name = await child.cfgimpl_get_home_by_path(path,
rconfig_bag) rconfig_bag,
)
option = await subconfig.cfgimpl_get_description().get_child(name, option = await subconfig.cfgimpl_get_description().get_child(name,
rconfig_bag, rconfig_bag,
child.cfgimpl_get_path()) child.cfgimpl_get_path())

View file

@ -178,10 +178,16 @@ class OptionDescriptionWalk(CacheOptionDescription):
async def get_child(self, async def get_child(self,
name: str, name: str,
config_bag: ConfigBag, config_bag: ConfigBag,
subpath: str) -> Union[BaseOption, SynDynOptionDescription]: subpath: str,
) -> Union[BaseOption, SynDynOptionDescription]:
# if not dyn # if not dyn
if name in self._children[0]: if name in self._children[0]:
return self._children[1][self._children[0].index(name)] option = self._children[1][self._children[0].index(name)]
if option.issubdyn():
raise AttributeError(_(f'unknown option "{name}" '
"in root optiondescription (it's a dynamic option)"
))
return option
# if dyn # if dyn
for child in self._children[1]: for child in self._children[1]:
if child.impl_is_dynoptiondescription(): if child.impl_is_dynoptiondescription():
@ -193,13 +199,13 @@ class OptionDescriptionWalk(CacheOptionDescription):
suffix, suffix,
child) child)
if self.impl_get_group_type() == groups.root: if self.impl_get_group_type() == groups.root:
raise AttributeError(_('unknown option "{0}" ' raise AttributeError(_(f'unknown option "{name}" '
'in root optiondescription' 'in root optiondescription'
'').format(name)) ))
else: else:
raise AttributeError(_('unknown option "{0}" ' raise AttributeError(_(f'unknown option "{name}" '
'in optiondescription "{1}"' f'in optiondescription "{self.impl_get_display_name()}"'
'').format(name, self.impl_get_display_name())) ))
async def get_children(self, async def get_children(self,
config_bag: Union[ConfigBag, Undefined], config_bag: Union[ConfigBag, Undefined],