Merge branch 'master' of ssh://git.labs.libre-entreprise.org/gitroot/tiramisu

This commit is contained in:
gwen 2013-09-04 09:05:25 +02:00
commit 02873f2836
2 changed files with 46 additions and 14 deletions

View File

@ -4,7 +4,7 @@ from py.test import raises
from tiramisu.setting import owners, groups from tiramisu.setting import owners, groups
from tiramisu.config import Config from tiramisu.config import Config
from tiramisu.option import IPOption, NetworkOption, NetmaskOption, IntOption,\ from tiramisu.option import IPOption, NetworkOption, NetmaskOption, IntOption,\
OptionDescription SymLinkOption, OptionDescription
def test_consistency_not_equal(): def test_consistency_not_equal():
@ -22,6 +22,16 @@ def test_consistency_not_equal():
c.b = 2 c.b = 2
def test_consistency_not_equal_symlink():
a = IntOption('a', '')
b = IntOption('b', '')
c = SymLinkOption('c', a)
od = OptionDescription('od', '', [a, b, c])
a.impl_add_consistency('not_equal', b)
c = Config(od)
assert set(od._consistencies.keys()) == set([a, b])
def test_consistency_not_equal_multi(): def test_consistency_not_equal_multi():
a = IntOption('a', '', multi=True) a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True) b = IntOption('b', '', multi=True)

View File

@ -168,6 +168,7 @@ class BaseOption(object):
consistencies = self._state_consistencies consistencies = self._state_consistencies
else: else:
consistencies = self._consistencies consistencies = self._consistencies
if isinstance(consistencies, list):
new_value = [] new_value = []
for consistency in consistencies: for consistency in consistencies:
if load: if load:
@ -178,11 +179,24 @@ class BaseOption(object):
new_value.append((consistency[0], new_value.append((consistency[0],
descr.impl_get_path_by_opt( descr.impl_get_path_by_opt(
consistency[1]))) consistency[1])))
else:
new_value = {}
for key, _consistencies in consistencies.items():
new_value[key] = []
for key_cons, _cons in _consistencies:
_list_cons = []
for _con in _cons:
if load:
_list_cons.append(descr.impl_get_opt_by_path(_con))
else:
_list_cons.append(descr.impl_get_path_by_opt(_con))
new_value[key].append((key_cons, tuple(_list_cons)))
if load: if load:
del(self._state_consistencies) del(self._state_consistencies)
self._consistencies = tuple(new_value) self._consistencies = new_value
else: else:
self._state_consistencies = tuple(new_value) self._state_consistencies = new_value
def _impl_convert_requires(self, descr, load=False): def _impl_convert_requires(self, descr, load=False):
"""export of the requires during the serialization process """export of the requires during the serialization process
@ -644,8 +658,10 @@ else:
class SymLinkOption(BaseOption): class SymLinkOption(BaseOption):
__slots__ = ('_name', '_opt', '_state_opt') __slots__ = ('_name', '_opt', '_state_opt', '_consistencies')
_opt_type = 'symlink' _opt_type = 'symlink'
#not return _opt consistencies
_consistencies = {}
def __init__(self, name, opt): def __init__(self, name, opt):
self._name = name self._name = name
@ -671,6 +687,12 @@ class SymLinkOption(BaseOption):
del(self._state_opt) del(self._state_opt)
super(SymLinkOption, self)._impl_setstate(descr) super(SymLinkOption, self)._impl_setstate(descr)
def _impl_convert_consistencies(self, descr, load=False):
if load:
del(self._state_consistencies)
else:
self._state_consistencies = None
class IPOption(Option): class IPOption(Option):
"represents the choice of an ip" "represents the choice of an ip"