add context property force_store_value

This commit is contained in:
2019-02-21 19:33:39 +01:00
parent 0a3b0e913f
commit 04b7d2bbc9
7 changed files with 64 additions and 25 deletions

View File

@ -906,12 +906,17 @@ class TiramisuContextProperty(TiramisuContext):
def read_only(self):
"""Set config to read only mode"""
old_props = self._config_bag.properties
settings = self._config_bag.context.cfgimpl_get_settings()
settings.read_only(self._config_bag.context)
del self._config_bag.properties
if 'force_store_value' not in old_props and \
'force_store_value' in self._config_bag.properties:
self._force_store_value()
def read_write(self):
"""Set config to read and write mode"""
old_props = self._config_bag.properties
settings = self._config_bag.context.cfgimpl_get_settings()
settings.read_write(self._config_bag.context)
#FIXME ?
@ -919,6 +924,9 @@ class TiramisuContextProperty(TiramisuContext):
settings.set_context_permissives(permissives)
#/FIXME ?
del self._config_bag.properties
if 'force_store_value' not in old_props and \
'force_store_value' in self._config_bag.properties:
self._force_store_value()
def add(self, prop):
"""Add a config property"""
@ -939,10 +947,16 @@ class TiramisuContextProperty(TiramisuContext):
def set(self, props):
"""Personalise config properties"""
if 'force_store_value' in props:
force_store_value = 'force_store_value' not in self._config_bag.properties
else:
force_store_value = False
context = self._config_bag.context
context.cfgimpl_get_settings().set_context_properties(props,
context)
del self._config_bag.properties
if force_store_value:
self._force_store_value()
def reset(self):
"""Remove config properties"""
@ -957,10 +971,20 @@ class TiramisuContextProperty(TiramisuContext):
def importation(self, properties):
"""Import config properties"""
if 'force_store_value' in properties:
force_store_value = 'force_store_value' not in self._config_bag.properties
else:
force_store_value = False
self._config_bag.context.cfgimpl_get_settings()._p_.importation(properties)
self._config_bag.context.cfgimpl_reset_cache(None,
None)
del self._config_bag.properties
if force_store_value:
self._force_store_value()
def _force_store_value(self):
descr = self._config_bag.context.cfgimpl_get_description()
descr.impl_build_force_store_values(self._config_bag)
class TiramisuContextPermissive(TiramisuContext):
@ -1150,8 +1174,8 @@ class _TiramisuContextConfig(TiramisuContext, _TiramisuContextConfigReset):
persistent=False,
storage=None):
return Config(self._config_bag.context.duplicate(session_id,
persistent=persistent,
storage=storage))
persistent=persistent,
storage=storage))
def deepcopy(self,
session_id=None,

View File

@ -682,8 +682,8 @@ class _CommonConfig(SubConfig):
persistent=persistent,
storage=storage)
duplicated_config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation())
duplicated_config.cfgimpl_get_settings()._p_.importation(self.cfgimpl_get_settings(
)._p_.exportation())
properties = self.cfgimpl_get_settings()._p_.exportation()
duplicated_config.cfgimpl_get_settings()._p_.importation(properties)
duplicated_config.cfgimpl_get_settings()._pp_.importation(self.cfgimpl_get_settings(
)._pp_.exportation())
if child is not None:

View File

@ -170,10 +170,12 @@ class CacheOptionDescription(BaseOption):
def impl_build_force_store_values(self,
config_bag: ConfigBag) -> None:
commit = False
if not hasattr(self, '_cache_force_store_values'):
raise ConfigError(_('option description seems to be part of an other '
'config'))
if 'force_store_value' not in config_bag.properties:
return
commit = False
values = config_bag.context.cfgimpl_get_values()
for subpath, option in self._cache_force_store_values:
if not values._p_.hasvalue(subpath):

View File

@ -102,14 +102,16 @@ read_write
you can set all variables not frozen
"""
ro_append = set(['frozen', 'disabled', 'validator', 'everything_frozen',
'mandatory', 'empty'])
'mandatory', 'empty', 'force_store_value'])
ro_remove = set(['permissive', 'hidden'])
rw_append = set(['frozen', 'disabled', 'validator', 'hidden'])
rw_append = set(['frozen', 'disabled', 'validator', 'hidden',
'force_store_value'])
rw_remove = set(['permissive', 'everything_frozen', 'mandatory', 'empty'])
FORBIDDEN_SET_PROPERTIES = frozenset(['force_store_value'])
FORBIDDEN_SET_PERMISSIVES = frozenset(['force_default_on_freeze', 'force_default_on_freeze'])
FORBIDDEN_SET_PERMISSIVES = frozenset(['force_default_on_freeze',
'force_store_value'])
log = getLogger('tiramisu')
@ -711,7 +713,8 @@ class Settings(object):
config_permissives):
properties = option_properties & config_properties - {'frozen',
'mandatory',
'empty'}
'empty',
'force_store_value'}
# remove global permissive properties
if properties and ('permissive' in config_properties):
properties -= config_permissives

View File

@ -57,6 +57,7 @@ class Properties(Cache):
return copy(self._properties)
def importation(self, properties):
self.reset_all_cache()
self._properties = properties