refactor masterslaves

This commit is contained in:
Emmanuel Garette 2017-12-02 22:53:57 +01:00
parent 3820f9fe4b
commit e40a1e78a2
11 changed files with 296 additions and 457 deletions

View File

@ -405,8 +405,13 @@ def _autocheck_get_value(api, path, conf, **kwargs):
def autocheck_get_value(api, path, confread, confwrite, **kwargs): def autocheck_get_value(api, path, confread, confwrite, **kwargs):
_set_value(api, path, confwrite, set_permissive=False, **kwargs) _set_value(api, path, confwrite, set_permissive=False, **kwargs)
_autocheck_get_value(api, path, confread, set_permissive=False, **kwargs) _autocheck_get_value(api, path, confread, set_permissive=False, **kwargs)
if path.endswith('val1'):
val2_path = path.replace('val1', 'val2')
_autocheck_default_value(api, val2_path, confread, **kwargs)
if confread != confwrite: if confread != confwrite:
_autocheck_get_value(api, path, confwrite, set_permissive=False, **kwargs) _autocheck_get_value(api, path, confwrite, set_permissive=False, **kwargs)
if path.endswith('val1'):
_autocheck_default_value(api, val2_path, confwrite, **kwargs)
@autocheck @autocheck
@ -528,7 +533,11 @@ def autocheck_append_value(api, path, confread, confwrite, **kwargs):
len_new = len(new_master_value) len_new = len(new_master_value)
assert len_value + 1 == len_new assert len_value + 1 == len_new
assert new_master_value[-1] == kwargs['default_multi'] assert new_master_value[-1] == kwargs['default_multi']
slave_path = path.rsplit('.', 1)[0] + '.third' slave_path = path.rsplit('.', 1)[0]
if slave_path.endswith('val1') or slave_path.endswith('val2'):
slave_path += '.third' + slave_path[-4:]
else:
slave_path += '.third'
for idx in range(len_new): for idx in range(len_new):
assert api.forcepermissive.config(confread).option(slave_path, idx).value.get() == kwargs['default_multi'] assert api.forcepermissive.config(confread).option(slave_path, idx).value.get() == kwargs['default_multi']
# #
@ -552,17 +561,21 @@ def autocheck_pop_value(api, path, confread, confwrite, **kwargs):
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
if not submulti_: if not submulti_:
values = ['value1', 'value2', 'value3', 'value4'] values = ['value1', 'value2', 'value3', 'value4']
slave = 'slave' slave_value = 'slave'
else: else:
values = [['value1'], ['value2'], ['value3'], ['value4']] values = [['value1'], ['value2'], ['value3'], ['value4']]
slave = ['slave'] slave_value = ['slave']
slaves = [kwargs['default_multi'], slave, kwargs['default_multi'], kwargs['default_multi']] slaves = [kwargs['default_multi'], slave_value, kwargs['default_multi'], kwargs['default_multi']]
a_slave = path.rsplit('.', 1)[0] + '.third' a_slave = path.rsplit('.', 1)[0]
if a_slave.endswith('val1') or a_slave.endswith('val2'):
a_slave += '.third' + a_slave[-4:]
else:
a_slave += '.third'
api.forcepermissive.config(confwrite).option(path).value.set(values) api.forcepermissive.config(confwrite).option(path).value.set(values)
api.forcepermissive.config(confwrite).option(a_slave, 1).value.set(slave) api.forcepermissive.config(confwrite).option(a_slave, 1).value.set(slave_value)
api.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] api.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi']
assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True
api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value
assert api.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False assert api.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False
api.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi'] api.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi']
assert api.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True assert api.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True
@ -572,13 +585,13 @@ def autocheck_pop_value(api, path, confread, confwrite, **kwargs):
api.forcepermissive.config(confwrite).option(path).value.pop(3) api.forcepermissive.config(confwrite).option(path).value.pop(3)
api.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] api.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi']
assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True
api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value
assert api.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False assert api.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False
api.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi'] api.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi']
assert api.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True assert api.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True
# #
api.forcepermissive.config(confwrite).option(path).value.pop(0) api.forcepermissive.config(confwrite).option(path).value.pop(0)
api.forcepermissive.config(confread).option(a_slave, 0).value.get() == slave api.forcepermissive.config(confread).option(a_slave, 0).value.get() == slave_value
assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is False assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is False
api.forcepermissive.config(confread).option(a_slave, 1).value.get() == kwargs['default_multi'] api.forcepermissive.config(confread).option(a_slave, 1).value.get() == kwargs['default_multi']
assert api.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is True assert api.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is True
@ -623,13 +636,15 @@ def autocheck_display(api, path, confread, confwrite, **kwargs):
return return
make_dict = kwargs['make_dict'] make_dict = kwargs['make_dict']
make_dict_value = kwargs['make_dict_value'] make_dict_value = kwargs['make_dict_value']
#print('--------')
#print(make_dict) #print(make_dict)
#print(make_dict_value)
#print(api.config(confread).config.make_dict()) #print(api.config(confread).config.make_dict())
assert api.config(confread).config.make_dict() == make_dict assert api.config(confread).config.make_dict() == make_dict
if confread != confwrite: if confread != confwrite:
assert(api.config(confwrite).config.make_dict()) == make_dict assert(api.config(confwrite).config.make_dict()) == make_dict
_set_value(api, path, confwrite, **kwargs) _set_value(api, path, confwrite, **kwargs)
#print('--')
#print(make_dict_value)
#print(api.config(confread).config.make_dict()) #print(api.config(confread).config.make_dict())
assert api.config(confread).config.make_dict() == make_dict_value assert api.config(confread).config.make_dict() == make_dict_value
if confread != confwrite: if confread != confwrite:
@ -1129,13 +1144,6 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
else: else:
default_value = value default_value = value
kwargs['default'] = default_value kwargs['default'] = default_value
if '.' in path:
if paths.get(path, {}) is None:
isslave = False
else:
isslave = paths.get(path, {}).get(path.rsplit('.', 1)[0], {}).get('master') is True and not path.endswith('.first')
if isslave and not multi is submulti:
kwargs['default'] = None
is_dyn = False is_dyn = False
is_master = False is_master = False
@ -1146,20 +1154,21 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
break break
if '.' in cpath: if '.' in cpath:
dirname, name = cpath.split('.')[-2:] dirname, name = cpath.split('.')[-2:]
for dname in cpath.split('.')[:-1]:
if options.get(dname, {}).get('dyn'):
is_dyn = True
if options.get(dname, {}).get('master'):
is_master = True
else: else:
dirname = '' dirname = ''
name = cpath name = cpath
if options.get(dirname, {}).get('hidden'): if options.get(dirname, {}).get('hidden'):
continue continue
if options.get(dirname, {}).get('dyn'):
is_dyn = True
if options.get(dirname, {}).get('master'):
is_master = True
no_propertieserror = not options.get(name, {}).get('disabled') and not options.get(name, {}).get('hidden')
allow_req = require and req allow_req = require and req
no_propertieserror = not options.get(name, {}).get('disabled') and not options.get(name, {}).get('hidden')
if is_dyn: if is_dyn:
dyns.append(no_propertieserror or allow_req) dyns.append(no_propertieserror or allow_req)
elif no_propertieserror or allow_req: if not is_dyn and (no_propertieserror or allow_req):
dico[cpath] = default_value dico[cpath] = default_value
if path == cpath: if path == cpath:
dico_value[cpath] = value dico_value[cpath] = value
@ -1167,7 +1176,12 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
dico_value[cpath] = default_value dico_value[cpath] = default_value
has_value = True has_value = True
if is_dyn: isslave = False
if '.' in path and is_master and not path.rsplit('.', 1)[1].startswith('first'):
isslave = True
if not multi is submulti:
kwargs['default'] = None
if is_dyn and dyns:
idx = 0 idx = 0
for cpath in list(paths.keys())[len(dyns):]: for cpath in list(paths.keys())[len(dyns):]:
if dyns[idx]: if dyns[idx]:
@ -1198,18 +1212,30 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
value = None value = None
if is_dyn: if is_dyn:
dico[cpath + 'extraoptconsistencyval1'] = value dico[cpath + 'extraoptconsistencyval1'] = value
dico[cpath[:-2] + '2.' + 'extraoptconsistencyval2'] = value
dico_value[cpath + 'extraoptconsistencyval1'] = value dico_value[cpath + 'extraoptconsistencyval1'] = value
dico_value[cpath[:-2] + '2.' + 'extraoptconsistencyval2'] = value if is_master:
spath = cpath.split('.')
spath[-2] = spath[-2][:-1] + '2'
spath[-3] = spath[-3][:-1] + '2'
npath = '.'.join(spath) + 'extraoptconsistencyval2'
else:
npath = cpath[:-2] + '2.' + 'extraoptconsistencyval2'
dico[npath] = value
dico_value[npath] = value
else: else:
dico[cpath + 'extraoptconsistency'] = value dico[cpath + 'extraoptconsistency'] = value
dico_value[cpath + 'extraoptconsistency'] = value dico_value[cpath + 'extraoptconsistency'] = value
if is_master: if is_master:
for cpath in list(paths.keys())[len(dyns):]: for cpath in list(paths.keys())[len(dyns):]:
if cpath.endswith('.first'): if cpath.endswith('.first') or cpath.endswith('.firstval1') or cpath.endswith('.firstval2'):
second_path = cpath.rsplit('.', 1)[0] + '.second' second_path = cpath.rsplit('.', 1)[0] + '.second'
third_path = cpath.rsplit('.', 1)[0] + '.third' third_path = cpath.rsplit('.', 1)[0] + '.third'
cons_path = cpath.rsplit('.', 1)[0] + '.extraoptconsistency' cons_path = cpath.rsplit('.', 1)[0] + '.extraoptconsistency'
if is_dyn:
suffix = cpath[-4:]
second_path += suffix
third_path += suffix
cons_path += suffix
# #
if default_multi: if default_multi:
if multi is not submulti: if multi is not submulti:
@ -1237,11 +1263,9 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
dico_value[second_path] = [dvalue] * len_master dico_value[second_path] = [dvalue] * len_master
if third_path in dico_value: if third_path in dico_value:
dico_value[third_path] = [dvalue] * len_master dico_value[third_path] = [dvalue] * len_master
cons_path = cpath.rsplit('.', 1)[0] + '.extraoptconsistency'
if cons_path in dico_value: if cons_path in dico_value:
dico_value[cons_path] = [dvalue] * len_master dico_value[cons_path] = [dvalue] * len_master
break return is_dyn, dico, dico_value
return dico, dico_value
if DISPLAY: if DISPLAY:
text = u' {} launch tests for {}'.format(ICON, path) text = u' {} launch tests for {}'.format(ICON, path)
if multi is True: if multi is True:
@ -1267,7 +1291,7 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
confwrite = confread = None confwrite = confread = None
idx = 0 idx = 0
for req in requires: for req in requires:
kwargs['make_dict'], kwargs['make_dict_value'] = _build_make_dict() is_dyn, kwargs['make_dict'], kwargs['make_dict_value'] = _build_make_dict()
kwargs['callback'] = callback kwargs['callback'] = callback
for func in autocheck_registers: for func in autocheck_registers:
cfg_name = 'conftest' + str(idx) cfg_name = 'conftest' + str(idx)
@ -1283,6 +1307,11 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
if api.unrestraint.option(path).option.isslave(): if api.unrestraint.option(path).option.isslave():
dirname = path.rsplit('.', 1)[0] dirname = path.rsplit('.', 1)[0]
master_path = dirname + '.first' master_path = dirname + '.first'
master_path_2 = None
if dirname.endswith('val1') or dirname.endswith('val2'):
master_path += 'val1'
master_path = master_path.replace('val2', 'val1')
master_path_2 = master_path.replace('val1', 'val2')
if multi is submulti: if multi is submulti:
value = SUBLIST_SECOND_VALUE value = SUBLIST_SECOND_VALUE
else: else:
@ -1290,6 +1319,10 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
api.option(master_path).value.set(value) api.option(master_path).value.set(value)
ckwargs['make_dict'][master_path] = value ckwargs['make_dict'][master_path] = value
ckwargs['make_dict_value'][master_path] = value ckwargs['make_dict_value'][master_path] = value
if master_path_2:
api.option(master_path_2).value.set(value)
ckwargs['make_dict'][master_path_2] = value
ckwargs['make_dict_value'][master_path_2] = value
if default_multi: if default_multi:
if multi is not submulti: if multi is not submulti:
dvalue = SECOND_VALUE dvalue = SECOND_VALUE
@ -1299,19 +1332,33 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
dvalue = [] dvalue = []
else: else:
dvalue = None dvalue = None
if dirname + '.second' in ckwargs['make_dict']: def do(suffix, oldsuffix=None):
ckwargs['make_dict'][dirname + '.second'] = [dvalue] * len(value) if suffix:
ckwargs['make_dict_value'][dirname + '.second'] = [dvalue] * len(value) ldirname = dirname.replace(oldsuffix, suffix)
if path == dirname + '.second': else:
ckwargs['make_dict_value'][dirname + '.second'][-1] = ckwargs['make_dict_value'][master_path][-1] ldirname = dirname
if dirname + '.third' in ckwargs['make_dict']: npath = ldirname + '.second' + suffix
ckwargs['make_dict'][dirname + '.third'] = [dvalue] * len(value) if npath in ckwargs['make_dict']:
ckwargs['make_dict_value'][dirname + '.third'] = [dvalue] * len(value) ckwargs['make_dict'][npath] = [dvalue] * len(value)
if path == dirname + '.third': ckwargs['make_dict_value'][npath] = [dvalue] * len(value)
ckwargs['make_dict_value'][dirname + '.third'][-1] = ckwargs['make_dict_value'][master_path][-1] if path == npath:
if dirname + '.extraoptconsistency' in ckwargs['make_dict']: ckwargs['make_dict_value'][npath][-1] = ckwargs['make_dict_value'][master_path][-1]
ckwargs['make_dict'][dirname + '.extraoptconsistency'] = [dvalue] * len(value) npath = ldirname + '.third' + suffix
ckwargs['make_dict_value'][dirname + '.extraoptconsistency'] = [dvalue] * len(value) if npath in ckwargs['make_dict']:
ckwargs['make_dict'][npath] = [dvalue] * len(value)
ckwargs['make_dict_value'][npath] = [dvalue] * len(value)
if path == npath:
ckwargs['make_dict_value'][npath][-1] = ckwargs['make_dict_value'][master_path][-1]
npath = ldirname + '.extraoptconsistency' + suffix
if npath in ckwargs['make_dict']:
ckwargs['make_dict'][npath] = [dvalue] * len(value)
ckwargs['make_dict_value'][npath] = [dvalue] * len(value)
if not is_dyn:
do('')
else:
#do(dirname[-4:])
do('val1', 'val2')
do('val2', 'val1')
#FIXME devrait etre dans la config ca ... #FIXME devrait etre dans la config ca ...
api.read_write() api.read_write()
@ -1478,11 +1525,15 @@ def make_conf(options, meta, multi, default, default_multi, require, consistency
local_collect_options = local_collect_options[optiondescription] local_collect_options = local_collect_options[optiondescription]
local_collect_options['properties'].update(option.get(optiondescription, {})) local_collect_options['properties'].update(option.get(optiondescription, {}))
option_name = path.split('.')[-1] option_name = path.split('.')[-1]
in_master = False
if '.' in path: if '.' in path:
name_od = path.rsplit('.', 1)[0] name_od = path.rsplit('.', 1)[0]
if '.' in name_od:
subod, name_od = name_od.split('.')
oddescr = collect_options.get(subod, {})
else: else:
name_od = '' oddescr = collect_options
in_master = collect_options.get(name_od, {}).get('properties', {}).get('master') in_master = oddescr.get(name_od, {}).get('properties', {}).get('master')
master = in_master and path.endswith('first') master = in_master and path.endswith('first')
obj, objcall = make_option(option_name, option.get(option_name), in_master, master) obj, objcall = make_option(option_name, option.get(option_name), in_master, master)
if obj is None: if obj is None:
@ -1517,18 +1568,10 @@ DICT_PATHS = [
('second', {'second': {'disabled': True}}), ('second', {'second': {'disabled': True}}),
('third', {'third': {'hidden': True}}) ('third', {'third': {'hidden': True}})
]), ]),
#test a config with an optiondescription
OrderedDict([('subod.first', {}),
('subod.second', {'second': {'disabled': True}}),
('subod.third', {'third': {'hidden': True}})]),
#test a config with two optiondescription #test a config with two optiondescription
OrderedDict([('subod.subsubod.first', {}), OrderedDict([('subod.subsubod.first', {}),
('subod.subsubod.second', {'second': {'disabled': True}}), ('subod.subsubod.second', {'second': {'disabled': True}}),
('subod.subsubod.third', {'third': {'hidden': True}})]), ('subod.subsubod.third', {'third': {'hidden': True}})]),
#test a config with mix of different optiondescription
OrderedDict([('first', {}),
('subod.second', {'second': {'disabled': True}}),
('subod.subsubod.third', {'third': {'hidden': True}})]),
#test a config with masterslaves #test a config with masterslaves
OrderedDict([('odmaster.first', {'odmaster': {'master': True}}), OrderedDict([('odmaster.first', {'odmaster': {'master': True}}),
('odmaster.second', {'odmaster': {'master': True}, 'second': {'disabled': True, 'slave': True}}), ('odmaster.second', {'odmaster': {'master': True}, 'second': {'disabled': True, 'slave': True}}),
@ -1566,7 +1609,17 @@ DICT_PATHS = [
('subod.subsubodval1.thirdval1', None), ('subod.subsubodval1.thirdval1', None),
('subod.subsubodval2.firstval2', None), ('subod.subsubodval2.firstval2', None),
('subod.subsubodval2.secondval2', None), ('subod.subsubodval2.secondval2', None),
('subod.subsubodval2.thirdval2', None)]) ('subod.subsubodval2.thirdval2', None)]),
#test a config with dyn subsubod with masterslave
OrderedDict([('subod.subsubod.first', {'subod': {'dyn': True}, 'subsubod': {'master': True}}),
('subod.subsubod.second', {'subod': {'dyn': True}, 'subsubod' : {'master': True}, 'second': {'disabled': True, 'slave': True}}),
('subod.subsubod.third', {'subod': {'dyn': True}, 'subsubod': {'master': True}, 'third': {'hidden': True, 'slave': True}}),
('subodval1.subsubodval1.firstval1', None),
('subodval1.subsubodval1.secondval1', None),
('subodval1.subsubodval1.thirdval1', None),
('subodval2.subsubodval2.firstval2', None),
('subodval2.subsubodval2.secondval2', None),
('subodval2.subsubodval2.thirdval2', None)]),
] ]

View File

@ -21,6 +21,7 @@
from .error import PropertiesOptionError, ConfigError, SlaveError, display_list from .error import PropertiesOptionError, ConfigError, SlaveError, display_list
from .i18n import _ from .i18n import _
from .setting import undefined from .setting import undefined
from .option.baseoption import DynSymLinkOption
from .storage import get_default_values_storages, get_default_settings_storages from .storage import get_default_values_storages, get_default_settings_storages
# ____________________________________________________________ # ____________________________________________________________
@ -166,10 +167,10 @@ def carry_out_calculation(option,
# callbk is something link (opt, True|False) # callbk is something link (opt, True|False)
opt, force_permissive = callbk opt, force_permissive = callbk
if opt._is_subdyn(): if opt._is_subdyn():
root = '.'.join(option.impl_getpath(context).split('.')[:-1]) opt = DynSymLinkOption(opt,
name = opt.impl_getname() + option.impl_getsuffix() option._rootpath,
path = root + '.' + name option.impl_getsuffix())
opt = opt._impl_to_dyn(name, path) path = opt.impl_getpath(context)
else: else:
path = context.cfgimpl_get_description( path = context.cfgimpl_get_description(
).impl_get_path_by_opt(opt) ).impl_get_path_by_opt(opt)

View File

@ -83,10 +83,17 @@ class SubConfig(object):
if setting_properties is not undefined: if setting_properties is not undefined:
self._impl_setting_properties = setting_properties self._impl_setting_properties = setting_properties
if setting_properties is not None and descr.impl_get_group_type() == groups.master: if setting_properties is not None and descr.impl_get_group_type() == groups.master:
self._impl_length = descr.get_length(context().cfgimpl_get_values(), master = descr.getmaster()
setting_properties=setting_properties, context_ = context()
masterp = master.impl_getpath(context_)
value = context_.cfgimpl_get_values().get_cached_value(master,
path=masterp,
validate=validate, validate=validate,
force_permissive=force_permissive) force_permissive=force_permissive,
self_properties=undefined,
index=None,
setting_properties=setting_properties)
self._impl_length = len(value)
def cfgimpl_get_length(self): def cfgimpl_get_length(self):
return getattr(self, '_impl_length') return getattr(self, '_impl_length')
@ -317,7 +324,7 @@ class SubConfig(object):
setting_properties=setting_properties) setting_properties=setting_properties)
child = self.cfgimpl_get_description().impl_getchild(name, child = self.cfgimpl_get_description().impl_getchild(name,
setting_properties, setting_properties,
context) self)
if isinstance(child, (OptionDescription, SynDynOptionDescription)): if isinstance(child, (OptionDescription, SynDynOptionDescription)):
raise TypeError(_("can't assign to an OptionDescription")) # pragma: optional cover raise TypeError(_("can't assign to an OptionDescription")) # pragma: optional cover
elif child.impl_is_symlinkoption() and \ elif child.impl_is_symlinkoption() and \
@ -350,7 +357,7 @@ class SubConfig(object):
setting_properties=setting_properties) setting_properties=setting_properties)
child = self.cfgimpl_get_description().impl_getchild(name, child = self.cfgimpl_get_description().impl_getchild(name,
setting_properties, setting_properties,
context) self)
if isinstance(child, (OptionDescription, SynDynOptionDescription)): if isinstance(child, (OptionDescription, SynDynOptionDescription)):
raise TypeError(_("can't delete an OptionDescription")) # pragma: optional cover raise TypeError(_("can't delete an OptionDescription")) # pragma: optional cover
elif child.impl_is_symlinkoption() and \ elif child.impl_is_symlinkoption() and \
@ -411,8 +418,8 @@ class SubConfig(object):
context = self._cfgimpl_get_context() context = self._cfgimpl_get_context()
option = self.cfgimpl_get_description().impl_getchild(name, option = self.cfgimpl_get_description().impl_getchild(name,
context, setting_properties,
setting_properties) self)
if option.impl_is_symlinkoption() and isinstance(option, DynSymLinkOption): if option.impl_is_symlinkoption() and isinstance(option, DynSymLinkOption):
# FIXME peuvent-il vraiment etre le 2 ? # FIXME peuvent-il vraiment etre le 2 ?
# si non supprimer tout ces tests inutiles # si non supprimer tout ces tests inutiles
@ -832,7 +839,7 @@ class _CommonConfig(SubConfig):
setting_properties=setting_properties) setting_properties=setting_properties)
option = self.cfgimpl_get_description().impl_getchild(path, option = self.cfgimpl_get_description().impl_getchild(path,
setting_properties, setting_properties,
self._cfgimpl_get_context()) self)
if not validate_properties: if not validate_properties:
return option return option
else: else:

