force_store_value for follower

This commit is contained in:
Emmanuel Garette 2019-11-19 18:46:05 +01:00
parent 7325f6e12f
commit c5d8e0055b
2 changed files with 61 additions and 19 deletions

View file

@ -76,9 +76,7 @@ class Leadership(OptionDescription):
self.impl_get_display_name()))
if idx != 0:
# remove empty property for follower
child_properties = list(child._properties)
child_properties.remove('empty')
child._properties = frozenset(child_properties)
child._properties = frozenset(child._properties - {'empty', 'unique'})
followers.append(child)
child._add_dependency(self)
child._leadership = weakref.ref(self)
@ -129,6 +127,33 @@ class Leadership(OptionDescription):
values.reset(soption_bag,
_commit=_commit)
def follower_force_store_value(self,
values,
value,
option_bag,
owner,
_commit) -> None:
settings = option_bag.config_bag.context.cfgimpl_get_settings()
if value:
rgevalue = range(len(value))
for follower in self.get_children(option_bag.config_bag):
foption_bag = OptionBag()
foption_bag.set_option(follower,
follower.impl_getpath(),
None,
option_bag.config_bag)
if 'force_store_value' in settings.getproperties(foption_bag):
for index in rgevalue:
foption_bag = OptionBag()
foption_bag.set_option(follower,
follower.impl_getpath(),
index,
option_bag.config_bag)
values._setvalue(foption_bag,
values.getvalue(foption_bag),
owner,
commit=False)
def pop(self,
values: Values,
index: int,

View file

@ -80,11 +80,6 @@ class CacheOptionDescription(BaseOption):
properties = option.impl_getproperties()
if 'force_store_value' in properties:
if __debug__:
if option.impl_is_follower():
# problem with index
raise ConfigError(_('the follower "{0}" cannot have '
'"force_store_value" property').format(
option.impl_get_display_name()))
if option.issubdyn():
raise ConfigError(_('the dynoption "{0}" cannot have '
'"force_store_value" property').format(
@ -125,17 +120,39 @@ class CacheOptionDescription(BaseOption):
values = config_bag.context.cfgimpl_get_values()
for subpath, option in self._cache_force_store_values:
if not values._p_.hasvalue(subpath):
option_bag = OptionBag()
option_bag.set_option(option,
subpath,
None,
config_bag)
option_bag.properties = frozenset()
values._p_.setvalue(subpath,
values.getvalue(option_bag),
owners.forced,
None,
False)
if option.impl_is_follower():
option_bag = OptionBag()
leader = option.impl_get_leadership().get_leader()
option_bag.set_option(leader,
leader.impl_getpath(),
None,
config_bag)
option_bag.properties = frozenset()
follower_len = len(values.getvalue(option_bag))
for index in range(follower_len):
option_bag = OptionBag()
option_bag.set_option(option,
subpath,
index,
config_bag)
option_bag.properties = frozenset()
values._p_.setvalue(subpath,
values.getvalue(option_bag),
owners.forced,
index,
False)
else:
option_bag = OptionBag()
option_bag.set_option(option,
subpath,
None,
config_bag)
option_bag.properties = frozenset()
values._p_.setvalue(subpath,
values.getvalue(option_bag),
owners.forced,
None,
False)
commit = True
if commit: