setitem for a slave only modify current value
This commit is contained in:
parent
35ffde841b
commit
32592b9289
4 changed files with 33 additions and 21 deletions
|
@ -171,15 +171,15 @@ def test_force_store_value():
|
||||||
conf = Config(descr)
|
conf = Config(descr)
|
||||||
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('forced', False),
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('forced', False),
|
||||||
'wantref2': ('forced', False),
|
'wantref2': ('forced', False),
|
||||||
'wantref3': ('forced', [False])}
|
'wantref3': ('forced', (False,))}
|
||||||
conf.wantref = True
|
conf.wantref = True
|
||||||
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('user', True),
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('user', True),
|
||||||
'wantref2': ('forced', False),
|
'wantref2': ('forced', False),
|
||||||
'wantref3': ('forced', [False])}
|
'wantref3': ('forced', (False,))}
|
||||||
del(conf.wantref)
|
del(conf.wantref)
|
||||||
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('forced', False),
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('forced', False),
|
||||||
'wantref2': ('forced', False),
|
'wantref2': ('forced', False),
|
||||||
'wantref3': ('forced', [False])}
|
'wantref3': ('forced', (False,))}
|
||||||
|
|
||||||
|
|
||||||
def test_force_store_value_no_requirement():
|
def test_force_store_value_no_requirement():
|
||||||
|
@ -205,7 +205,7 @@ def test_force_store_value_masterslaves():
|
||||||
descr = OptionDescription("int", "", [b, c])
|
descr = OptionDescription("int", "", [b, c])
|
||||||
descr.impl_set_group_type(groups.master)
|
descr.impl_set_group_type(groups.master)
|
||||||
conf = Config(descr)
|
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():
|
def test_force_store_value_callback():
|
||||||
|
|
|
@ -167,5 +167,7 @@ def test_owner_masterslaves():
|
||||||
cfg.int.append(1)
|
cfg.int.append(1)
|
||||||
cfg.str[0] = 'yes'
|
cfg.str[0] = 'yes'
|
||||||
assert cfg.cfgimpl_get_values().getowner(c, 0) == owners.user
|
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)
|
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, 0) == owners.user
|
||||||
|
assert cfg.cfgimpl_get_values().getowner(c, 1) == owners.default
|
||||||
|
|
|
@ -38,9 +38,6 @@ class Values(Cache):
|
||||||
"""
|
"""
|
||||||
values = []
|
values = []
|
||||||
vidx = None
|
vidx = None
|
||||||
if index is None:
|
|
||||||
# raise Exception('arf')
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _setvalue_info(nb, idx, value, vidx):
|
def _setvalue_info(nb, idx, value, vidx):
|
||||||
lst = list(self._values[nb])
|
lst = list(self._values[nb])
|
||||||
|
@ -48,7 +45,7 @@ class Values(Cache):
|
||||||
if index is None or nb == 0:
|
if index is None or nb == 0:
|
||||||
lst.append(value)
|
lst.append(value)
|
||||||
else:
|
else:
|
||||||
lst.append([value])
|
lst.append((value,))
|
||||||
else:
|
else:
|
||||||
if index is None or nb == 0:
|
if index is None or nb == 0:
|
||||||
lst[idx] = value
|
lst[idx] = value
|
||||||
|
@ -59,9 +56,14 @@ class Values(Cache):
|
||||||
else:
|
else:
|
||||||
vidx = None
|
vidx = None
|
||||||
if vidx is None:
|
if vidx is None:
|
||||||
lst[idx].append(value)
|
tval = list(lst[idx])
|
||||||
|
tval.append(value)
|
||||||
|
lst[idx] = tuple(tval)
|
||||||
elif nb != 1:
|
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))
|
values.append(tuple(lst))
|
||||||
return vidx
|
return vidx
|
||||||
if path in self._values[0]:
|
if path in self._values[0]:
|
||||||
|
@ -70,6 +72,8 @@ class Values(Cache):
|
||||||
idx = None
|
idx = None
|
||||||
vidx = _setvalue_info(0, idx, path, vidx)
|
vidx = _setvalue_info(0, idx, path, vidx)
|
||||||
vidx = _setvalue_info(1, idx, index, vidx)
|
vidx = _setvalue_info(1, idx, index, vidx)
|
||||||
|
if isinstance(value, list):
|
||||||
|
value = tuple(value)
|
||||||
vidx = _setvalue_info(2, idx, value, vidx)
|
vidx = _setvalue_info(2, idx, value, vidx)
|
||||||
_setvalue_info(3, idx, owner, vidx)
|
_setvalue_info(3, idx, owner, vidx)
|
||||||
self._values = tuple(values)
|
self._values = tuple(values)
|
||||||
|
@ -116,7 +120,7 @@ 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], list):
|
if isinstance(self._values[3][idx], tuple):
|
||||||
if index is None:
|
if index is None:
|
||||||
raise ValueError('Slave need index to set owner')
|
raise ValueError('Slave need index to set owner')
|
||||||
towner = list(self._values[3][idx])
|
towner = list(self._values[3][idx])
|
||||||
|
@ -164,7 +168,7 @@ class Values(Cache):
|
||||||
"""
|
"""
|
||||||
if path in self._values[0]:
|
if path in self._values[0]:
|
||||||
idx = self._values[0].index(path)
|
idx = self._values[0].index(path)
|
||||||
if isinstance(self._values[1][idx], list):
|
if isinstance(self._values[1][idx], tuple):
|
||||||
if index is None:
|
if index is None:
|
||||||
raise ValueError('index is mandatory')
|
raise ValueError('index is mandatory')
|
||||||
elif index is not None:
|
elif index is not None:
|
||||||
|
@ -191,6 +195,8 @@ class Values(Cache):
|
||||||
value.append(undefined)
|
value.append(undefined)
|
||||||
else:
|
else:
|
||||||
value = None
|
value = None
|
||||||
|
if isinstance(value, tuple):
|
||||||
|
value = list(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def set_information(self, key, value):
|
def set_information(self, key, value):
|
||||||
|
|
|
@ -405,7 +405,7 @@ class Values(object):
|
||||||
raise err
|
raise err
|
||||||
self._setvalue(opt, path, value)
|
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 = self._getcontext()
|
||||||
context.cfgimpl_reset_cache()
|
context.cfgimpl_reset_cache()
|
||||||
if force_owner is undefined:
|
if force_owner is undefined:
|
||||||
|
@ -421,6 +421,9 @@ class Values(object):
|
||||||
value[idx] = list(val)
|
value[idx] = list(val)
|
||||||
#FIXME pourquoi là et pas dans masterslaves ??
|
#FIXME pourquoi là et pas dans masterslaves ??
|
||||||
if opt.impl_is_master_slaves('slave'):
|
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)
|
self._p_.resetvalue(path)
|
||||||
for idx, val in enumerate(value):
|
for idx, val in enumerate(value):
|
||||||
self._p_.setvalue(path, val, owner, idx)
|
self._p_.setvalue(path, val, owner, idx)
|
||||||
|
@ -739,7 +742,7 @@ class Multi(list):
|
||||||
self._validate(value, fake_context, index, True)
|
self._validate(value, fake_context, index, True)
|
||||||
#assume not checking mandatory property
|
#assume not checking mandatory property
|
||||||
super(Multi, self).__setitem__(index, value)
|
super(Multi, self).__setitem__(index, value)
|
||||||
self._store()
|
self._store(index=index)
|
||||||
|
|
||||||
#def __repr__(self, *args, **kwargs):
|
#def __repr__(self, *args, **kwargs):
|
||||||
# return super(Multi, self).__repr__(*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(
|
fake_multi = fake_context.cfgimpl_get_values()._get_cached_value(
|
||||||
self.opt, path=self.path, validate=False,
|
self.opt, path=self.path, validate=False,
|
||||||
force_permissive=force_permissive)
|
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)
|
self._validate(value, fake_context, index, True)
|
||||||
if not '_index' in self.__slots__ and self.opt.impl_is_submulti():
|
if not '_index' in self.__slots__ and self.opt.impl_is_submulti():
|
||||||
if not isinstance(value, SubMulti):
|
if not isinstance(value, SubMulti):
|
||||||
|
@ -871,13 +875,13 @@ class Multi(list):
|
||||||
self._store(force=force)
|
self._store(force=force)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _store(self, force=False):
|
def _store(self, force=False, index=None):
|
||||||
values = self._getcontext().cfgimpl_get_values()
|
values = self._getcontext().cfgimpl_get_values()
|
||||||
if not force:
|
if not force:
|
||||||
#FIXME could get properties an pass it
|
#FIXME could get properties an pass it
|
||||||
values.validate(self.opt, self, self.path,
|
values.validate(self.opt, self, self.path,
|
||||||
valid_masterslave=False)
|
valid_masterslave=False)
|
||||||
values._setvalue(self.opt, self.path, self)
|
values._setvalue(self.opt, self.path, self, index=index)
|
||||||
|
|
||||||
|
|
||||||
class SubMulti(Multi):
|
class SubMulti(Multi):
|
||||||
|
@ -900,7 +904,7 @@ class SubMulti(Multi):
|
||||||
def __setitem__(self, index, value):
|
def __setitem__(self, index, value):
|
||||||
self._setitem(index, value)
|
self._setitem(index, value)
|
||||||
|
|
||||||
def _store(self, force=False):
|
def _store(self, force=False, index=None):
|
||||||
#force is unused here
|
#force is unused here
|
||||||
values = self._getcontext().cfgimpl_get_values()
|
values = self._getcontext().cfgimpl_get_values()
|
||||||
values.validate(self.opt, self, self.path, valid_masterslave=False)
|
values.validate(self.opt, self, self.path, valid_masterslave=False)
|
||||||
|
|
Loading…
Reference in a new issue