View File

@ -634,15 +634,17 @@ class SymLinkOption(OnlyOption):
class DynSymLinkOption(object): class DynSymLinkOption(object):
__slots__ = ('_dyn', '_opt', '_name') __slots__ = ('_rootpath',
'_opt',
'_suffix')
def __init__(self, def __init__(self,
name,
opt, opt,
dyn): rootpath,
self._name = name suffix):
self._dyn = dyn
self._opt = opt self._opt = opt
self._rootpath = rootpath
self._suffix = suffix
def __getattr__(self, def __getattr__(self,
name, name,
@ -650,7 +652,7 @@ class DynSymLinkOption(object):
return getattr(self.impl_getopt(), name) return getattr(self.impl_getopt(), name)
def impl_getname(self): def impl_getname(self):
return self._name return self._opt.impl_getname() + self._suffix
def impl_get_display_name(self): def impl_get_display_name(self):
return self.impl_getopt().impl_get_display_name(dyn_name=self.impl_getname()) return self.impl_getopt().impl_get_display_name(dyn_name=self.impl_getname())
@ -659,18 +661,13 @@ class DynSymLinkOption(object):
return self._opt return self._opt
def impl_getsuffix(self): def impl_getsuffix(self):
return self._dyn.split('.')[-1][len(self.impl_getopt().impl_getname()):] return self._suffix
def impl_getpath(self, def impl_getpath(self,
context): context):
path = self.impl_getopt().impl_getpath(context) if self._rootpath == '':
base_path = '.'.join(path.split('.')[:-2]) return self.impl_getname()
if self.impl_is_master_slaves() and base_path is not '': return self._rootpath + '.' + self.impl_getname()
base_path = base_path + self.impl_getsuffix()
if base_path == '':
return self._dyn
else:
return base_path + '.' + self._dyn
def impl_validate(self, def impl_validate(self,
value, value,

View File

@ -91,4 +91,3 @@ class DynOptionDescription(OptionDescription):
'').format(val, '').format(val,
self.impl_get_display_name())) self.impl_get_display_name()))
return values return values

