From c5d8e0055b93fa4aa71fec43ee17676d8e821721 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 19 Nov 2019 18:46:05 +0100 Subject: [PATCH] force_store_value for follower --- tiramisu/option/leadership.py | 31 ++++++++++++++++-- tiramisu/option/optiondescription.py | 49 +++++++++++++++++++--------- 2 files changed, 61 insertions(+), 19 deletions(-) diff --git a/tiramisu/option/leadership.py b/tiramisu/option/leadership.py index 4a63854..19ec78a 100644 --- a/tiramisu/option/leadership.py +++ b/tiramisu/option/leadership.py @@ -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, diff --git a/tiramisu/option/optiondescription.py b/tiramisu/option/optiondescription.py index 845310b..b754fdb 100644 --- a/tiramisu/option/optiondescription.py +++ b/tiramisu/option/optiondescription.py @@ -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: