setitem for a slave only modify current value

This commit is contained in:
Emmanuel Garette 2016-03-08 23:18:42 +01:00
parent 35ffde841b
commit 32592b9289
4 changed files with 33 additions and 21 deletions

View File

@ -171,15 +171,15 @@ def test_force_store_value():
conf = Config(descr)
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('forced', False),
'wantref2': ('forced', False),
'wantref3': ('forced', [False])}
'wantref3': ('forced', (False,))}
conf.wantref = True
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('user', True),
'wantref2': ('forced', False),
'wantref3': ('forced', [False])}
'wantref3': ('forced', (False,))}
del(conf.wantref)
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('forced', False),
'wantref2': ('forced', False),
'wantref3': ('forced', [False])}
'wantref3': ('forced', (False,))}
def test_force_store_value_no_requirement():
@ -205,7 +205,7 @@ def test_force_store_value_masterslaves():
descr = OptionDescription("int", "", [b, c])
descr.impl_set_group_type(groups.master)
conf = Config(descr)
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'int': ('forced', [])}
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'int': ('forced', ())}
def test_force_store_value_callback():

View File

@ -167,5 +167,7 @@ def test_owner_masterslaves():
cfg.int.append(1)
cfg.str[0] = 'yes'
assert cfg.cfgimpl_get_values().getowner(c, 0) == owners.user
assert cfg.cfgimpl_get_values().getowner(c, 1) == owners.default
cfg.cfgimpl_get_values().setowner(c, owners.user, 0)
assert cfg.cfgimpl_get_values().getowner(c, 0) == owners.user
assert cfg.cfgimpl_get_values().getowner(c, 1) == owners.default

View File

@ -38,9 +38,6 @@ class Values(Cache):
"""
values = []
vidx = None
if index is None:
# raise Exception('arf')
pass
def _setvalue_info(nb, idx, value, vidx):
lst = list(self._values[nb])
@ -48,7 +45,7 @@ class Values(Cache):
if index is None or nb == 0:
lst.append(value)
else:
lst.append([value])
lst.append((value,))
else:
if index is None or nb == 0:
lst[idx] = value
@ -59,9 +56,14 @@ class Values(Cache):
else:
vidx = None
if vidx is None:
lst[idx].append(value)
tval = list(lst[idx])
tval.append(value)
lst[idx] = tuple(tval)
elif nb != 1:
lst[idx][vidx] = value
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]:
@ -70,6 +72,8 @@ class Values(Cache):
idx = None
vidx = _setvalue_info(0, idx, path, vidx)
vidx = _setvalue_info(1, idx, index, vidx)
if isinstance(value, list):
value = tuple(value)
vidx = _setvalue_info(2, idx, value, vidx)
_setvalue_info(3, idx, owner, vidx)
self._values = tuple(values)
@ -116,7 +120,7 @@ class Values(Cache):
"""change owner for a path
"""
idx = self._values[0].index(path)
if isinstance(self._values[3][idx], list):
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])
@ -164,7 +168,7 @@ class Values(Cache):
"""
if path in self._values[0]:
idx = self._values[0].index(path)
if isinstance(self._values[1][idx], list):
if isinstance(self._values[1][idx], tuple):
if index is None:
raise ValueError('index is mandatory')
elif index is not None:
@ -191,6 +195,8 @@ class Values(Cache):
value.append(undefined)
else:
value = None
if isinstance(value, tuple):
value = list(value)
return value
def set_information(self, key, value):

View File

@ -405,7 +405,7 @@ class Values(object):
raise err
self._setvalue(opt, path, value)
def _setvalue(self, opt, path, value, force_owner=undefined):
def _setvalue(self, opt, path, value, force_owner=undefined, index=None):
context = self._getcontext()
context.cfgimpl_reset_cache()
if force_owner is undefined:
@ -421,6 +421,9 @@ class Values(object):
value[idx] = list(val)
#FIXME pourquoi là et pas dans masterslaves ??
if opt.impl_is_master_slaves('slave'):
if index is not None:
self._p_.setvalue(path, value[index], owner, index)
else:
self._p_.resetvalue(path)
for idx, val in enumerate(value):
self._p_.setvalue(path, val, owner, idx)
@ -739,7 +742,7 @@ class Multi(list):
self._validate(value, fake_context, index, True)
#assume not checking mandatory property
super(Multi, self).__setitem__(index, value)
self._store()
self._store(index=index)
#def __repr__(self, *args, **kwargs):
# return super(Multi, self).__repr__(*args, **kwargs)
@ -776,7 +779,8 @@ class Multi(list):
fake_multi = fake_context.cfgimpl_get_values()._get_cached_value(
self.opt, path=self.path, validate=False,
force_permissive=force_permissive)
fake_multi.append(value, validate=False, force=True)
fake_multi.append(value, validate=False, force=True,
setitem=setitem)
self._validate(value, fake_context, index, True)
if not '_index' in self.__slots__ and self.opt.impl_is_submulti():
if not isinstance(value, SubMulti):
@ -871,13 +875,13 @@ class Multi(list):
self._store(force=force)
return ret
def _store(self, force=False):
def _store(self, force=False, index=None):
values = self._getcontext().cfgimpl_get_values()
if not force:
#FIXME could get properties an pass it
values.validate(self.opt, self, self.path,
valid_masterslave=False)
values._setvalue(self.opt, self.path, self)
values._setvalue(self.opt, self.path, self, index=index)
class SubMulti(Multi):
@ -900,7 +904,7 @@ class SubMulti(Multi):
def __setitem__(self, index, value):
self._setitem(index, value)
def _store(self, force=False):
def _store(self, force=False, index=None):
#force is unused here
values = self._getcontext().cfgimpl_get_values()
values.validate(self.opt, self, self.path, valid_masterslave=False)