first version with sqlalchemy option's storage
This commit is contained in:
@ -254,11 +254,11 @@ class Property(object):
|
||||
self._properties = prop
|
||||
|
||||
def append(self, propname):
|
||||
if self._opt is not None and self._opt._calc_properties is not None \
|
||||
and propname in self._opt._calc_properties:
|
||||
if self._opt is not None and self._opt.impl_getrequires() is not None \
|
||||
and propname in self._opt.impl_getrequires():
|
||||
raise ValueError(_('cannot append {0} property for option {1}: '
|
||||
'this property is calculated').format(
|
||||
propname, self._opt._name))
|
||||
propname, self._opt.impl_getname()))
|
||||
self._properties.add(propname)
|
||||
self._setting._setproperties(self._properties, self._opt, self._path)
|
||||
|
||||
@ -343,7 +343,8 @@ class Settings(object):
|
||||
is_cached, props = self._p_.getcache(path, ntime)
|
||||
if is_cached:
|
||||
return props
|
||||
props = self._p_.getproperties(path, opt._properties)
|
||||
#FIXME
|
||||
props = self._p_.getproperties(path, opt.impl_getproperties())
|
||||
if is_apply_req:
|
||||
props |= self.apply_requires(opt, path)
|
||||
if 'cache' in self:
|
||||
@ -374,12 +375,15 @@ class Settings(object):
|
||||
if opt is None:
|
||||
self._p_.setproperties(None, properties)
|
||||
else:
|
||||
if opt._calc_properties is not None:
|
||||
properties -= opt._calc_properties
|
||||
if set(opt._properties) == properties:
|
||||
self._p_.reset_properties(path)
|
||||
else:
|
||||
self._p_.setproperties(path, properties)
|
||||
#if opt._calc_properties is not None:
|
||||
# properties -= opt._calc_properties
|
||||
#FIXME a revoir ---------
|
||||
#if set(opt._properties) == properties:
|
||||
# self._p_.reset_properties(path)
|
||||
#else:
|
||||
# self._p_.setproperties(path, properties)
|
||||
self._p_.setproperties(path, properties)
|
||||
#FIXME fin revoir -----
|
||||
self.context().cfgimpl_reset_cache()
|
||||
|
||||
#____________________________________________________________
|
||||
@ -440,12 +444,12 @@ class Settings(object):
|
||||
raise PropertiesOptionError(_('cannot change the value for '
|
||||
'option {0} this option is'
|
||||
' frozen').format(
|
||||
opt_or_descr._name),
|
||||
opt_or_descr.impl_getname()),
|
||||
props)
|
||||
else:
|
||||
raise PropertiesOptionError(_("trying to access to an option "
|
||||
"named: {0} with properties {1}"
|
||||
"").format(opt_or_descr._name,
|
||||
"").format(opt_or_descr.impl_getname(),
|
||||
str(props)), props)
|
||||
|
||||
def setpermissive(self, permissive, opt=None, path=None):
|
||||
@ -544,44 +548,43 @@ class Settings(object):
|
||||
:param path: the option's path in the config
|
||||
:type path: str
|
||||
"""
|
||||
if opt._requires is None:
|
||||
if opt.impl_getrequires() is None:
|
||||
return frozenset()
|
||||
|
||||
# filters the callbacks
|
||||
calc_properties = set()
|
||||
for requires in opt._requires:
|
||||
for require in requires:
|
||||
option, expected, action, inverse, \
|
||||
transitive, same_action = require
|
||||
reqpath = self._get_path_by_opt(option)
|
||||
if reqpath == path or reqpath.startswith(path + '.'):
|
||||
raise RequirementError(_("malformed requirements "
|
||||
"imbrication detected for option:"
|
||||
" '{0}' with requirement on: "
|
||||
"'{1}'").format(path, reqpath))
|
||||
try:
|
||||
value = self.context()._getattr(reqpath,
|
||||
force_permissive=True)
|
||||
except PropertiesOptionError as err:
|
||||
if not transitive:
|
||||
continue
|
||||
properties = err.proptype
|
||||
if same_action and action not in properties:
|
||||
raise RequirementError(_("option '{0}' has "
|
||||
"requirement's property "
|
||||
"error: "
|
||||
"{1} {2}").format(opt._name,
|
||||
reqpath,
|
||||
properties))
|
||||
# transitive action, force expected
|
||||
value = expected[0]
|
||||
inverse = False
|
||||
if (not inverse and
|
||||
value in expected or
|
||||
inverse and value not in expected):
|
||||
calc_properties.add(action)
|
||||
# the calculation cannot be carried out
|
||||
break
|
||||
for require in opt.impl_getrequires():
|
||||
expected = tuple(require.get_expected())
|
||||
inverse = require.inverse
|
||||
option = require.get_option(self.context())
|
||||
reqpath = self._get_path_by_opt(option)
|
||||
if reqpath == path or reqpath.startswith(path + '.'):
|
||||
raise RequirementError(_("malformed requirements "
|
||||
"imbrication detected for option:"
|
||||
" '{0}' with requirement on: "
|
||||
"'{1}'").format(path, reqpath))
|
||||
try:
|
||||
value = self.context()._getattr(reqpath,
|
||||
force_permissive=True)
|
||||
except PropertiesOptionError as err:
|
||||
if not require.transitive:
|
||||
continue
|
||||
properties = err.proptype
|
||||
if require.same_action and require.action not in properties:
|
||||
raise RequirementError(_("option '{0}' has "
|
||||
"requirement's property "
|
||||
"error: "
|
||||
"{1} {2}").format(opt.impl_getname(),
|
||||
reqpath,
|
||||
properties))
|
||||
# transitive action, force expected
|
||||
value = expected[0]
|
||||
inverse = False
|
||||
if not inverse and value in expected or \
|
||||
inverse and value not in expected:
|
||||
calc_properties.add(require.action)
|
||||
# the calculation cannot be carried out
|
||||
#break
|
||||
return calc_properties
|
||||
|
||||
def _get_path_by_opt(self, opt):
|
||||
|
Reference in New Issue
Block a user