better support for setowner
This commit is contained in:
parent
32592b9289
commit
3b872cb8c9
|
@ -540,13 +540,3 @@ class StorageOptionDescription(StorageBase):
|
||||||
raise AttributeError(_('unknown Option {0} '
|
raise AttributeError(_('unknown Option {0} '
|
||||||
'in OptionDescription {1}'
|
'in OptionDescription {1}'
|
||||||
'').format(name, self.impl_getname()))
|
'').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)
|
|
||||||
|
|
|
@ -31,15 +31,7 @@ class Values(Cache):
|
||||||
# should init cache too
|
# should init cache too
|
||||||
super(Values, self).__init__(storage)
|
super(Values, self).__init__(storage)
|
||||||
|
|
||||||
# value
|
def _setvalue_info(self, nb, idx, value, values, index, vidx):
|
||||||
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):
|
|
||||||
lst = list(self._values[nb])
|
lst = list(self._values[nb])
|
||||||
if idx is None:
|
if idx is None:
|
||||||
if index is None or nb == 0:
|
if index is None or nb == 0:
|
||||||
|
@ -64,18 +56,31 @@ class Values(Cache):
|
||||||
tval[vidx] = value
|
tval[vidx] = value
|
||||||
lst[idx] = tuple(tval)
|
lst[idx] = tuple(tval)
|
||||||
lst[idx] = tuple(lst[idx])
|
lst[idx] = tuple(lst[idx])
|
||||||
|
for ls in lst:
|
||||||
|
if isinstance(ls, list):
|
||||||
|
raise Exception('pouet')
|
||||||
values.append(tuple(lst))
|
values.append(tuple(lst))
|
||||||
return vidx
|
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]:
|
if path in self._values[0]:
|
||||||
idx = self._values[0].index(path)
|
idx = self._values[0].index(path)
|
||||||
else:
|
else:
|
||||||
idx = None
|
idx = None
|
||||||
vidx = _setvalue_info(0, idx, path, vidx)
|
vidx = self._setvalue_info(0, idx, path, values, index, vidx)
|
||||||
vidx = _setvalue_info(1, idx, index, vidx)
|
vidx = self._setvalue_info(1, idx, index, values, index, vidx)
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
value = tuple(value)
|
value = tuple(value)
|
||||||
vidx = _setvalue_info(2, idx, value, vidx)
|
vidx = self._setvalue_info(2, idx, value, values, index, vidx)
|
||||||
_setvalue_info(3, idx, owner, vidx)
|
if isinstance(value, list):
|
||||||
|
value = tuple(value)
|
||||||
|
self._setvalue_info(3, idx, owner, values, index, vidx)
|
||||||
self._values = tuple(values)
|
self._values = tuple(values)
|
||||||
|
|
||||||
def getvalue(self, path, index=None):
|
def getvalue(self, path, index=None):
|
||||||
|
@ -112,7 +117,18 @@ class Values(Cache):
|
||||||
"""
|
"""
|
||||||
values = {}
|
values = {}
|
||||||
for idx, path in enumerate(self._values[0]):
|
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
|
return values
|
||||||
|
|
||||||
# owner
|
# owner
|
||||||
|
@ -120,19 +136,15 @@ class Values(Cache):
|
||||||
"""change owner for a path
|
"""change owner for a path
|
||||||
"""
|
"""
|
||||||
idx = self._values[0].index(path)
|
idx = self._values[0].index(path)
|
||||||
if isinstance(self._values[3][idx], tuple):
|
|
||||||
if index is None:
|
if index is None:
|
||||||
raise ValueError('Slave need index to set owner')
|
vidx = None
|
||||||
towner = list(self._values[3][idx])
|
else:
|
||||||
towner[index] = owner
|
vidx = self._values[1][idx].index(index)
|
||||||
owner = towner
|
values = []
|
||||||
elif index is not None:
|
self._setvalue_info(3, idx, owner, values, index, vidx)
|
||||||
raise ValueError('Only slave option needs index to set owner')
|
lst = list(self._values)
|
||||||
lst = list(self._values[3])
|
lst[3] = tuple(values[0])
|
||||||
lst[idx] = owner
|
self._values = tuple(lst)
|
||||||
values = list(self._values)
|
|
||||||
values[3] = tuple(lst)
|
|
||||||
self._values = tuple(values)
|
|
||||||
|
|
||||||
def get_max_length(self, path):
|
def get_max_length(self, path):
|
||||||
if path in self._values[0]:
|
if path in self._values[0]:
|
||||||
|
@ -164,7 +176,7 @@ class Values(Cache):
|
||||||
|
|
||||||
def _getvalue(self, path, nb, index):
|
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]:
|
if path in self._values[0]:
|
||||||
idx = self._values[0].index(path)
|
idx = self._values[0].index(path)
|
||||||
|
|
|
@ -134,11 +134,6 @@ class Values(object):
|
||||||
submulti_index, True)
|
submulti_index, True)
|
||||||
|
|
||||||
def get_modified_values(self):
|
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()
|
return self._p_.get_modified_values()
|
||||||
|
|
||||||
def __contains__(self, opt):
|
def __contains__(self, opt):
|
||||||
|
|
Loading…
Reference in New Issue