add context property force_store_value

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

View file

@ -421,7 +421,7 @@ def test_cache_master_and_slaves_master():
cfg = Config(maconfig) cfg = Config(maconfig)
cfg.property.read_write() cfg.property.read_write()
cfg.value.dict() cfg.value.dict()
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings'] global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']
val1_props = [] val1_props = []
val1_val1_props = ['empty'] val1_val1_props = ['empty']
val1_val2_props = [] val1_val2_props = []
@ -450,7 +450,7 @@ def test_cache_master_and_slaves_master():
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}}) compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}})
# #
cfg.option('val1.val1').value.set([undefined]) cfg.option('val1.val1').value.set([undefined])
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(global_props), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
cfg.value.dict() cfg.value.dict()
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
@ -470,7 +470,7 @@ def test_cache_master_and_slaves_master():
cfg.option('val1.val1').value.set([undefined, undefined]) cfg.option('val1.val1').value.set([undefined, undefined])
cfg.value.dict() cfg.value.dict()
cfg.option('val1.val2', 1).value.set('oui') cfg.option('val1.val2', 1).value.set('oui')
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
val1_val2_props = {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)} val1_val2_props = {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)}
@ -497,7 +497,7 @@ def test_cache_master_callback():
cfg = Config(maconfig) cfg = Config(maconfig)
cfg.property.read_write() cfg.property.read_write()
cfg.value.dict() cfg.value.dict()
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings'] global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']
val1_props = [] val1_props = []
val1_val1_props = ['empty'] val1_val1_props = ['empty']
val1_val2_props = [] val1_val2_props = []
@ -522,7 +522,7 @@ def test_cache_master_callback():
'val1.val2': {None: (val1_val2_props, None)}}) 'val1.val2': {None: (val1_val2_props, None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}}) compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}})
cfg.option('val1.val1').value.set([undefined]) cfg.option('val1.val1').value.set([undefined])
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(global_props), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
cfg.value.dict() cfg.value.dict()
@ -544,7 +544,7 @@ def test_cache_requires():
cfg.property.pop('expire') cfg.property.pop('expire')
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
assert cfg.option('ip_address_service').value.get() == None assert cfg.option('ip_address_service').value.get() == None
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}}) 'ip_address_service': {None: (set([]), None)}})
@ -554,30 +554,30 @@ def test_cache_requires():
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)}, compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}}) 'activate_service': {None: (True, None)}})
cfg.value.dict() cfg.value.dict()
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}}) 'ip_address_service': {None: (set([]), None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)}, compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}}) 'activate_service': {None: (True, None)}})
cfg.option('ip_address_service').value.set('1.1.1.1') cfg.option('ip_address_service').value.set('1.1.1.1')
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)}}) 'activate_service': {None: (set([]), None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (True, None)}}) compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (True, None)}})
cfg.value.dict() cfg.value.dict()
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}}) 'ip_address_service': {None: (set([]), None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: ('1.1.1.1', None)}, compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: ('1.1.1.1', None)},
'activate_service': {None: (True, None)}}) 'activate_service': {None: (True, None)}})
cfg.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
cfg.value.dict() cfg.value.dict()
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set(['disabled']), None)}}) 'ip_address_service': {None: (set(['disabled']), None)}})
@ -593,7 +593,7 @@ def test_cache_global_properties():
cfg.property.read_write() cfg.property.read_write()
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
assert cfg.option('ip_address_service').value.get() == None assert cfg.option('ip_address_service').value.get() == None
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}}) 'ip_address_service': {None: (set([]), None)}})
@ -604,12 +604,12 @@ def test_cache_global_properties():
'activate_service': {None: (True, None)}}) 'activate_service': {None: (True, None)}})
cfg.property.pop('disabled') cfg.property.pop('disabled')
assert cfg.option('ip_address_service').value.get() == None assert cfg.option('ip_address_service').value.get() == None
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings']), None)}, compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}}) 'ip_address_service': {None: (set([]), None)}})
cfg.property.add('test') cfg.property.add('test')
assert cfg.option('ip_address_service').value.get() == None assert cfg.option('ip_address_service').value.get() == None
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test']), None)}, compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}}) 'ip_address_service': {None: (set([]), None)}})

View file

@ -72,8 +72,17 @@ def test_copy_force_store_value():
descr = make_description() descr = make_description()
conf = Config(descr) conf = Config(descr)
conf2 = Config(descr) conf2 = Config(descr)
assert to_tuple(conf.value.exportation()) == ((), (), (), ())
assert to_tuple(conf2.value.exportation()) == ((), (), (), ())
#
conf.property.read_write()
assert to_tuple(conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
assert to_tuple(conf2.value.exportation()) == ((), (), (), ())
#
conf2.property.read_only()
assert to_tuple(conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',)) assert to_tuple(conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
assert to_tuple(conf2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',)) assert to_tuple(conf2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
#
conf.option('creole.general.wantref').value.set(True) conf.option('creole.general.wantref').value.set(True)
assert to_tuple(conf.value.exportation()) == (('creole.general.wantref',), (None,), (True,), ('user',)) assert to_tuple(conf.value.exportation()) == (('creole.general.wantref',), (None,), (True,), ('user',))
assert to_tuple(conf2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',)) assert to_tuple(conf2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
@ -82,9 +91,9 @@ def test_copy_force_store_value():
def test_copy_force_store_value_metaconfig(): def test_copy_force_store_value_metaconfig():
descr = make_description() descr = make_description()
meta = MetaConfig([], optiondescription=descr) meta = MetaConfig([], optiondescription=descr)
meta.property.read_only()
conf = meta.config.new(session_id='conf') conf = meta.config.new(session_id='conf')
assert meta.property.get() == conf.property.get() assert meta.property.get() == conf.property.get()
assert meta.permissive.get() == conf.permissive.get() assert meta.permissive.get() == conf.permissive.get()
conf.property.read_write()
assert to_tuple(conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',)) assert to_tuple(conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
assert to_tuple(meta.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',)) assert to_tuple(meta.value.exportation()) == ((), (), (), ())

View file

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

View file

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

View file

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

View file

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

View file

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