View File

@ -49,30 +49,32 @@ class MasterSlaves(OptionDescription):
master = children[0] master = children[0]
if not children: if not children:
raise ValueError(_('children is mandatory in masterslaves "{}"').format(name)) raise ValueError(_('children is mandatory in masterslaves "{}"').format(name))
for child in children[1:]:
if child.impl_getdefault() != []:
raise ValueError(_("not allowed default value for option {0} "
"in master/slave object {1}").format(child.impl_getname(),
name))
slaves.append(child)
child._add_dependency(self)
for idx, child in enumerate(children): for idx, child in enumerate(children):
if idx != 0 and child.impl_getdefault() != []:
raise ValueError(_('not allowed default value for option "{0}" '
'in master/slave object "{1}"'
'').format(child.impl_get_display_name(),
self.impl_get_display_name()))
if child.impl_is_symlinkoption(): # pragma: optional cover if child.impl_is_symlinkoption(): # pragma: optional cover
raise ValueError(_("master group {0} shall not have " raise ValueError(_('master group "{0}" shall not have '
"a symlinkoption").format(self.impl_getname())) "a symlinkoption").format(self.impl_get_display_name()))
if not isinstance(child, Option): # pragma: optional cover if not isinstance(child, Option): # pragma: optional cover
raise ValueError(_("master group {0} shall not have " raise ValueError(_('master group "{0}" shall not have '
"a subgroup").format(self.impl_getname())) 'a subgroup').format(self.impl_get_display_name()))
if not child.impl_is_multi(): # pragma: optional cover if not child.impl_is_multi(): # pragma: optional cover
raise ValueError(_("not allowed option {0} " raise ValueError(_('not allowed option "{0}" '
"in group {1}" 'in group "{1}"'
": this option is not a multi" ': this option is not a multi'
"").format(child.impl_getname(), self.impl_getname())) '').format(child.impl_get_display_name(),
self.impl_get_display_name()))
# no empty property for save # no empty property for save
if idx != 0: if idx != 0:
properties = list(child._properties) properties = list(child._properties)
properties.remove('empty') properties.remove('empty')
child._properties = tuple(properties) child._properties = tuple(properties)
slaves.append(child)
child._add_dependency(self)
child._master_slaves = weakref.ref(self)
callback, callback_params = master.impl_get_callback() callback, callback_params = master.impl_get_callback()
if callback is not None and callback_params != {}: if callback is not None and callback_params != {}:
for callbacks in callback_params.values(): for callbacks in callback_params.values():
@ -81,35 +83,16 @@ class MasterSlaves(OptionDescription):
if callbk[0] in slaves: if callbk[0] in slaves:
raise ValueError(_("callback of master's option shall " raise ValueError(_("callback of master's option shall "
"not refered a slave's ones")) "not refered a slave's ones"))
#everything is ok, store references
for child in children:
child._master_slaves = weakref.ref(self)
master._add_dependency(self)
def is_master(self, opt): def is_master(self, opt):
master = self._children[0][0] master = self._children[0][0]
return opt.impl_getname() == master or (opt.impl_is_dynsymlinkoption() and return opt.impl_getname() == master or (opt.impl_is_dynsymlinkoption() and
opt._opt.impl_getname() == master) opt._opt.impl_getname() == master)
def getmaster(self, opt): def getmaster(self):
master = self._children[1][0] return self._children[1][0]
if opt is not None and opt.impl_is_dynsymlinkoption():
suffix = opt.impl_getsuffix()
name = master.impl_getname() + suffix
base_path = opt._dyn.split('.')[0] + '.'
path = base_path + name
master = master._impl_to_dyn(name, path)
return master
def getslaves(self, opt): def getslaves(self):
if opt.impl_is_dynsymlinkoption():
for slave in self._children[1][1:]:
suffix = opt.impl_getsuffix()
name = slave.impl_getname() + suffix
base_path = opt._dyn.split('.')[0] + '.'
path = base_path + name
yield slave._impl_to_dyn(name, path)
else:
for slave in self._children[1][1:]: for slave in self._children[1][1:]:
yield slave yield slave
@ -127,7 +110,7 @@ class MasterSlaves(OptionDescription):
_commit=True, _commit=True,
force_permissive=False): force_permissive=False):
for slave in self.getslaves(opt): for slave in self.getslaves():
slave_path = slave.impl_getpath(values._getcontext()) slave_path = slave.impl_getpath(values._getcontext())
values.reset(slave, values.reset(slave,
slave_path, slave_path,
@ -137,15 +120,17 @@ class MasterSlaves(OptionDescription):
force_permissive=force_permissive) force_permissive=force_permissive)
def pop(self, def pop(self,
opt,
path,
values, values,
index, index,
setting_properties, setting_properties,
force_permissive=False): force_permissive,
slaves=undefined):
for slave in self.getslaves(opt): context = values._getcontext()
slave_path = slave.impl_getpath(values._getcontext()) if slaves is undefined:
slaves = self.getslaves()
for slave in slaves:
slave_path = slave.impl_getpath(context)
slavelen = values._p_.get_max_length(slave_path) slavelen = values._p_.get_max_length(slave_path)
if not values.is_default_owner(slave, if not values.is_default_owner(slave,
slave_path, slave_path,
@ -153,13 +138,6 @@ class MasterSlaves(OptionDescription):
validate_meta=False, validate_meta=False,
index=index, index=index,
force_permissive=force_permissive): force_permissive=force_permissive):
#FIXME # just for raise if needed
#multi = values.get_cached_value(slave,
# validate=False,
# validate_properties=False,
# )
#if isinstance(multi, Exception):
# raise multi
if slavelen > index: if slavelen > index:
values._p_.resetvalue_index(slave_path, values._p_.resetvalue_index(slave_path,
index) index)
@ -168,214 +146,6 @@ class MasterSlaves(OptionDescription):
values._p_.reduce_index(slave_path, values._p_.reduce_index(slave_path,
idx) idx)
def getitem(self,
values,
opt,
path,
validate,
force_permissive,
trusted_cached_properties,
validate_properties,
setting_properties=undefined,
self_properties=undefined,
index=None,
check_frozen=False):
if self.is_master(opt):
return self._getmaster(values,
opt,
path,
validate,
force_permissive,
validate_properties,
self_properties,
index,
setting_properties,
check_frozen)
else:
return self._getslave(values,
opt,
path,
validate,
force_permissive,
trusted_cached_properties,
validate_properties,
setting_properties,
self_properties,
index,
check_frozen)
def _getmaster(self,
values,
opt,
path,
validate,
force_permissive,
validate_properties,
self_properties,
index,
setting_properties,
check_frozen):
return values.get_cached_value(opt,
path=path,
validate=validate,
force_permissive=force_permissive,
self_properties=self_properties,
index=index,
setting_properties=setting_properties)
def _getslave(self, values, opt, path, validate, force_permissive,
trusted_cached_properties, validate_properties, setting_properties,
self_properties, index, check_frozen):
"""
if master has length 0:
return []
if master has length bigger than 0:
if default owner:
if has callback:
if return a list:
list same length as master: return list
list is smaller than master: return list + None
list is greater than master: raise SlaveError
if has default value:
list same length as master: return list
list is smaller than master: return list + None
list is greater than master: raise SlaveError
if has default_multi value:
return default_multi * master's length
if has value:
list same length as master: return list
list is smaller than master: return list + None
list is greater than master: raise SlaveError
"""
master = self.getmaster(opt)
context = values._getcontext()
masterp = master.impl_getpath(context)
try:
mastervalue = values.get_cached_value(master,
path=masterp,
validate=validate,
force_permissive=force_permissive,
validate_properties=validate_properties,
self_properties=self_properties,
from_masterslave=True,
setting_properties=setting_properties,
check_frozen=check_frozen)
except PropertiesOptionError as mastervalue:
mastervalue.set_orig_opt(opt)
raise mastervalue
masterlen = len(mastervalue)
#self._master_is_meta = values._is_meta(master, masterp, force_permissive=force_permissive)
multi = list() # values._get_multi(opt, path)
if validate_properties:
props = context.cfgimpl_get_settings().validate_properties(opt, False,
check_frozen,
value=multi,
path=path,
force_permissive=force_permissive,
setting_properties=setting_properties)
if props:
return props
#FIXME shouldn't have index!!!
if index is None:
indexes = range(0, masterlen)
else:
indexes = [index]
for idx in indexes:
try:
value = values.get_cached_value(opt,
path,
validate,
force_permissive,
trusted_cached_properties,
validate_properties,
index=idx,
# not self_properties,
# depends to index
#self_properties=self_properties,
setting_properties=setting_properties,
from_masterslave=True,
check_frozen=check_frozen)
except PropertiesOptionError as perr:
err = perr
if index is None:
multi.append(err)
else:
multi = err
if index is None:
multi.append(value)
else:
multi = value
return multi
def validate(self,
values,
opt,
index,
path,
setitem):
if self.is_master(opt):
#for regen slave path
base_path = '.'.join(path.split('.')[:-1]) + '.'
for slave in self.getslaves(opt):
slave_path = base_path + slave.impl_getname()
slavelen = values._p_.get_max_length(slave_path)
self.validate_slave_length(index,
slavelen,
slave.impl_getname(),
opt)
else:
val_len = self.get_length(values)
if isinstance(val_len, Exception):
return val_len
self.validate_slave_length(val_len,
index,
opt.impl_getname(),
opt,
setitem=setitem)
def get_length(self,
values,
validate=True,
force_permissive=False,
master=None,
masterp=None,
setting_properties=undefined):
"""get master len with slave option"""
if master is None:
master = self.getmaster(None)
if masterp is None:
masterp = master.impl_getpath(values._getcontext())
value = self._getmaster(values,
master,
masterp,
validate,
force_permissive,
validate,
undefined,
None,
setting_properties,
False)
if isinstance(value, Exception):
return value
return len(value)
def validate_slave_length(self,
masterlen,
valuelen,
name,
opt,
setitem=False):
if valuelen > masterlen or (valuelen < masterlen and setitem):
if debug: # pragma: no cover
log.debug('validate_slave_length: masterlen: {0}, valuelen: {1}, '
'setitem: {2}'.format(masterlen, valuelen, setitem))
if not opt.impl_is_master_slaves('master'):
opt = self.getmaster(opt)
raise SlaveError(_("invalid len for the slave: {0}"
" which has {1} as master").format(
name, opt.impl_getname()))
def reset_cache(self, def reset_cache(self,
opt, opt,
path, path,
@ -384,14 +154,14 @@ class MasterSlaves(OptionDescription):
resetted_opts): resetted_opts):
context = obj._getcontext() context = obj._getcontext()
#FIXME pb avec dyn, devrait etre une option #FIXME pb avec dyn, devrait etre une option
mopt = self.getmaster(None) mopt = self.getmaster()
mpath = mopt.impl_getpath(context) mpath = mopt.impl_getpath(context)
mopt.reset_cache(mopt, mopt.reset_cache(mopt,
mpath, mpath,
obj, obj,
type_, type_,
resetted_opts) resetted_opts)
for slave in self.getslaves(mopt): for slave in self.getslaves():
spath = slave.impl_getpath(context) spath = slave.impl_getpath(context)
slave.reset_cache(slave, slave.reset_cache(slave,
spath, spath,
@ -399,45 +169,6 @@ class MasterSlaves(OptionDescription):
type_, type_,
resetted_opts) resetted_opts)
def impl_getchild(self,
name,
setting_properties,
context=undefined,
dyn=True):
return super(MasterSlaves, self).impl_getchild(name,
setting_properties,
context,
dyn)
def impl_validate(self,
context,
force_permissive,
setting_properties,
masterlen=None,
slavelen=None,
opt=None,
setitem=False):
values = context.cfgimpl_get_values()
if masterlen is None:
master = self.getmaster(opt)
masterp = master.impl_getpath(context)
mastervalue = values.get_cached_value(master, path=masterp,
force_permissive=force_permissive,
setting_properties=setting_properties)
if isinstance(mastervalue, Exception):
return mastervalue
masterlen = len(mastervalue)
else:
master = opt
if slavelen is not None:
self.validate_slave_length(masterlen, slavelen, opt.impl_getname(), master, setitem=setitem)
else:
for slave in self.getslaves(master):
slave_path = slave.impl_getpath(context)
slavelen = values._p_.get_max_length(slave_path)
self.validate_slave_length(masterlen, slavelen, slave.impl_getname(), master)
def impl_validate_value(self, def impl_validate_value(self,
option, option,
value, value,
@ -446,3 +177,6 @@ class MasterSlaves(OptionDescription):
if len(value) < context._impl_length: if len(value) < context._impl_length:
return ValueError(_('cannot reduce length of master "{}"' return ValueError(_('cannot reduce length of master "{}"'
'').format(option.impl_get_display_name())) '').format(option.impl_get_display_name()))
def is_masterslaves(self):
return True

View File

@ -629,9 +629,9 @@ class Option(OnlyOption):
suffix = option.impl_getname()[namelen:] suffix = option.impl_getname()[namelen:]
opts = [] opts = []
for opt in all_cons_opts: for opt in all_cons_opts:
name = opt.impl_getname() + suffix opts.append(DynSymLinkOption(opt,
path = subpath + '.' + name subpath,
opts.append(opt._impl_to_dyn(name, path)) suffix))
else: else:
opts = all_cons_opts opts = all_cons_opts
err = opts[0]()._launch_consistency(self, err = opts[0]()._launch_consistency(self,
@ -685,13 +685,6 @@ class Option(OnlyOption):
warnings_only): warnings_only):
pass pass
def _impl_to_dyn(self,
name,
path):
return DynSymLinkOption(name,
self,
dyn=path)
def impl_getdefault_multi(self): def impl_getdefault_multi(self):
"accessing the default value for a multi" "accessing the default value for a multi"
if self.impl_is_submulti(): if self.impl_is_submulti():

View File

@ -24,7 +24,7 @@ from copy import copy
from ..i18n import _ from ..i18n import _
from ..setting import groups, undefined, owners from ..setting import groups, undefined, owners
from .baseoption import BaseOption from .baseoption import BaseOption
from .option import ALLOWED_CONST_LIST from .option import ALLOWED_CONST_LIST, DynSymLinkOption
from .syndynoptiondescription import SynDynOptionDescription from .syndynoptiondescription import SynDynOptionDescription
from ..error import ConfigError, ConflictError from ..error import ConfigError, ConflictError
@ -145,7 +145,9 @@ class CacheOptionDescription(BaseOption):
self._set_readonly() self._set_readonly()
def impl_already_build_caches(self): def impl_already_build_caches(self):
return getattr(self, '_cache_paths', None) is not None if hasattr(self, '_cache_paths'):
return True
return False
def impl_build_force_store_values(self, def impl_build_force_store_values(self,
config, config,
@ -202,8 +204,7 @@ class CacheOptionDescription(BaseOption):
cache_option) cache_option)
_currpath.pop() _currpath.pop()
if save: if save:
_setattr = object.__setattr__ self._cache_paths = (tuple(cache_option), tuple(cache_path))
_setattr(self, '_cache_paths', (tuple(cache_option), tuple(cache_path)))
class OptionDescriptionWalk(CacheOptionDescription): class OptionDescriptionWalk(CacheOptionDescription):
@ -250,8 +251,13 @@ class OptionDescriptionWalk(CacheOptionDescription):
path = _rebuild_dynpath(path, path = _rebuild_dynpath(path,
suffix, suffix,
subdyn) subdyn)
option = option._impl_to_dyn(name + suffix, if '.' in path:
path) subpath = path.rsplit('.', 1)[0]
else:
subpath = ''
option = DynSymLinkOption(option,
subpath,
suffix)
break break
if not found: if not found:
return False return False
@ -272,11 +278,17 @@ class OptionDescriptionWalk(CacheOptionDescription):
name = option.impl_getname() name = option.impl_getname()
for suffix in option._subdyn._impl_get_suffixes(context, for suffix in option._subdyn._impl_get_suffixes(context,
setting_properties): setting_properties):
spath = _rebuild_dynpath(path, path = _rebuild_dynpath(path,
suffix, suffix,
option._subdyn) option._subdyn)
find_results.append((spath, option._impl_to_dyn( if '.' in path:
name + suffix, spath))) subpath = path.rsplit('.', 1)[0]
else:
subpath = ''
doption = DynSymLinkOption(option,
subpath,
suffix)
find_results.append((subpath, doption))
else: else:
find_results.append((path, option)) find_results.append((path, option))
return True return True
@ -302,11 +314,17 @@ class OptionDescriptionWalk(CacheOptionDescription):
name = option.impl_getname() name = option.impl_getname()
for suffix in option._subdyn._impl_get_suffixes(context, for suffix in option._subdyn._impl_get_suffixes(context,
setting_properties): setting_properties):
spath = _rebuild_dynpath(path, path = _rebuild_dynpath(path,
suffix, suffix,
option._subdyn) option._subdyn)
find_results.append((spath, option._impl_to_dyn(name + suffix, if '.' in path:
spath))) subpath = path.rsplit('.', 1)[0]
else:
subpath = ''
doption = DynSymLinkOption(option,
subpath,
suffix)
find_results.append((path, doption))
else: else:
find_results.append((path, option)) find_results.append((path, option))
else: else:
@ -319,18 +337,17 @@ class OptionDescriptionWalk(CacheOptionDescription):
def impl_getchild(self, def impl_getchild(self,
name, name,
setting_properties, setting_properties,
context=undefined, subconfig):
dyn=True): if name in self._children[0]:
if name not in self._children[0]:
child = self._impl_search_dynchild(name,
context=context,
setting_properties=setting_properties)
if child:
return child
else:
child = self._children[1][self._children[0].index(name)] child = self._children[1][self._children[0].index(name)]
if not child.impl_is_dynoptiondescription(): if not child.impl_is_dynoptiondescription():
return child return child
else:
child = self._impl_search_dynchild(name,
subconfig=subconfig,
setting_properties=setting_properties)
if child:
return child
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()))
@ -340,7 +357,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
if getattr(self, '_cache_paths', None) is None: if getattr(self, '_cache_paths', None) is None:
raise ConfigError(_('use impl_get_opt_by_path only with root OptionDescription')) raise ConfigError(_('use impl_get_opt_by_path only with root OptionDescription'))
if path not in self._cache_paths[1]: if path not in self._cache_paths[1]:
raise AttributeError(_('no option for path {0}').format(path)) raise AttributeError(_('no option for path "{}"').format(path))
return self._cache_paths[0][self._cache_paths[1].index(path)] return self._cache_paths[0][self._cache_paths[1].index(path)]
def impl_get_path_by_opt(self, def impl_get_path_by_opt(self,
@ -348,7 +365,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
if getattr(self, '_cache_paths', None) is None: if getattr(self, '_cache_paths', None) is None:
raise ConfigError(_('use impl_get_path_by_opt only with root OptionDescription')) raise ConfigError(_('use impl_get_path_by_opt only with root OptionDescription'))
if opt not in self._cache_paths[0]: if opt not in self._cache_paths[0]:
raise AttributeError(_('no option {0} found').format(opt)) raise AttributeError(_('no option "{}" found').format(opt))
return self._cache_paths[1][self._cache_paths[0].index(opt)] return self._cache_paths[1][self._cache_paths[0].index(opt)]
def impl_getchildren(self, def impl_getchildren(self,
@ -374,37 +391,30 @@ class OptionDescriptionWalk(CacheOptionDescription):
def _impl_search_dynchild(self, def _impl_search_dynchild(self,
name, name,
context, subconfig,
setting_properties): setting_properties):
for child in self._impl_st_getchildren(only_dyn=True): for child in self._impl_st_getchildren(only_dyn=True):
cname = child.impl_getname() cname = child.impl_getname()
if name.startswith(cname): if name.startswith(cname):
for value in child._impl_get_suffixes(context, for value in child._impl_get_suffixes(subconfig._cfgimpl_get_context(),
setting_properties): setting_properties):
if name == cname + value: if name == cname + value:
return SynDynOptionDescription(child, return SynDynOptionDescription(child,
name, subconfig.cfgimpl_get_path(),
value) value)
def __getattr__(self,
name,
context=undefined,
setting_properties=undefined):
if name.startswith('_'):
return object.__getattribute__(self,
name)
def _impl_get_dynchild(self, def _impl_get_dynchild(self,
child, child,
suffix): suffix,
name = child.impl_getname() + suffix subpath):
path = self.impl_getname() + suffix + '.' + name
if isinstance(child, OptionDescription): if isinstance(child, OptionDescription):
return SynDynOptionDescription(child, return SynDynOptionDescription(child,
name, subpath,
suffix) suffix)
else: else:
return child._impl_to_dyn(name, return DynSymLinkOption(child,
path) subpath,
suffix)
class OptionDescription(OptionDescriptionWalk): class OptionDescription(OptionDescriptionWalk):
@ -456,6 +466,9 @@ class OptionDescription(OptionDescriptionWalk):
# the group_type is useful for filtering OptionDescriptions in a config # the group_type is useful for filtering OptionDescriptions in a config
self._group_type = groups.default self._group_type = groups.default
def is_masterslaves(self):
return False
def impl_getdoc(self): def impl_getdoc(self):
return self.impl_get_information('doc') return self.impl_get_information('doc')

View File

@ -20,20 +20,21 @@
# ____________________________________________________________ # ____________________________________________________________
from ..i18n import _ from ..i18n import _
from ..setting import undefined from ..setting import undefined
from .baseoption import DynSymLinkOption
class SynDynOptionDescription(object): class SynDynOptionDescription(object):
__slots__ = ('_opt', __slots__ = ('_opt',
'_name', '_subpath',
'_suffix') '_suffix')
def __init__(self, def __init__(self,
opt, opt,
name, subpath,
suffix): suffix):
self._opt = opt self._opt = opt
self._name = name self._subpath = subpath
self._suffix = suffix self._suffix = suffix
def __getattr__(self, name): def __getattr__(self, name):
@ -42,18 +43,19 @@ class SynDynOptionDescription(object):
def impl_getchild(self, def impl_getchild(self,
name, name,
setting_properties, setting_properties,
context): subconfig):
if name.endswith(self._suffix): if name.endswith(self._suffix):
oname = name[:-len(self._suffix)] oname = name[:-len(self._suffix)]
child = self._children[1][self._children[0].index(oname)] child = self._children[1][self._children[0].index(oname)]
return self._impl_get_dynchild(child, return self._impl_get_dynchild(child,
self._suffix) self._suffix,
subconfig.cfgimpl_get_path())
raise AttributeError(_('unknown Option {0} ' raise AttributeError(_('unknown Option {0} '
'in SynDynOptionDescription {1}' 'in SynDynOptionDescription {1}'
'').format(name, self.impl_getname())) '').format(name, self.impl_getname()))
def impl_getname(self): def impl_getname(self):
return self._name return self._opt.impl_getname() + self._suffix
def impl_getchildren(self, def impl_getchildren(self,
setting_properties, setting_properties,
@ -62,13 +64,39 @@ class SynDynOptionDescription(object):
children = [] children = []
for child in self._opt.impl_getchildren(setting_properties): for child in self._opt.impl_getchildren(setting_properties):
yield(self._opt._impl_get_dynchild(child, yield(self._opt._impl_get_dynchild(child,
self._suffix)) self._suffix,
self._subpath))
def impl_getpath(self, context): def impl_getpath(self):
path = self.impl_getopt().impl_getpath(context).split('.') subpath = self._subpath
path[-1] += self._suffix if subpath != '':
path.append(self._name) subpath += '.'
return '.'.join(path) return subpath + self.impl_getname()
def impl_getopt(self): def impl_getopt(self):
return self._opt return self._opt
def getmaster(self):
master = self._opt.getmaster()
return DynSymLinkOption(master,
self.impl_getpath(),
self._suffix)
def getslaves(self):
subpath = self.impl_getpath()
for slave in self._opt.getslaves():
yield DynSymLinkOption(slave,
subpath,
self._suffix)
def pop(self,
values,
index,
setting_properties,
force_permissive,
slaves=undefined):
self._opt.pop(values,
index,
setting_properties,
force_permissive,
slaves=self.getslaves())

View File

@ -20,6 +20,10 @@ from ...setting import undefined
from ...i18n import _ from ...i18n import _
DEBUG = True
DEBUG = False
class Values(Cache): class Values(Cache):
__slots__ = ('_values', '_informations', '__weakref__') __slots__ = ('_values', '_informations', '__weakref__')
@ -71,8 +75,8 @@ class Values(Cache):
"""set value for a path """set value for a path
a specified value must be associated to an owner a specified value must be associated to an owner
""" """
if value == 'y': if DEBUG:
raise Exception('pouet') print('setvalue', path, value, index)
values = [] values = []
vidx = None vidx = None
@ -93,6 +97,10 @@ class Values(Cache):
return: boolean return: boolean
""" """
has_path = path in self._values[0] has_path = path in self._values[0]
if path.startswith('subod.subodval'):
raise Exception('arf ...')
if DEBUG:
print('hasvalue', path, index, has_path)
if index is None: if index is None:
return has_path return has_path
elif has_path: elif has_path:
@ -105,6 +113,8 @@ class Values(Cache):
""" """
_values == ((path1, path2), ((idx1_1, idx1_2), None), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2)) _values == ((path1, path2), ((idx1_1, idx1_2), None), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
""" """
if DEBUG:
print('reduce_index', path, index)
path_idx = self._values[0].index(path) path_idx = self._values[0].index(path)
indexes = self._values[1][path_idx] indexes = self._values[1][path_idx]
if index in indexes: if index in indexes:
@ -118,6 +128,8 @@ class Values(Cache):
self._values = tuple(values) self._values = tuple(values)
def resetvalue_index(self, path, index): def resetvalue_index(self, path, index):
if DEBUG:
print('resetvalue_index', path, index)
def _resetvalue(nb): def _resetvalue(nb):
values_idx = list(values[nb]) values_idx = list(values[nb])
del(values_idx[path_idx]) del(values_idx[path_idx])
@ -149,6 +161,8 @@ class Values(Cache):
def resetvalue(self, path, commit): def resetvalue(self, path, commit):
"""remove value means delete value in storage """remove value means delete value in storage
""" """
if DEBUG:
print('resetvalue', path)
def _resetvalue(nb): def _resetvalue(nb):
lst = list(self._values[nb]) lst = list(self._values[nb])
lst.pop(idx) lst.pop(idx)
@ -217,6 +231,8 @@ class Values(Cache):
with_value) with_value)
if owner is undefined: if owner is undefined:
owner = default owner = default
if DEBUG:
print('getvalue', path, index, value)
if with_value: if with_value:
return owner, value return owner, value
else: else:

View File

@ -489,7 +489,7 @@ class Values(object):
if meta is None: if meta is None:
return False return False
if opt.impl_is_master_slaves('slave'): if opt.impl_is_master_slaves('slave'):
master = opt.impl_get_master_slaves().getmaster(opt) master = opt.impl_get_master_slaves().getmaster()
masterp = master.impl_getpath(context) masterp = master.impl_getpath(context)
# slave could be a "meta" only if master hasn't value # slave could be a "meta" only if master hasn't value
if self._p_.hasvalue(masterp, if self._p_.hasvalue(masterp,
@ -714,12 +714,10 @@ class Values(object):
index=None, index=None,
setting_properties=setting_properties, setting_properties=setting_properties,
_commit=True) _commit=True)
subconfig.cfgimpl_get_description().pop(opt, subconfig.cfgimpl_get_description().pop(self,
path,
self,
index, index,
setting_properties, setting_properties,
force_permissive=force_permissive) force_permissive)
#______________________________________________________________________ #______________________________________________________________________
# information # information