Some optimisations

This commit is contained in:
2015-05-03 09:56:03 +02:00
parent 487b99b32c
commit 6cc74506fb
7 changed files with 156 additions and 128 deletions

View File

@ -357,37 +357,36 @@ class Settings(object):
self._p_.delproperties(_path)
self._getcontext().cfgimpl_reset_cache()
def _getproperties(self, opt=None, path=None, _is_apply_req=True,
self_properties=undefined):
def _getproperties(self, opt=None, path=None,
self_properties=undefined, read_write=True):
"""
be careful, _is_apply_req doesn't copy properties
"""
if opt is None:
props = copy(self._p_.getproperties(path, default_properties))
props = self._p_.getproperties(path, default_properties)
else:
if self_properties is undefined:
self_properties = self._getproperties()
if path is None: # pragma: optional cover
raise ValueError(_('if opt is not None, path should not be'
' None in _getproperties'))
ntime = None
is_cached = False
if 'cache' in self_properties and 'expire' in self_properties:
ntime = int(time())
else:
ntime = None
if 'cache' in self_properties and self._p_.hascache(path):
if 'expire' in self_properties:
ntime = int(time())
is_cached, props = self._p_.getcache(path, ntime)
if is_cached:
return copy(props)
props = self._p_.getproperties(path, opt.impl_getproperties())
if _is_apply_req:
props = copy(props)
if not is_cached:
props = copy(self._p_.getproperties(path, opt.impl_getproperties()))
props |= self.apply_requires(opt, path)
if 'cache' in self_properties:
if 'expire' in self_properties:
if ntime is None:
ntime = int(time())
ntime = ntime + expires_time
self._p_.setcache(path, copy(props), ntime)
return props
self._p_.setcache(path, props, ntime)
if read_write:
return copy(props)
else:
return props
def append(self, propname):
"puts property propname in the Config's properties attribute"
@ -442,7 +441,7 @@ class Settings(object):
"""
# opt properties
if self_properties is undefined:
self_properties = self._getproperties()
self_properties = self._getproperties(read_write=False)
properties = self._getproperties(opt_or_descr, path,
self_properties=self_properties)
# remove opt permissive
@ -455,12 +454,14 @@ class Settings(object):
if force_permissives is not None:
properties -= force_permissives
# global properties
if force_properties is not None:
self_properties.update(force_properties)
forced_properties = copy(self_properties)
forced_properties.update(force_properties)
else:
forced_properties = self_properties
# calc properties
properties &= self_properties
properties &= forced_properties
# mandatory and frozen are special properties
if is_descr:
properties -= frozenset(('mandatory', 'frozen'))
@ -469,7 +470,7 @@ class Settings(object):
not self._getcontext().cfgimpl_get_values()._isempty(
opt_or_descr, value, opt_or_descr.impl_allow_empty_list()):
properties.remove('mandatory')
if is_write and 'everything_frozen' in self_properties:
if is_write and 'everything_frozen' in forced_properties:
properties.add('frozen')
elif 'frozen' in properties and not is_write:
properties.remove('frozen')