do not add suffix for suboption in dynamic optiondescription
This commit is contained in:
parent
4b052c3943
commit
73c8db5839
8 changed files with 760 additions and 777 deletions
File diff suppressed because it is too large
Load diff
|
@ -699,7 +699,7 @@ def test_mandatory_dyndescription():
|
||||||
od2 = OptionDescription('od', '', [od])
|
od2 = OptionDescription('od', '', [od])
|
||||||
cfg = Config(od2)
|
cfg = Config(od2)
|
||||||
cfg.property.read_only()
|
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():
|
def test_mandatory_dyndescription_context():
|
||||||
|
@ -710,7 +710,7 @@ def test_mandatory_dyndescription_context():
|
||||||
od2 = OptionDescription('od', '', [od])
|
od2 = OptionDescription('od', '', [od])
|
||||||
cfg = Config(od2)
|
cfg = Config(od2)
|
||||||
cfg.property.read_only()
|
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():
|
def test_mandatory_callback_leader_and_followers_leader():
|
||||||
|
|
|
@ -197,33 +197,15 @@ class _SubConfig:
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
):
|
):
|
||||||
option = option_bag.option
|
option = option_bag.option
|
||||||
if isinstance(option, (Option, Leadership)):
|
if isinstance(option, DynOptionDescription):
|
||||||
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 = ''
|
|
||||||
dynoption = option
|
dynoption = option
|
||||||
for suffix in dynoption.get_suffixes(option_bag.config_bag):
|
else:
|
||||||
path_suffix = dynoption.convert_suffix_to_path(suffix)
|
dynoption = option.getsubdyn()
|
||||||
if isinstance(option, Option):
|
for doption_bag in dynoption.get_sub_children(option,
|
||||||
subpath = '.'.join([subp + path_suffix for subp in subpaths])
|
option_bag.config_bag,
|
||||||
elif isinstance(option, Leadership):
|
option_bag.index,
|
||||||
subpath = option.impl_getpath() + path_suffix
|
properties=None
|
||||||
doption = option.to_dynoption(subpath,
|
):
|
||||||
suffix,
|
|
||||||
dynoption,
|
|
||||||
)
|
|
||||||
doption_bag = OptionBag(doption,
|
|
||||||
option_bag.index,
|
|
||||||
option_bag.config_bag,
|
|
||||||
properties=None,
|
|
||||||
)
|
|
||||||
self.reset_one_option_cache(resetted_opts,
|
self.reset_one_option_cache(resetted_opts,
|
||||||
doption_bag,
|
doption_bag,
|
||||||
)
|
)
|
||||||
|
@ -493,23 +475,10 @@ class _SubConfig:
|
||||||
suboption = option.impl_getopt()
|
suboption = option.impl_getopt()
|
||||||
if suboption.issubdyn():
|
if suboption.issubdyn():
|
||||||
dynopt = suboption.getsubdyn()
|
dynopt = suboption.getsubdyn()
|
||||||
rootpath = dynopt.impl_getpath()
|
return list(dynopt.get_sub_children(suboption,
|
||||||
subpaths = [rootpath] + suboption.impl_getpath()[len(rootpath) + 1:].split('.')[:-1]
|
option_bag.config_bag,
|
||||||
ret = []
|
option_bag.index,
|
||||||
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,
|
|
||||||
option_bag.config_bag,
|
|
||||||
ori_option=option
|
|
||||||
)
|
|
||||||
ret.append(doption_bag)
|
|
||||||
return ret
|
|
||||||
if suboption.impl_is_follower():
|
if suboption.impl_is_follower():
|
||||||
options_bag = self.get_sub_option_bag(option_bag.config_bag, # pylint: disable=no-member
|
options_bag = self.get_sub_option_bag(option_bag.config_bag, # pylint: disable=no-member
|
||||||
suboption.impl_getpath(),
|
suboption.impl_getpath(),
|
||||||
|
|
|
@ -30,7 +30,7 @@ from ..autolib import ParamOption
|
||||||
from ..i18n import _
|
from ..i18n import _
|
||||||
from .optiondescription import OptionDescription
|
from .optiondescription import OptionDescription
|
||||||
from .baseoption import BaseOption
|
from .baseoption import BaseOption
|
||||||
from ..setting import OptionBag, ConfigBag
|
from ..setting import OptionBag, ConfigBag, undefined
|
||||||
from ..error import ConfigError
|
from ..error import ConfigError
|
||||||
from ..autolib import Calculation
|
from ..autolib import Calculation
|
||||||
|
|
||||||
|
@ -118,3 +118,31 @@ class DynOptionDescription(OptionDescription):
|
||||||
|
|
||||||
def impl_is_dynoptiondescription(self) -> bool:
|
def impl_is_dynoptiondescription(self) -> bool:
|
||||||
return True
|
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
|
||||||
|
|
|
@ -125,21 +125,10 @@ class CacheOptionDescription(BaseOption):
|
||||||
def do_option_bags(option):
|
def do_option_bags(option):
|
||||||
if option.issubdyn():
|
if option.issubdyn():
|
||||||
dynopt = option.getsubdyn()
|
dynopt = option.getsubdyn()
|
||||||
rootpath = dynopt.impl_getpath()
|
yield from dynopt.get_sub_children(option,
|
||||||
subpaths = [rootpath] + option.impl_getpath()[len(rootpath) + 1:].split('.')[1:]
|
config_bag,
|
||||||
for suffix in dynopt.get_suffixes(config_bag):
|
None,
|
||||||
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,
|
|
||||||
config_bag,
|
|
||||||
properties=None,
|
|
||||||
)
|
|
||||||
yield doption_bag
|
|
||||||
else:
|
else:
|
||||||
option_bag = OptionBag(option,
|
option_bag = OptionBag(option,
|
||||||
None,
|
None,
|
||||||
|
@ -211,7 +200,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||||
# if not dyn
|
# if not dyn
|
||||||
if name in self._children[0]: # pylint: disable=no-member
|
if name in self._children[0]: # pylint: disable=no-member
|
||||||
option = self._children[1][self._children[0].index(name)] # 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}" '
|
raise AttributeError(_(f'unknown option "{name}" '
|
||||||
"in root optiondescription (it's a dynamic option)"
|
"in root optiondescription (it's a dynamic option)"
|
||||||
))
|
))
|
||||||
|
|
|
@ -53,7 +53,8 @@ class SynDynOption:
|
||||||
def impl_getname(self) -> str:
|
def impl_getname(self) -> str:
|
||||||
"""get option name
|
"""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:
|
def impl_get_display_name(self) -> str:
|
||||||
"""get option display name
|
"""get option display name
|
||||||
|
|
|
@ -65,18 +65,15 @@ class SynDynOptionDescription:
|
||||||
"""get child by name
|
"""get child by name
|
||||||
"""
|
"""
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
suffix = self.ori_dyn.convert_suffix_to_path(self._suffix)
|
try:
|
||||||
if name.endswith(suffix):
|
child = self._children[1][self._children[0].index(name)]
|
||||||
oname = name[:-len(suffix)]
|
except ValueError:
|
||||||
try:
|
# when name not in self._children
|
||||||
child = self._children[1][self._children[0].index(oname)]
|
pass
|
||||||
except ValueError:
|
else:
|
||||||
# when oname not in self._children
|
return child.to_dynoption(subpath,
|
||||||
pass
|
self._suffix,
|
||||||
else:
|
self.ori_dyn)
|
||||||
return child.to_dynoption(subpath,
|
|
||||||
self._suffix,
|
|
||||||
self.ori_dyn)
|
|
||||||
raise AttributeError(_('unknown option "{0}" '
|
raise AttributeError(_('unknown option "{0}" '
|
||||||
'in dynamic optiondescription "{1}"'
|
'in dynamic optiondescription "{1}"'
|
||||||
'').format(name, self.impl_get_display_name()))
|
'').format(name, self.impl_get_display_name()))
|
||||||
|
@ -84,6 +81,8 @@ class SynDynOptionDescription:
|
||||||
def impl_getname(self) -> str:
|
def impl_getname(self) -> str:
|
||||||
"""get name
|
"""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)
|
return self.opt.impl_getname() + self.ori_dyn.convert_suffix_to_path(self._suffix)
|
||||||
|
|
||||||
def get_children(self,
|
def get_children(self,
|
||||||
|
|
|
@ -350,11 +350,8 @@ class Values:
|
||||||
rootpath = option.impl_getpath()
|
rootpath = option.impl_getpath()
|
||||||
for suffix in option.get_suffixes(option_bag.config_bag):
|
for suffix in option.get_suffixes(option_bag.config_bag):
|
||||||
for coption in force_store_options:
|
for coption in force_store_options:
|
||||||
subpaths = [rootpath] + \
|
parent_subpath = rootpath + suffix + coption.impl_getpath()[len(rootpath):].rsplit('.', 1)[0]
|
||||||
coption.impl_getpath()[len(rootpath) + 1:].split('.')[:-1]
|
doption = coption.to_dynoption(parent_subpath,
|
||||||
path_suffix = option.convert_suffix_to_path(suffix)
|
|
||||||
subpath = '.'.join([subp + path_suffix for subp in subpaths])
|
|
||||||
doption = coption.to_dynoption(subpath,
|
|
||||||
suffix,
|
suffix,
|
||||||
option,
|
option,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue