path for dyn option with leadership in calculation
This commit is contained in:
parent
2ea43832e5
commit
d6f1564744
2 changed files with 29 additions and 27 deletions
|
@ -363,9 +363,11 @@ async def manager_callback(callbk: Param,
|
||||||
callbk_option.impl_get_display_name(),
|
callbk_option.impl_get_display_name(),
|
||||||
))
|
))
|
||||||
#FIXME in same dynamic option?
|
#FIXME in same dynamic option?
|
||||||
rootpath = option.rootpath
|
|
||||||
suffix = option.impl_getsuffix()
|
suffix = option.impl_getsuffix()
|
||||||
|
rootpath = option.rootpath
|
||||||
subdyn = callbk_option.getsubdyn()
|
subdyn = callbk_option.getsubdyn()
|
||||||
|
if len(callbk_option.impl_getpath().split('.')) == len(rootpath.split('.')):
|
||||||
|
rootpath = rootpath.rsplit('.', 1)[0]
|
||||||
callbk_option = callbk_option.to_dynoption(rootpath,
|
callbk_option = callbk_option.to_dynoption(rootpath,
|
||||||
suffix,
|
suffix,
|
||||||
subdyn)
|
subdyn)
|
||||||
|
|
|
@ -29,7 +29,7 @@ from .syndynoption import SynDynOption
|
||||||
|
|
||||||
|
|
||||||
class SynDynOptionDescription:
|
class SynDynOptionDescription:
|
||||||
__slots__ = ('_opt',
|
__slots__ = ('opt',
|
||||||
'rootpath',
|
'rootpath',
|
||||||
'_suffix',
|
'_suffix',
|
||||||
'ori_dyn')
|
'ori_dyn')
|
||||||
|
@ -39,7 +39,7 @@ class SynDynOptionDescription:
|
||||||
rootpath: str,
|
rootpath: str,
|
||||||
suffix: str,
|
suffix: str,
|
||||||
ori_dyn) -> None:
|
ori_dyn) -> None:
|
||||||
self._opt = opt
|
self.opt = opt
|
||||||
if rootpath is None:
|
if rootpath is None:
|
||||||
rootpath = ''
|
rootpath = ''
|
||||||
assert isinstance(rootpath, str), 'rootpath must be a string, not {}'.format(type(rootpath))
|
assert isinstance(rootpath, str), 'rootpath must be a string, not {}'.format(type(rootpath))
|
||||||
|
@ -50,12 +50,12 @@ class SynDynOptionDescription:
|
||||||
|
|
||||||
def __getattr__(self,
|
def __getattr__(self,
|
||||||
name: str) -> Any:
|
name: str) -> Any:
|
||||||
# if not in SynDynOptionDescription, get value in self._opt
|
# if not in SynDynOptionDescription, get value in self.opt
|
||||||
return getattr(self._opt,
|
return getattr(self.opt,
|
||||||
name)
|
name)
|
||||||
|
|
||||||
def impl_getopt(self) -> BaseOption:
|
def impl_getopt(self) -> BaseOption:
|
||||||
return self._opt
|
return self.opt
|
||||||
|
|
||||||
async def get_child(self,
|
async def get_child(self,
|
||||||
name: str,
|
name: str,
|
||||||
|
@ -71,13 +71,13 @@ class SynDynOptionDescription:
|
||||||
else:
|
else:
|
||||||
return child.to_dynoption(subpath,
|
return child.to_dynoption(subpath,
|
||||||
self._suffix,
|
self._suffix,
|
||||||
self._opt)
|
self.opt)
|
||||||
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()))
|
||||||
|
|
||||||
def impl_getname(self) -> str:
|
def impl_getname(self) -> str:
|
||||||
return self._opt.impl_getname() + self._suffix
|
return self.opt.impl_getname() + self._suffix
|
||||||
|
|
||||||
def impl_is_dynoptiondescription(self) -> bool:
|
def impl_is_dynoptiondescription(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
@ -88,10 +88,10 @@ class SynDynOptionDescription:
|
||||||
):
|
):
|
||||||
subpath = self.impl_getpath()
|
subpath = self.impl_getpath()
|
||||||
children = []
|
children = []
|
||||||
for child in await self._opt.get_children(config_bag):
|
for child in await self.opt.get_children(config_bag):
|
||||||
children.append(child.to_dynoption(subpath,
|
children.append(child.to_dynoption(subpath,
|
||||||
self._suffix,
|
self._suffix,
|
||||||
self._opt))
|
self.opt))
|
||||||
return children
|
return children
|
||||||
|
|
||||||
def impl_is_dynsymlinkoption(self) -> bool:
|
def impl_is_dynsymlinkoption(self) -> bool:
|
||||||
|
@ -102,10 +102,10 @@ class SynDynOptionDescription:
|
||||||
byname: Optional[str],
|
byname: Optional[str],
|
||||||
config_bag: ConfigBag,
|
config_bag: ConfigBag,
|
||||||
self_opt: BaseOption=None) -> BaseOption:
|
self_opt: BaseOption=None) -> BaseOption:
|
||||||
async for option in self._opt.get_children_recursively(bytype,
|
async for option in self.opt.get_children_recursively(bytype,
|
||||||
byname,
|
byname,
|
||||||
config_bag,
|
config_bag,
|
||||||
self):
|
self):
|
||||||
yield option
|
yield option
|
||||||
|
|
||||||
def impl_getpath(self) -> str:
|
def impl_getpath(self) -> str:
|
||||||
|
@ -115,18 +115,18 @@ class SynDynOptionDescription:
|
||||||
return rootpath + self.impl_getname()
|
return rootpath + self.impl_getname()
|
||||||
|
|
||||||
def impl_get_display_name(self) -> str:
|
def impl_get_display_name(self) -> str:
|
||||||
return self._opt.impl_get_display_name() + self._suffix
|
return self.opt.impl_get_display_name() + self._suffix
|
||||||
|
|
||||||
|
|
||||||
class SynDynLeadership(SynDynOptionDescription):
|
class SynDynLeadership(SynDynOptionDescription):
|
||||||
def get_leader(self) -> SynDynOption:
|
def get_leader(self) -> SynDynOption:
|
||||||
return self._opt.get_leader().to_dynoption(self.impl_getpath(),
|
return self.opt.get_leader().to_dynoption(self.impl_getpath(),
|
||||||
self._suffix,
|
self._suffix,
|
||||||
self.ori_dyn)
|
self.ori_dyn)
|
||||||
|
|
||||||
def get_followers(self) -> Iterator[SynDynOption]:
|
def get_followers(self) -> Iterator[SynDynOption]:
|
||||||
subpath = self.impl_getpath()
|
subpath = self.impl_getpath()
|
||||||
for follower in self._opt.get_followers():
|
for follower in self.opt.get_followers():
|
||||||
yield follower.to_dynoption(subpath,
|
yield follower.to_dynoption(subpath,
|
||||||
self._suffix,
|
self._suffix,
|
||||||
self.ori_dyn)
|
self.ori_dyn)
|
||||||
|
@ -146,20 +146,20 @@ class SynDynLeadership(SynDynOptionDescription):
|
||||||
async def pop(self,
|
async def pop(self,
|
||||||
*args,
|
*args,
|
||||||
**kwargs) -> None:
|
**kwargs) -> None:
|
||||||
await self._opt.pop(*args,
|
await self.opt.pop(*args,
|
||||||
followers=self.get_followers(),
|
followers=self.get_followers(),
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
async def follower_force_store_value(self,
|
async def follower_force_store_value(self,
|
||||||
values,
|
values,
|
||||||
value,
|
value,
|
||||||
option_bag,
|
option_bag,
|
||||||
owner) -> None:
|
owner) -> None:
|
||||||
await self._opt.follower_force_store_value(values,
|
await self.opt.follower_force_store_value(values,
|
||||||
value,
|
value,
|
||||||
option_bag,
|
option_bag,
|
||||||
owner,
|
owner,
|
||||||
dyn=self)
|
dyn=self)
|
||||||
|
|
||||||
def impl_getsuffix(self) -> str:
|
def impl_getsuffix(self) -> str:
|
||||||
return self._suffix
|
return self._suffix
|
||||||
|
|
Loading…
Reference in a new issue