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,6 +31,36 @@ class Values(Cache):
|
||||||
# should init cache too
|
# should init cache too
|
||||||
super(Values, self).__init__(storage)
|
super(Values, self).__init__(storage)
|
||||||
|
|
||||||
|
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:
|
||||||
|
lst.append(value)
|
||||||
|
else:
|
||||||
|
lst.append((value,))
|
||||||
|
else:
|
||||||
|
if index is None or nb == 0:
|
||||||
|
lst[idx] = value
|
||||||
|
else:
|
||||||
|
if nb == 1:
|
||||||
|
if index in lst[idx]:
|
||||||
|
vidx = lst[idx].index(index)
|
||||||
|
else:
|
||||||
|
vidx = None
|
||||||
|
if vidx is None:
|
||||||
|
tval = list(lst[idx])
|
||||||
|
tval.append(value)
|
||||||
|
lst[idx] = tuple(tval)
|
||||||
|
elif nb != 1:
|
||||||
|
tval = list(lst[idx])
|
||||||
|
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
|
# value
|
||||||
def setvalue(self, path, value, owner, index):
|
def setvalue(self, path, value, owner, index):
|
||||||
"""set value for a path
|
"""set value for a path
|
||||||
|
@ -39,43 +69,18 @@ class Values(Cache):
|
||||||
values = []
|
values = []
|
||||||
vidx = None
|
vidx = None
|
||||||
|
|
||||||
def _setvalue_info(nb, idx, value, vidx):
|
|
||||||
lst = list(self._values[nb])
|
|
||||||
if idx is None:
|
|
||||||
if index is None or nb == 0:
|
|
||||||
lst.append(value)
|
|
||||||
else:
|
|
||||||
lst.append((value,))
|
|
||||||
else:
|
|
||||||
if index is None or nb == 0:
|
|
||||||
lst[idx] = value
|
|
||||||
else:
|
|
||||||
if nb == 1:
|
|
||||||
if index in lst[idx]:
|
|
||||||
vidx = lst[idx].index(index)
|
|
||||||
else:
|
|
||||||
vidx = None
|
|
||||||
if vidx is None:
|
|
||||||
tval = list(lst[idx])
|
|
||||||
tval.append(value)
|
|
||||||
lst[idx] = tuple(tval)
|
|
||||||
elif nb != 1:
|
|
||||||
tval = list(lst[idx])
|
|
||||||
tval[vidx] = value
|
|
||||||
lst[idx] = tuple(tval)
|
|
||||||
lst[idx] = tuple(lst[idx])
|
|
||||||
values.append(tuple(lst))
|
|
||||||
return vidx
|
|
||||||
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:
|
vidx = None
|
||||||
raise ValueError('Slave need index to set owner')
|
else:
|
||||||
towner = list(self._values[3][idx])
|
vidx = self._values[1][idx].index(index)
|
||||||
towner[index] = owner
|
values = []
|
||||||
owner = towner
|
self._setvalue_info(3, idx, owner, values, index, vidx)
|
||||||
elif index is not None:
|
lst = list(self._values)
|
||||||
raise ValueError('Only slave option needs index to set owner')
|
lst[3] = tuple(values[0])
|
||||||
lst = list(self._values[3])
|
self._values = tuple(lst)
|
||||||
lst[idx] = owner
|
|
||||||
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