Arity change, remove force_properties:

* tiramisu/config.py (in cfgimpl_get_home_by_path and getattr)
 * tiramisu/value.py (in getitem):
This commit is contained in:
Emmanuel Garette 2014-04-12 21:37:20 +02:00
parent cd4d3527c7
commit 3ab0688c46
4 changed files with 48 additions and 47 deletions

View file

@ -1,10 +1,12 @@
Sat Apr 12 11:37:27 CEST 2014 Emmanuel Garette <egarette@cadoles.com> Sat Apr 12 11:37:27 CEST 2014 Emmanuel Garette <egarette@cadoles.com>
* behavior change in master/slave part of code: * behavior change in master/slave part of code:
if slave has a default value greater than master's one, it's raise if slave has a default value greater than master's one, it's raise
SlaveError, didn't try to reduce the slave's length SlaveError, didn't try to reduce the slave's length
* tiramisu/config.py (in cfgimpl_get_home_by_path and getattr) and
tiramisu/value.py (in getitem): arity change, remove force_properties
* tiramisu/option.py: split into tiramisu/option directory * tiramisu/option.py: split into tiramisu/option directory
* tiramisu/option/masterslave.py: master/slaves have no a special * tiramisu/option/masterslave.py: master/slaves have no a special
object MasterSlaves for all code related to master/slaves options object MasterSlaves for all code related to master/slaves options
* tiramisu/option/masterslave.py: master and slaves values (length, * tiramisu/option/masterslave.py: master and slaves values (length,
consistency, ...) are now check every time consistency, ...) are now check every time

View file

@ -1,4 +1,5 @@
import autopath import autopath
from time import sleep
#from py.test import raises #from py.test import raises
from tiramisu.config import Config from tiramisu.config import Config
@ -205,11 +206,12 @@ def test_mandatory_warnings_ro():
except PropertiesOptionError as err: except PropertiesOptionError as err:
proc = err.proptype proc = err.proptype
assert proc == ['mandatory'] assert proc == ['mandatory']
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3'] assert config.cfgimpl_get_values().mandatory_warnings() == ['str', 'str1', 'unicode2', 'str3']
config.read_write() config.read_write()
config.str = 'a' config.str = 'a'
config.read_only() config.read_only()
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3'] assert config.cfgimpl_get_values().mandatory_warnings() == ['str1', 'unicode2', 'str3']
sleep(.1)
def test_mandatory_warnings_rw(): def test_mandatory_warnings_rw():
@ -218,9 +220,10 @@ def test_mandatory_warnings_rw():
config.str = '' config.str = ''
config.read_write() config.read_write()
config.str config.str
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3'] assert config.cfgimpl_get_values().mandatory_warnings() == ['str', 'str1', 'unicode2', 'str3']
config.str = 'a' config.str = 'a'
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3'] assert config.cfgimpl_get_values().mandatory_warnings() == ['str1', 'unicode2', 'str3']
sleep(.1)
def test_mandatory_warnings_disabled(): def test_mandatory_warnings_disabled():
@ -230,9 +233,10 @@ def test_mandatory_warnings_disabled():
setting = config.cfgimpl_get_settings() setting = config.cfgimpl_get_settings()
config.read_write() config.read_write()
config.str config.str
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3'] assert config.cfgimpl_get_values().mandatory_warnings() == ['str', 'str1', 'unicode2', 'str3']
setting[descr.str].append('disabled') setting[descr.str].append('disabled')
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3'] assert config.cfgimpl_get_values().mandatory_warnings() == ['str1', 'unicode2', 'str3']
sleep(.1)
def test_mandatory_warnings_frozen(): def test_mandatory_warnings_frozen():
@ -242,7 +246,8 @@ def test_mandatory_warnings_frozen():
setting = config.cfgimpl_get_settings() setting = config.cfgimpl_get_settings()
config.read_write() config.read_write()
config.str config.str
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3'] assert config.cfgimpl_get_values().mandatory_warnings() == ['str', 'str1', 'unicode2', 'str3']
setting[descr.str].append('frozen') setting[descr.str].append('frozen')
config.read_only() config.read_only()
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3'] assert config.cfgimpl_get_values().mandatory_warnings() == ['str', 'str1', 'unicode2', 'str3']
sleep(.1)

