better way to manage follower in MetaConfig
This commit is contained in:
@ -345,17 +345,17 @@ class TiramisuOptionOwner(CommonTiramisuOption):
|
||||
|
||||
def get(self):
|
||||
"""Get owner for a specified option"""
|
||||
option = self._option_bag.option
|
||||
self._option_bag.option
|
||||
return self._values.getowner(self._option_bag)
|
||||
|
||||
def isdefault(self):
|
||||
"""Is option has defaut value"""
|
||||
option = self._option_bag.option
|
||||
self._option_bag.option
|
||||
return self._values.is_default_owner(self._option_bag)
|
||||
|
||||
def set(self, owner):
|
||||
"""Get owner for a specified option"""
|
||||
option = self._option_bag.option
|
||||
self._option_bag.option
|
||||
try:
|
||||
obj_owner = getattr(owners, owner)
|
||||
except AttributeError:
|
||||
|
@ -45,7 +45,6 @@ class Leadership(OptionDescription):
|
||||
children: List[BaseOption],
|
||||
requires=None,
|
||||
properties=None) -> None:
|
||||
|
||||
super().__init__(name,
|
||||
doc,
|
||||
children,
|
||||
|
@ -81,3 +81,7 @@ class SynDynOption:
|
||||
|
||||
def impl_is_dynsymlinkoption(self) -> bool:
|
||||
return True
|
||||
|
||||
def impl_get_leadership(self):
|
||||
return self.opt.impl_get_leadership().to_dynoption(self.rootpath,
|
||||
self.suffix)
|
||||
|
@ -259,12 +259,10 @@ class Values(object):
|
||||
|
||||
#______________________________________________________________________
|
||||
# set value
|
||||
|
||||
def setvalue(self,
|
||||
value,
|
||||
option_bag,
|
||||
_commit):
|
||||
|
||||
context = option_bag.config_bag.context
|
||||
owner = self.get_context_owner()
|
||||
if 'validator' in option_bag.config_bag.properties:
|
||||
@ -295,7 +293,6 @@ class Values(object):
|
||||
def setvalue_validation(self,
|
||||
value,
|
||||
option_bag):
|
||||
|
||||
settings = option_bag.config_bag.context.cfgimpl_get_settings()
|
||||
# First validate properties with this value
|
||||
opt = option_bag.option
|
||||
@ -317,7 +314,6 @@ class Values(object):
|
||||
value,
|
||||
owner,
|
||||
commit=True):
|
||||
|
||||
option_bag.config_bag.context.cfgimpl_reset_cache(option_bag)
|
||||
if isinstance(value, list):
|
||||
# copy
|
||||
@ -329,8 +325,8 @@ class Values(object):
|
||||
commit)
|
||||
|
||||
def _get_modified_parent(self,
|
||||
option_bag):
|
||||
""" Search in differents parents a Config with a modified value and return it
|
||||
option_bag: OptionBag) -> Optional[OptionBag]:
|
||||
""" Search in differents parents a Config with a modified value
|
||||
If not found, return None
|
||||
For follower option, return the Config where leader is modified
|
||||
"""
|
||||
@ -342,26 +338,6 @@ class Values(object):
|
||||
doption_bag.config_bag = config_bag
|
||||
return doption_bag
|
||||
|
||||
if option_bag.option.impl_is_follower():
|
||||
leader = option_bag.option.impl_get_leadership().get_leader()
|
||||
leaderpath = leader.impl_getpath()
|
||||
if self._p_.hasvalue(leaderpath,
|
||||
index=None):
|
||||
return None
|
||||
config_bag = option_bag.config_bag
|
||||
leader_option_bag = OptionBag()
|
||||
leader_option_bag.set_option(leader,
|
||||
leaderpath,
|
||||
None,
|
||||
config_bag)
|
||||
leader_option_bag = self._get_modified_parent(leader_option_bag)
|
||||
if leader_option_bag is None:
|
||||
return None
|
||||
new_config_bag = leader_option_bag.config_bag
|
||||
if not new_config_bag.context.cfgimpl_get_values()._p_.hasvalue(option_bag.path,
|
||||
index=option_bag.index):
|
||||
return None
|
||||
return build_option_bag(option_bag, new_config_bag.context)
|
||||
for parent in option_bag.config_bag.context.get_parents():
|
||||
doption_bag = build_option_bag(option_bag, parent)
|
||||
if 'force_metaconfig_on_freeze' in option_bag.properties:
|
||||
@ -377,6 +353,7 @@ class Values(object):
|
||||
only_default=True)
|
||||
if parent_owner != owners.default:
|
||||
return doption_bag
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@ -417,7 +394,7 @@ class Values(object):
|
||||
if only_default:
|
||||
if self._p_.hasvalue(option_bag.path,
|
||||
option_bag.index):
|
||||
owner = option_bag
|
||||
owner = 'not_default'
|
||||
else:
|
||||
owner = owners.default
|
||||
else:
|
||||
|
Reference in New Issue
Block a user