force_store_value is now used directly when configuration is loaded

This commit is contained in:
2016-03-07 16:13:41 +01:00
parent 51d14f30a4
commit da89c1aa58
8 changed files with 120 additions and 106 deletions

View File

@ -23,7 +23,7 @@ import re
from ..i18n import _
from ..setting import groups, undefined # , log
from ..setting import groups, undefined, owners # , log
from .baseoption import BaseOption, SymLinkOption
from . import MasterSlaves
from ..error import ConfigError, ConflictError
@ -92,26 +92,35 @@ class OptionDescription(BaseOption, StorageOptionDescription):
"""
return _impl_getpaths(self, include_groups, _currpath)
def impl_build_cache(self, _consistencies=None, cache_option=None):
def impl_build_cache(self, config, path='', _consistencies=None,
cache_option=None, force_store_values=None):
"""validate duplicate option and set option has readonly option
"""
if cache_option is None:
init = True
_consistencies = {}
cache_option = []
force_store_values = []
else:
init = False
for option in self._impl_getchildren(dyn=False):
#FIXME specifique id for sqlalchemy?
#FIXME avec sqlalchemy ca marche le multi parent ? (dans des configs différentes)
cache_option.append(option._get_id())
if path == '':
subpath = option.impl_getname()
else:
subpath = path + '.' + option.impl_getname()
if isinstance(option, OptionDescription):
option._set_readonly(False)
option.impl_build_cache(_consistencies, cache_option)
option.impl_build_cache(config, subpath, _consistencies,
cache_option, force_store_values)
#cannot set multi option as OptionDescription requires
else:
option._set_readonly(True)
is_multi = option.impl_is_multi()
if 'force_store_value' in option.impl_getproperties():
force_store_values.append((subpath, option))
for func, all_cons_opts, params in option._get_consistencies():
option._valid_consistencies(all_cons_opts[1:])
if is_multi:
@ -175,6 +184,21 @@ class OptionDescription(BaseOption, StorageOptionDescription):
opt.impl_getname()))
self._cache_consistencies[opt] = tuple(cons)
self._set_readonly(False)
for subpath, option in force_store_values:
value = config.cfgimpl_get_values()._get_cached_value(option,
path=subpath,
validate=False,
trusted_cached_properties=False,
validate_properties=True)
if option.impl_is_master_slaves('slave'):
# problem with index
raise ConfigError(_('a slave ({0}) cannot have '
'force_store_value property').format(subpath))
if option._is_subdyn():
raise ConfigError(_('a dynoption ({0}) cannot have '
'force_store_value property').format(subpath))
config._impl_values._p_.setvalue(subpath, value,
owners.forced, None)
# ____________________________________________________________
def impl_set_group_type(self, group_type):