View file

@ -62,14 +62,12 @@ class SubConfig(object):
"remove cache (in context)" "remove cache (in context)"
self._cfgimpl_get_context().cfgimpl_reset_cache(only_expired, only) self._cfgimpl_get_context().cfgimpl_reset_cache(only_expired, only)
def cfgimpl_get_home_by_path(self, path, force_permissive=False, def cfgimpl_get_home_by_path(self, path, force_permissive=False):
force_properties=None):
""":returns: tuple (config, name)""" """:returns: tuple (config, name)"""
path = path.split('.') path = path.split('.')
for step in path[:-1]: for step in path[:-1]:
self = self.getattr(step, self = self.getattr(step,
force_permissive=force_permissive, force_permissive=force_permissive)
force_properties=force_properties)
return self, path[-1] return self, path[-1]
def __hash__(self): def __hash__(self):
@ -214,29 +212,24 @@ class SubConfig(object):
def __getattr__(self, name): def __getattr__(self, name):
return self.getattr(name) return self.getattr(name)
def _getattr(self, name, force_permissive=False, force_properties=None, def _getattr(self, name, force_permissive=False, validate=True):
validate=True):
"""use getattr instead of _getattr """use getattr instead of _getattr
""" """
return self.getattr(name, force_permissive, force_properties, validate) return self.getattr(name, force_permissive, validate)
def getattr(self, name, force_permissive=False, force_properties=None, def getattr(self, name, force_permissive=False, validate=True):
validate=True):
""" """
attribute notation mechanism for accessing the value of an option attribute notation mechanism for accessing the value of an option
:param name: attribute name :param name: attribute name
:return: option's value if name is an option name, OptionDescription :return: option's value if name is an option name, OptionDescription
otherwise otherwise
""" """
#FIXME force_properties vraiment utile maintenant ?
# attribute access by passing a path, # attribute access by passing a path,
# for instance getattr(self, "creole.general.family.adresse_ip_eth0") # for instance getattr(self, "creole.general.family.adresse_ip_eth0")
if '.' in name: if '.' in name:
homeconfig, name = self.cfgimpl_get_home_by_path( homeconfig, name = self.cfgimpl_get_home_by_path(
name, force_permissive=force_permissive, name, force_permissive=force_permissive)
force_properties=force_properties)
return homeconfig.getattr(name, force_permissive=force_permissive, return homeconfig.getattr(name, force_permissive=force_permissive,
force_properties=force_properties,
validate=validate) validate=validate)
opt_or_descr = getattr(self.cfgimpl_get_description(), name) opt_or_descr = getattr(self.cfgimpl_get_description(), name)
if self._impl_path is None: if self._impl_path is None:
@ -251,19 +244,16 @@ class SubConfig(object):
path = context.cfgimpl_get_description().impl_get_path_by_opt( path = context.cfgimpl_get_description().impl_get_path_by_opt(
opt_or_descr._opt) opt_or_descr._opt)
return context.getattr(path, validate=validate, return context.getattr(path, validate=validate,
force_properties=force_properties,
force_permissive=force_permissive) force_permissive=force_permissive)
elif isinstance(opt_or_descr, OptionDescription): elif isinstance(opt_or_descr, OptionDescription):
self.cfgimpl_get_settings().validate_properties( self.cfgimpl_get_settings().validate_properties(
opt_or_descr, True, False, path=subpath, opt_or_descr, True, False, path=subpath,
force_permissive=force_permissive, force_permissive=force_permissive)
force_properties=force_properties)
return SubConfig(opt_or_descr, self._impl_context, subpath) return SubConfig(opt_or_descr, self._impl_context, subpath)
else: else:
return self.cfgimpl_get_values()._get_cached_item( return self.cfgimpl_get_values()._get_cached_item(
opt_or_descr, path=subpath, opt_or_descr, path=subpath,
validate=validate, validate=validate,
force_properties=force_properties,
force_permissive=force_permissive) force_permissive=force_permissive)
def find(self, bytype=None, byname=None, byvalue=None, type_='option', def find(self, bytype=None, byname=None, byvalue=None, type_='option',

View file

@ -22,7 +22,7 @@ from tiramisu.error import ConfigError, SlaveError, PropertiesOptionError
from tiramisu.setting import owners, expires_time, undefined from tiramisu.setting import owners, expires_time, undefined
from tiramisu.autolib import carry_out_calculation from tiramisu.autolib import carry_out_calculation
from tiramisu.i18n import _ from tiramisu.i18n import _
from tiramisu.option import SymLinkOption from tiramisu.option import SymLinkOption, OptionDescription
class Values(object): class Values(object):
@ -170,13 +170,11 @@ class Values(object):
"enables us to use the pythonic dictionary-like access to values" "enables us to use the pythonic dictionary-like access to values"
return self.getitem(opt) return self.getitem(opt)
def getitem(self, opt, validate=True, force_permissive=False, def getitem(self, opt, validate=True, force_permissive=False):
force_properties=None):
""" """
""" """
return self._get_cached_item(opt, validate=validate, return self._get_cached_item(opt, validate=validate,
force_permissive=force_permissive, force_permissive=force_permissive)
force_properties=force_properties)
def _get_cached_item(self, opt, path=None, validate=True, def _get_cached_item(self, opt, path=None, validate=True,
force_permissive=False, force_properties=None, force_permissive=False, force_properties=None,
@ -296,7 +294,6 @@ class Values(object):
is_write=is_write) is_write=is_write)
def _setvalue(self, opt, path, value, force_permissive=False, def _setvalue(self, opt, path, value, force_permissive=False,
force_properties=None,
is_write=True, validate_properties=True): is_write=True, validate_properties=True):
context = self._getcontext() context = self._getcontext()
context.cfgimpl_reset_cache() context.cfgimpl_reset_cache()
@ -304,8 +301,7 @@ class Values(object):
setting = context.cfgimpl_get_settings() setting = context.cfgimpl_get_settings()
setting.validate_properties(opt, False, is_write, setting.validate_properties(opt, False, is_write,
value=value, path=path, value=value, path=path,
force_permissive=force_permissive, force_permissive=force_permissive)
force_properties=force_properties)
owner = context.cfgimpl_get_settings().getowner() owner = context.cfgimpl_get_settings().getowner()
if isinstance(value, Multi): if isinstance(value, Multi):
value = list(value) value = list(value)
@ -421,18 +417,26 @@ class Values(object):
:returns: generator of mandatory Option's path :returns: generator of mandatory Option's path
""" """
#if value in cache, properties are not calculated def _mandatory_warnings(description):
#if value in cache, properties are not calculated
for opt in description.impl_getchildren():
if isinstance(opt, OptionDescription):
_mandatory_warnings(opt)
elif isinstance(opt, SymLinkOption):
pass
else:
path = self._get_opt_path(opt)
try:
self._get_cached_item(opt, path=path,
force_properties=frozenset(('mandatory',)))
except PropertiesOptionError as err:
if err.proptype == ['mandatory']:
yield path
self.reset_cache(False) self.reset_cache(False)
context = self.context() descr = self._getcontext().cfgimpl_get_description()
for path in context.cfgimpl_get_description().impl_getpaths( ret = list(_mandatory_warnings(descr))
include_groups=True):
try:
context.getattr(path,
force_properties=frozenset(('mandatory',)))
except PropertiesOptionError as err:
if err.proptype == ['mandatory']:
yield path
self.reset_cache(False) self.reset_cache(False)
return ret
def force_cache(self): def force_cache(self):
"""parse all option to force data in cache """parse all option to force data in cache