do not add suffix for suboption in dynamic optiondescription

This commit is contained in:
egarette@silique.fr 2023-11-17 22:39:33 +01:00
parent 4b052c3943
commit 73c8db5839
8 changed files with 760 additions and 777 deletions

File diff suppressed because it is too large Load diff

View file

@ -699,7 +699,7 @@ def test_mandatory_dyndescription():
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
cfg.property.read_only()
compare(cfg.value.mandatory(), ['od.dodval1.stval1', 'od.dodval2.stval2'])
compare(cfg.value.mandatory(), ['od.dodval1.st', 'od.dodval2.st'])
def test_mandatory_dyndescription_context():
@ -710,7 +710,7 @@ def test_mandatory_dyndescription_context():
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
cfg.property.read_only()
compare(cfg.value.mandatory(), ['od.dodval1.stval1', 'od.dodval2.stval2'])
compare(cfg.value.mandatory(), ['od.dodval1.st', 'od.dodval2.st'])
def test_mandatory_callback_leader_and_followers_leader():

View file

@ -197,33 +197,15 @@ class _SubConfig:
resetted_opts,
):
option = option_bag.option
if isinstance(option, (Option, Leadership)):
dynoption = option.getsubdyn()
if isinstance(option, Option):
rootpath = dynoption.impl_getpath()
subpaths = [rootpath] + option.impl_getpath()[len(rootpath) + 1:].split('.')[:-1]
elif isinstance(option, DynOptionDescription):
path = option.impl_getpath()
if '.' in path:
subpath = path.rsplit('.', 1)[0]
else:
subpath = ''
if isinstance(option, DynOptionDescription):
dynoption = option
for suffix in dynoption.get_suffixes(option_bag.config_bag):
path_suffix = dynoption.convert_suffix_to_path(suffix)
if isinstance(option, Option):
subpath = '.'.join([subp + path_suffix for subp in subpaths])
elif isinstance(option, Leadership):
subpath = option.impl_getpath() + path_suffix
doption = option.to_dynoption(subpath,
suffix,
dynoption,
)
doption_bag = OptionBag(doption,
option_bag.index,
else:
dynoption = option.getsubdyn()
for doption_bag in dynoption.get_sub_children(option,
option_bag.config_bag,
properties=None,
)
option_bag.index,
properties=None
):
self.reset_one_option_cache(resetted_opts,
doption_bag,
)
@ -493,23 +475,10 @@ class _SubConfig:
suboption = option.impl_getopt()
if suboption.issubdyn():
dynopt = suboption.getsubdyn()
rootpath = dynopt.impl_getpath()
subpaths = [rootpath] + suboption.impl_getpath()[len(rootpath) + 1:].split('.')[:-1]
ret = []
for suffix in dynopt.get_suffixes(option_bag.config_bag):
path_suffix = dynopt.convert_suffix_to_path(suffix)
subpath = '.'.join([subp + path_suffix for subp in subpaths])
doption = suboption.to_dynoption(subpath,
suffix,
dynopt,
)
doption_bag = OptionBag(doption,
option_bag.index,
return list(dynopt.get_sub_children(suboption,
option_bag.config_bag,
ori_option=option
)
ret.append(doption_bag)
return ret
option_bag.index,
))
if suboption.impl_is_follower():
options_bag = self.get_sub_option_bag(option_bag.config_bag, # pylint: disable=no-member
suboption.impl_getpath(),

View file

@ -30,7 +30,7 @@ from ..autolib import ParamOption
from ..i18n import _
from .optiondescription import OptionDescription
from .baseoption import BaseOption
from ..setting import OptionBag, ConfigBag
from ..setting import OptionBag, ConfigBag, undefined
from ..error import ConfigError
from ..autolib import Calculation
@ -118,3 +118,31 @@ class DynOptionDescription(OptionDescription):
def impl_is_dynoptiondescription(self) -> bool:
return True
def get_sub_children(self,
option,
config_bag,
index=None,
properties=undefined,
):
if option == self:
rootpath = self.impl_getpath().rsplit('.', 1)[0]
else:
rootpath = self.impl_getpath()
subpath = option.impl_getpath()[len(rootpath):].rsplit('.', 1)[0]
for suffix in self.get_suffixes(config_bag):
path_suffix = self.convert_suffix_to_path(suffix)
if option == self:
parent_path = rootpath
else:
parent_path = rootpath + path_suffix + subpath
doption_bag = OptionBag(option.to_dynoption(parent_path,
suffix,
self,
),
index,
config_bag,
properties=properties,
ori_option=option
)
yield doption_bag

View file

@ -125,21 +125,10 @@ class CacheOptionDescription(BaseOption):
def do_option_bags(option):
if option.issubdyn():
dynopt = option.getsubdyn()
rootpath = dynopt.impl_getpath()
subpaths = [rootpath] + option.impl_getpath()[len(rootpath) + 1:].split('.')[1:]
for suffix in dynopt.get_suffixes(config_bag):
path_suffix = dynopt.convert_suffix_to_path(suffix)
subpath = '.'.join([subp + path_suffix for subp in subpaths])
doption = option.to_dynoption(subpath,
suffix,
dynopt,
)
doption_bag = OptionBag(doption,
None,
yield from dynopt.get_sub_children(option,
config_bag,
properties=None,
None,
)
yield doption_bag
else:
option_bag = OptionBag(option,
None,
@ -211,7 +200,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
# if not dyn
if name in self._children[0]: # pylint: disable=no-member
option = self._children[1][self._children[0].index(name)] # pylint: disable=no-member
if option.issubdyn():
if option.impl_is_dynoptiondescription():
raise AttributeError(_(f'unknown option "{name}" '
"in root optiondescription (it's a dynamic option)"
))

View file

@ -53,7 +53,8 @@ class SynDynOption:
def impl_getname(self) -> str:
"""get option name
"""
return self.opt.impl_getname() + self.dyn_parent.convert_suffix_to_path(self.suffix)
return self.opt.impl_getname()
#return self.opt.impl_getname() + self.dyn_parent.convert_suffix_to_path(self.suffix)
def impl_get_display_name(self) -> str:
"""get option display name

View file

@ -65,13 +65,10 @@ class SynDynOptionDescription:
"""get child by name
"""
# pylint: disable=unused-argument
suffix = self.ori_dyn.convert_suffix_to_path(self._suffix)
if name.endswith(suffix):
oname = name[:-len(suffix)]
try:
child = self._children[1][self._children[0].index(oname)]
child = self._children[1][self._children[0].index(name)]
except ValueError:
# when oname not in self._children
# when name not in self._children
pass
else:
return child.to_dynoption(subpath,
@ -84,6 +81,8 @@ class SynDynOptionDescription:
def impl_getname(self) -> str:
"""get name
"""
if isinstance(self, SynDynLeadership):
return self.opt.impl_getname()
return self.opt.impl_getname() + self.ori_dyn.convert_suffix_to_path(self._suffix)
def get_children(self,

View file

@ -350,11 +350,8 @@ class Values:
rootpath = option.impl_getpath()
for suffix in option.get_suffixes(option_bag.config_bag):
for coption in force_store_options:
subpaths = [rootpath] + \
coption.impl_getpath()[len(rootpath) + 1:].split('.')[:-1]
path_suffix = option.convert_suffix_to_path(suffix)
subpath = '.'.join([subp + path_suffix for subp in subpaths])
doption = coption.to_dynoption(subpath,
parent_subpath = rootpath + suffix + coption.impl_getpath()[len(rootpath):].rsplit('.', 1)[0]
doption = coption.to_dynoption(parent_subpath,
suffix,
option,
)