better support for setowner

This commit is contained in:
Emmanuel Garette 2016-03-09 15:48:14 +01:00
parent 32592b9289
commit 3b872cb8c9
3 changed files with 58 additions and 61 deletions

View File

@ -540,13 +540,3 @@ class StorageOptionDescription(StorageBase):
raise AttributeError(_('unknown Option {0} '
'in OptionDescription {1}'
'').format(name, self.impl_getname()))
def _get_force_store_value(self):
#FIXME faire des tests (notamment pas ajouter à un config)
#FIXME devrait faire un cache !
opts, paths = self._cache_paths
for index in range(0, len(paths)):
opt = opts[index]
path = paths[index]
if 'force_store_value' in opt._properties:
yield (opt, path)

View File

@ -31,15 +31,7 @@ class Values(Cache):
# should init cache too
super(Values, self).__init__(storage)
# value
def setvalue(self, path, value, owner, index):
"""set value for a path
a specified value must be associated to an owner
"""
values = []
vidx = None
def _setvalue_info(nb, idx, value, vidx):
def _setvalue_info(self, nb, idx, value, values, index, vidx):
lst = list(self._values[nb])
if idx is None:
if index is None or nb == 0:
@ -64,18 +56,31 @@ class Values(Cache):
tval[vidx] = value
lst[idx] = tuple(tval)
lst[idx] = tuple(lst[idx])
for ls in lst:
if isinstance(ls, list):
raise Exception('pouet')
values.append(tuple(lst))
return vidx
# value
def setvalue(self, path, value, owner, index):
"""set value for a path
a specified value must be associated to an owner
"""
values = []
vidx = None
if path in self._values[0]:
idx = self._values[0].index(path)
else:
idx = None
vidx = _setvalue_info(0, idx, path, vidx)
vidx = _setvalue_info(1, idx, index, vidx)
vidx = self._setvalue_info(0, idx, path, values, index, vidx)
vidx = self._setvalue_info(1, idx, index, values, index, vidx)
if isinstance(value, list):
value = tuple(value)
vidx = _setvalue_info(2, idx, value, vidx)
_setvalue_info(3, idx, owner, vidx)
vidx = self._setvalue_info(2, idx, value, values, index, vidx)
if isinstance(value, list):
value = tuple(value)
self._setvalue_info(3, idx, owner, values, index, vidx)
self._values = tuple(values)
def getvalue(self, path, index=None):
@ -112,7 +117,18 @@ class Values(Cache):
"""
values = {}
for idx, path in enumerate(self._values[0]):
values[path] = (self._values[3][idx], self._values[2][idx])
indexes = self._values[1][idx]
value = self._values[2][idx]
owner = self._values[3][idx]
if indexes is not None:
val = {}
own = {}
for cpt, index in enumerate(indexes):
val[str(index)] = value[cpt]
own[str(index)] = owner[cpt]
value = val
owner = own
values[path] = (owner, value)
return values
# owner
@ -120,19 +136,15 @@ class Values(Cache):
"""change owner for a path
"""
idx = self._values[0].index(path)
if isinstance(self._values[3][idx], tuple):
if index is None:
raise ValueError('Slave need index to set owner')
towner = list(self._values[3][idx])
towner[index] = owner
owner = towner
elif index is not None:
raise ValueError('Only slave option needs index to set owner')
lst = list(self._values[3])
lst[idx] = owner
values = list(self._values)
values[3] = tuple(lst)
self._values = tuple(values)
vidx = None
else:
vidx = self._values[1][idx].index(index)
values = []
self._setvalue_info(3, idx, owner, values, index, vidx)
lst = list(self._values)
lst[3] = tuple(values[0])
self._values = tuple(lst)
def get_max_length(self, path):
if path in self._values[0]:
@ -164,7 +176,7 @@ class Values(Cache):
def _getvalue(self, path, nb, index):
"""
_values == ((path1, path2), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2), ((idx1_1, idx1_2), None))
_values == ((path1, path2), ((idx1_1, idx1_2), None), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
"""
if path in self._values[0]:
idx = self._values[0].index(path)

View File

@ -134,11 +134,6 @@ class Values(object):
submulti_index, True)
def get_modified_values(self):
context = self._getcontext()
if context._impl_descr is not None:
for opt, path in context.cfgimpl_get_description(
)._get_force_store_value():
self._getowner(opt, path, force_permissive=True)
return self._p_.get_modified_values()
def __contains__(self, opt):