can set owner for a slave

This commit is contained in:
Emmanuel Garette 2016-01-25 16:22:28 +01:00
parent 8a21d49948
commit 51d14f30a4
3 changed files with 30 additions and 9 deletions

View File

@ -3,7 +3,7 @@ do_autopath()
from py.test import raises from py.test import raises
from tiramisu.setting import owners from tiramisu.setting import owners, groups
from tiramisu.config import Config from tiramisu.config import Config
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \ from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption StrOption, OptionDescription, SymLinkOption
@ -131,6 +131,7 @@ def test_setowner_optiondescription():
descr1 = OptionDescription('tiramisu', '', [gcdummy]) descr1 = OptionDescription('tiramisu', '', [gcdummy])
descr = OptionDescription('tiramisu', '', [descr1]) descr = OptionDescription('tiramisu', '', [descr1])
cfg = Config(descr) cfg = Config(descr)
cfg
raises(ConfigError, 'cfg.cfgimpl_get_values().getowner(descr1)') raises(ConfigError, 'cfg.cfgimpl_get_values().getowner(descr1)')
raises(ConfigError, 'cfg.cfgimpl_get_values().setowner(descr1, owners.user)') raises(ConfigError, 'cfg.cfgimpl_get_values().setowner(descr1, owners.user)')
@ -145,3 +146,18 @@ def test_setowner_symlinkoption():
cfg.tiramisu.dummy = True cfg.tiramisu.dummy = True
assert cfg.cfgimpl_get_values().getowner(s) == owners.user assert cfg.cfgimpl_get_values().getowner(s) == owners.user
raises(ConfigError, 'cfg.cfgimpl_get_values().setowner(s, owners.user)') raises(ConfigError, 'cfg.cfgimpl_get_values().setowner(s, owners.user)')
def test_owner_masterslaves():
b = IntOption('int', 'Test int option', default=[0], multi=True)
c = StrOption('str', 'Test string option', multi=True)
descr = OptionDescription("int", "", [b, c])
descr.impl_set_group_type(groups.master)
cfg = Config(descr)
raises(ConfigError, 'cfg.cfgimpl_get_values().setowner(c, owners.user)')
cfg.int.append(1)
cfg.str[0] = 'yes'
assert cfg.cfgimpl_get_values().getowner(c, 0) == owners.user
cfg.cfgimpl_get_values().setowner(c, owners.user, 0)
assert cfg.cfgimpl_get_values().getowner(c, 0) == owners.user

View File

@ -115,10 +115,12 @@ class Values(Cache):
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], list):
if index is None: if index is None:
raise ValueError('list but no index') raise ValueError('Slave need index to set owner')
owner = list(self._values[3][idx])[index] = owner towner = list(self._values[3][idx])
towner[index] = owner
owner = towner
elif index is not None: elif index is not None:
raise ValueError('index set but not a list') raise ValueError('Only slave option needs index to set owner')
lst = list(self._values[3]) lst = list(self._values[3])
lst[idx] = owner lst[idx] = owner
values = list(self._values) values = list(self._values)

View File

@ -506,7 +506,7 @@ class Values(object):
only_default=only_default, index=index) only_default=only_default, index=index)
return owner return owner
def setowner(self, opt, owner): def setowner(self, opt, owner, index=None):
""" """
sets a owner to an option sets a owner to an option
@ -523,10 +523,11 @@ class Values(object):
props = self._getcontext().cfgimpl_get_settings().validate_properties(opt, props = self._getcontext().cfgimpl_get_settings().validate_properties(opt,
False, False,
True, True,
path) path,
index=index)
if props: if props:
raise props raise props
self._p_.setowner(path, owner) self._p_.setowner(path, owner, index=index)
def is_default_owner(self, opt, validate_properties=True, def is_default_owner(self, opt, validate_properties=True,
validate_meta=True, index=None): validate_meta=True, index=None):
@ -752,7 +753,8 @@ class Multi(list):
True, False, True, True, False, True,
index=index) index=index)
def append(self, value=undefined, force=False, setitem=True, validate=True): def append(self, value=undefined, force=False, setitem=True, validate=True,
force_permissive=False):
"""the list value can be updated (appened) """the list value can be updated (appened)
only if the option is a master only if the option is a master
""" """
@ -769,7 +771,8 @@ class Multi(list):
if 'validator' in setting_properties: if 'validator' in setting_properties:
fake_context = context._gen_fake_values() fake_context = context._gen_fake_values()
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)
fake_multi.append(value, validate=False, force=True) fake_multi.append(value, validate=False, force=True)
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():