some corrections

This commit is contained in:
Emmanuel Garette 2018-03-31 21:06:19 +02:00
parent eba178cdee
commit 790115c919
4 changed files with 284 additions and 288 deletions

View file

@ -9,7 +9,7 @@ do_autopath()
from tiramisu import Config, MetaConfig, \ from tiramisu import Config, MetaConfig, \
StrOption, SymLinkOption, OptionDescription, MasterSlaves, DynOptionDescription, \ StrOption, SymLinkOption, OptionDescription, MasterSlaves, DynOptionDescription, \
getapi, submulti, undefined, owners getapi, submulti, undefined, owners
from tiramisu.error import PropertiesOptionError, APIError, ConfigError from tiramisu.error import PropertiesOptionError, APIError, ConfigError, SlaveError
from tiramisu.api import display_count from tiramisu.api import display_count
from collections import OrderedDict from collections import OrderedDict
ICON = u'\u2937' ICON = u'\u2937'
@ -77,46 +77,27 @@ def autocheck_option_multi(api, pathread, pathwrite, confread, confwrite, **kwar
api.option(pathread).option.issubmulti() api.option(pathread).option.issubmulti()
api.option(pathread).option.ismaster() api.option(pathread).option.ismaster()
api.option(pathread).option.isslave() api.option(pathread).option.isslave()
# else:
raises(PropertiesOptionError, "api.option(pathread).option.ismulti()")
raises(PropertiesOptionError, "api.option(pathread).option.issubmulti()")
raises(PropertiesOptionError, "api.option(pathread).option.ismaster()")
raises(PropertiesOptionError, "api.option(pathread).option.isslave()")
#
if not kwargs.get('propertyerror', False):
api.forcepermissive.option(pathread).option.ismulti() api.forcepermissive.option(pathread).option.ismulti()
api.forcepermissive.option(pathread).option.issubmulti() api.forcepermissive.option(pathread).option.issubmulti()
api.forcepermissive.option(pathread).option.ismaster() api.forcepermissive.option(pathread).option.ismaster()
api.forcepermissive.option(pathread).option.isslave() api.forcepermissive.option(pathread).option.isslave()
# else:
api.unrestraint.option(pathread).option.ismulti() raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.ismulti()")
api.unrestraint.option(pathread).option.issubmulti() raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.issubmulti()")
api.unrestraint.option(pathread).option.ismaster() raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.ismaster()")
api.unrestraint.option(pathread).option.isslave() raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.isslave()")
elif not kwargs.get('propertyerror', False): #
#raises(PropertiesOptionError, "api.option(pathread).option.ismulti()") api.unrestraint.option(pathread).option.ismulti()
#raises(PropertiesOptionError, "api.option(pathread).option.issubmulti()") api.unrestraint.option(pathread).option.issubmulti()
#raises(PropertiesOptionError, "api.option(pathread).option.ismaster()") api.unrestraint.option(pathread).option.ismaster()
#raises(PropertiesOptionError, "api.option(pathread).option.isslave()") api.unrestraint.option(pathread).option.isslave()
#
api.forcepermissive.option(pathread).option.ismulti()
api.forcepermissive.option(pathread).option.issubmulti()
api.forcepermissive.option(pathread).option.ismaster()
api.forcepermissive.option(pathread).option.isslave()
#
api.unrestraint.option(pathread).option.ismulti()
api.unrestraint.option(pathread).option.issubmulti()
api.unrestraint.option(pathread).option.ismaster()
api.unrestraint.option(pathread).option.isslave()
#else:
# raises(PropertiesOptionError, "api.option(pathread).option.ismulti()")
# raises(PropertiesOptionError, "api.option(pathread).option.issubmulti()")
# raises(PropertiesOptionError, "api.option(pathread).option.ismaster()")
# raises(PropertiesOptionError, "api.option(pathread).option.isslave()")
# #
# raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.ismulti()")
# raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.issubmulti()")
# raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.ismaster()")
# raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.isslave()")
# #
# api.unrestraint.option(pathread).option.ismulti()
# api.unrestraint.option(pathread).option.issubmulti()
# api.unrestraint.option(pathread).option.ismaster()
# api.unrestraint.option(pathread).option.isslave()
@autocheck @autocheck
@ -134,17 +115,17 @@ def autocheck_default_owner(api, pathread, pathwrite, confread, confwrite, **kwa
assert api.config(conf).option(pathread).owner.isdefault() assert api.config(conf).option(pathread).owner.isdefault()
assert api.forcepermissive.config(conf).option(pathread).owner.isdefault() assert api.forcepermissive.config(conf).option(pathread).owner.isdefault()
elif not kwargs.get('propertyerror', False): elif not kwargs.get('propertyerror', False):
#raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()") raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
assert api.forcepermissive.config(conf).option(pathread).owner.get() == 'default' assert api.forcepermissive.config(conf).option(pathread).owner.get() == 'default'
# #
#raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.isdefault()") raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.isdefault()")
assert api.forcepermissive.config(conf).option(pathread).owner.isdefault() assert api.forcepermissive.config(conf).option(pathread).owner.isdefault()
#else: else:
# raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()") raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
# raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.get()") raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.get()")
# # #
# raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.isdefault()") raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.isdefault()")
# raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.isdefault()") raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.isdefault()")
else: else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.config(conf).option(pathread, 0).owner.get() == 'default' assert api.config(conf).option(pathread, 0).owner.get() == 'default'
@ -166,8 +147,8 @@ def autocheck_default_owner(api, pathread, pathwrite, confread, confwrite, **kwa
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault()") raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault()")
# unrestraint is not allowed # unrestraint is not allowed
#raises(APIError, "api.unrestraint.config(conf).option(pathread).owner.get()") raises(APIError, "api.unrestraint.config(conf).option(pathread).owner.get()")
#raises(APIError, "api.unrestraint.config(conf).option(pathread).owner.isdefault()") raises(APIError, "api.unrestraint.config(conf).option(pathread).owner.isdefault()")
do(confread) do(confread)
if confread != confwrite: if confread != confwrite:
do(confwrite) do(confwrite)
@ -256,7 +237,8 @@ def _set_value(api, pathwrite, conf, **kwargs):
raises(PropertiesOptionError, "api.config(conf).option(pathwrite).value.set([first_value[0]])") raises(PropertiesOptionError, "api.config(conf).option(pathwrite).value.set([first_value[0]])")
raises(PropertiesOptionError, raises(PropertiesOptionError,
"api.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]])") "api.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]])")
raises(APIError, "api.unrestraint.config(conf).option(pathwrite).value.set(first_value[1])") if len(first_value) > 1:
raises(APIError, "api.unrestraint.config(conf).option(pathwrite).value.set(first_value[1])")
elif isslave: elif isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not set_permissive: if not set_permissive:
@ -287,7 +269,7 @@ def _set_value(api, pathwrite, conf, **kwargs):
else: else:
raises(PropertiesOptionError, "api.config(conf).option(pathwrite).value.set(first_value)") raises(PropertiesOptionError, "api.config(conf).option(pathwrite).value.set(first_value)")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathwrite).value.set(first_value)") raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathwrite).value.set(first_value)")
#raises(APIError, "api.unrestraint.config(conf).option(pathwrite).value.set(first_value)") #FIXME raises(APIError, "api.unrestraint.config(conf).option(pathwrite).value.set(first_value)")
@autocheck @autocheck
@ -418,7 +400,8 @@ def autocheck_get_value(api, pathread, pathwrite, confread, confwrite, **kwargs)
def autocheck_value_slave(api, pathread, pathwrite, confread, confwrite, **kwargs): def autocheck_value_slave(api, pathread, pathwrite, confread, confwrite, **kwargs):
isslave = api.unrestraint.option(pathread).option.isslave() isslave = api.unrestraint.option(pathread).option.isslave()
if not isslave: if not isslave:
#FIXME raises(APIError, "api.config(confread).option(pathread).value.len()") if kwargs.get('propertyerror', False):
raises(APIError, "api.config(confread).option(pathread).value.len()")
return return
if kwargs.get('propertyerror', False): if kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option(pathread).value.len()") raises(PropertiesOptionError, "api.option(pathread).value.len()")
@ -453,14 +436,14 @@ def autocheck_value_slave(api, pathread, pathwrite, confread, confwrite, **kwarg
else: else:
value = SUBLIST_FIRST_VALUE[0] value = SUBLIST_FIRST_VALUE[0]
raises(IndexError, "api.forcepermissive.option(pathread, length).value.get()") raises(SlaveError, "api.forcepermissive.option(pathread, length).value.get()")
raises(IndexError, "api.forcepermissive.option(pathread, length).value.set(value)") raises(SlaveError, "api.forcepermissive.option(pathread, length).value.set(value)")
raises(IndexError, "api.forcepermissive.option(pathread, length).value.reset()") raises(SlaveError, "api.forcepermissive.option(pathread, length).value.reset()")
raises(IndexError, "api.forcepermissive.option(pathread, length).owner.get()") raises(SlaveError, "api.forcepermissive.option(pathread, length).owner.get()")
raises(IndexError, "api.forcepermissive.option(pathread, length).owner.isdefault()") raises(SlaveError, "api.forcepermissive.option(pathread, length).owner.isdefault()")
raises(IndexError, "api.forcepermissive.option(pathread, length).property.get()") raises(SlaveError, "api.forcepermissive.option(pathread, length).property.get()")
raises(IndexError, "api.forcepermissive.option(pathread, length).owner.set('new_user')") raises(SlaveError, "api.forcepermissive.option(pathread, length).owner.set('new_user')")
raises(IndexError, "api.forcepermissive.option(pathread, length).property.set(('prop',))") raises(SlaveError, "api.forcepermissive.option(pathread, length).property.add('prop')")
@autocheck @autocheck
@ -488,12 +471,12 @@ def autocheck_reset_value(api, pathread, pathwrite, confread, confwrite, **kwarg
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.config(confwrite).option(pathwrite).value.reset() api.config(confwrite).option(pathwrite).value.reset()
#else: #else:
# raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).value.reset()") #FIXME raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).value.reset()")
else: else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.config(confwrite).option(pathwrite, 0).value.reset() api.config(confwrite).option(pathwrite, 0).value.reset()
#else: #else:
# raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite, 0).value.reset()") #FIXME raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite, 0).value.reset()")
# get value after reset value without permissive # get value after reset value without permissive
def do(conf): def do(conf):
@ -606,7 +589,6 @@ def autocheck_reset_value_permissive(api, pathread, pathwrite, confread, confwri
# check if is a multi, a master or a slave # check if is a multi, a master or a slave
isslave = api.unrestraint.option(pathread).option.isslave() isslave = api.unrestraint.option(pathread).option.isslave()
_set_value(api, pathwrite, confwrite, **kwargs) _set_value(api, pathwrite, confwrite, **kwargs)
# reset value with permissive # reset value with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave: if not isslave:
@ -618,14 +600,14 @@ def autocheck_reset_value_permissive(api, pathread, pathwrite, confread, confwri
api.forcepermissive.config(confwrite).option(pathwrite).value.reset() api.forcepermissive.config(confwrite).option(pathwrite).value.reset()
else: else:
api.forcepermissive.option(pathwrite, 1).value.reset() api.forcepermissive.option(pathwrite, 1).value.reset()
#else: #FIXME else:
# if not isslave: # if not isslave:
# raises(PropertiesOptionError, "api.forcepermissive.config(confwrite).option(pathwrite).value.reset()") # raises(PropertiesOptionError, "api.forcepermissive.config(confwrite).option(pathwrite).value.reset()")
# else: # else:
# raises(PropertiesOptionError, "api.forcepermissive.option(pathwrite, 1).value.reset()") # raises(PropertiesOptionError, "api.forcepermissive.option(pathwrite, 1).value.reset()")
_autocheck_default_value(api, pathread, confread, **kwargs) _autocheck_default_value(api, pathread, confread, **kwargs)
if confread != confwrite: if confread != confwrite:
_autocheck_default_value(api, pathread, confwrite, **kwargs) _autocheck_default_value(api, pathwrite, confwrite, **kwargs)
@autocheck @autocheck
@ -636,16 +618,10 @@ def autocheck_display(api, pathread, pathwrite, 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(api.config(confread).config.make_dict())
assert api.config(confread).option.make_dict() == make_dict assert api.config(confread).option.make_dict() == make_dict
if confread != confwrite: if confread != confwrite:
assert(api.config(confwrite).option.make_dict()) == make_dict assert(api.config(confwrite).option.make_dict()) == make_dict
_set_value(api, pathwrite, confwrite, **kwargs) _set_value(api, pathwrite, confwrite, **kwargs)
#print('--')
#print(make_dict_value)
#print(api.config(confread).config.make_dict())
assert api.config(confread).option.make_dict() == make_dict_value assert api.config(confread).option.make_dict() == make_dict_value
if confread != confwrite: if confread != confwrite:
assert(api.config(confwrite).option.make_dict()) == make_dict_value assert(api.config(confwrite).option.make_dict()) == make_dict_value
@ -666,29 +642,52 @@ def _getproperties(multi, isslave, kwargs):
return default_props, frozenset(properties) return default_props, frozenset(properties)
def _check_default_properties(api, pathread, conf, kwargs, props_permissive, props): def _check_properties(api, pathread, conf, kwargs, props_permissive, props):
if not api.unrestraint.option(pathread).option.isslave(): if not api.unrestraint.option(pathread).option.isslave():
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert set(api.config(conf).option(pathread).property.get()) == set(props_permissive) assert set(api.config(conf).option(pathread).property.get()) == set(props_permissive)
assert set(api.config(conf).forcepermissive.option(pathread).property.get()) == set(props_permissive) assert set(api.config(conf).option(pathread).property.get()) == set(props)
elif not kwargs.get('propertyerror', False): else:
#raises(PropertiesOptionError, "api.config(conf).option(pathread).property.get()") raises(PropertiesOptionError, "api.config(conf).option(pathread).property.get()")
raises(PropertiesOptionError, "api.config(conf).option(pathread).property.get()")
if kwargs.get('propertyerror', False):
assert set(api.forcepermissive.config(conf).option(pathread).property.get()) == set(props_permissive)
assert set(api.forcepermissive.config(conf).option(pathread).property.get()) == set(props) assert set(api.forcepermissive.config(conf).option(pathread).property.get()) == set(props)
#else: else:
# raises(PropertiesOptionError, "api.config(conf).option(pathread).property.get()") assert(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).property.get()")
# raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).property.get()") assert(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).property.get()")
#raises(APIError, "api.unrestraint.option(pathread).property.get()") assert set(api.unrestraint.config(conf).option(pathread).property.get()) == set(props_permissive)
assert set(api.unrestraint.config(conf).option(pathread).property.get()) == set(props)
else: else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert set(api.config(conf).option(pathread, 0).property.get()) == set(props_permissive) assert set(api.config(conf).option(pathread, 0).property.get()) == set(props_permissive)
assert set(api.config(conf).option(pathread, 0).property.get()) == set(props)
#
assert set(api.config(conf).option(pathread, 1).property.get()) == set(props_permissive) assert set(api.config(conf).option(pathread, 1).property.get()) == set(props_permissive)
elif not kwargs.get('propertyerror', False): assert set(api.config(conf).option(pathread, 1).property.get()) == set(props)
raises(PropertiesOptionError, "api.config(conf).option(pathread).property.get()")
assert set(api.forcepermissive.config(conf).option(pathread, 0).property.get()) == set(props)
assert set(api.forcepermissive.config(conf).option(pathread, 1).property.get()) == set(props)
else: else:
raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).property.get()") raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).property.get()")
raises(APIError, "api.unrestraint.option(pathread, 0).property.get()") raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).property.get()")
#
raises(PropertiesOptionError, "api.config(conf).option(pathread, 1).property.get()")
raises(PropertiesOptionError, "api.config(conf).option(pathread, 1).property.get()")
if kwargs.get('propertyerror', False):
assert set(api.forcepermissive.config(conf).option(pathread, 0).property.get()) == set(props_permissive)
assert set(api.forcepermissive.config(conf).option(pathread, 0).property.get()) == set(props)
#
assert set(api.forcepermissive.config(conf).option(pathread, 1).property.get()) == set(props_permissive)
assert set(api.forcepermissive.config(conf).option(pathread, 1).property.get()) == set(props)
else:
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).property.get()")
#
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 1).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 1).property.get()")
assert set(api.unrestraint.config(conf).option(pathread, 0).property.get()) == set(props_permissive)
assert set(api.unrestraint.config(conf).option(pathread, 0).property.get()) == set(props)
#
assert set(api.unrestraint.config(conf).option(pathread, 1).property.get()) == set(props_permissive)
assert set(api.unrestraint.config(conf).option(pathread, 1).property.get()) == set(props)
@autocheck @autocheck
@ -701,21 +700,17 @@ def autocheck_property(api, pathread, pathwrite, confread, confwrite, **kwargs):
default_props, properties = _getproperties(multi, isslave, kwargs) default_props, properties = _getproperties(multi, isslave, kwargs)
_check_default_properties(api, pathread, confread, kwargs, default_props, default_props) _check_properties(api, pathread, confread, kwargs, default_props, default_props)
_check_default_properties(api, pathread, confwrite, kwargs, default_props, default_props) if confread != confwrite:
_check_properties(api, pathread, confwrite, kwargs, default_props, default_props)
# set properties without permissive # set properties without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): for prop in properties:
for prop in properties: api.config(confwrite).option(pathwrite).property.add(prop)
api.config(confwrite).option(pathwrite).property.add(prop) _check_properties(api, pathread, confread, kwargs, properties, properties)
#else:
# raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).property.set(properties)")
_check_default_properties(api, pathread, confread, kwargs, properties, default_props)
if confread != confwrite: if confread != confwrite:
_check_default_properties(api, pathread, confwrite, kwargs, properties, default_props) _check_properties(api, pathread, confwrite, kwargs, properties, properties)
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
raises(ConfigError, "api.config(confread).option(pathread).property.set(properties)")
def _property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs): def _property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs):
@ -736,28 +731,19 @@ def _property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs
default_props.extend(extra_properties) default_props.extend(extra_properties)
default_props, properties = _getproperties(multi, isslave, kwargs) default_props, properties = _getproperties(multi, isslave, kwargs)
_check_default_properties(api, pathread, confwrite, kwargs, default_props, default_props) _check_properties(api, pathread, confwrite, kwargs, default_props, default_props)
if confwrite != confread: if confwrite != confread:
_check_default_properties(api, pathread, confread, kwargs, default_props, default_props) _check_properties(api, pathread, confread, kwargs, default_props, default_props)
# set properties with permissive # set properties with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): for prop in properties:
for prop in properties: api.config(confwrite).option(pathwrite).property.add(prop)
api.config(confwrite).option(pathwrite).property.add(prop) api.forcepermissive.config(confwrite).option(pathwrite).property.add(prop)
api.forcepermissive.config(confwrite).option(pathwrite).property.add(prop) api.unrestraint.config(confwrite).option(pathwrite).property.add(prop)
elif not kwargs.get('propertyerror', False):
for prop in properties:
#raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).property.add(prop)")
api.forcepermissive.config(confwrite).option(pathwrite).property.add(prop)
#else:
# raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).property.set(properties)")
# raises(PropertiesOptionError, "api.forcepermissive.config(confwrite).option(pathwrite).property.set(properties)")
_check_default_properties(api, pathread, confwrite, kwargs, properties, properties) _check_properties(api, pathread, confwrite, kwargs, properties, properties)
if confwrite != confread: if confwrite != confread:
_check_default_properties(api, pathread, confread, kwargs, properties, properties) _check_properties(api, pathread, confread, kwargs, properties, properties)
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
raises(ConfigError, "api.config(confread).option(pathwrite).property.set(properties)")
@autocheck @autocheck
@ -777,16 +763,11 @@ def autocheck_reset_property(api, pathread, pathwrite, confread, confwrite, **kw
_property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs) _property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs)
# reset properties without permissive # reset properties without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): api.config(confwrite).option(pathwrite).property.reset()
api.config(confwrite).option(pathwrite).property.reset()
#else:
# raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).property.reset()")
_check_default_properties(api, pathread, confread, kwargs, default_props, properties) _check_properties(api, pathread, confread, kwargs, default_props, default_props)
if confread != confwrite: if confread != confwrite:
_check_default_properties(api, pathread, confwrite, kwargs, default_props, properties) _check_properties(api, pathread, confwrite, kwargs, default_props, default_props)
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
raises(ConfigError, "api.config(confread).option(pathread).property.reset()")
@autocheck @autocheck
@ -798,25 +779,19 @@ def autocheck_reset_property_permissive(api, pathread, pathwrite, confread, conf
_property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs) _property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs)
# reset properties with permissive for prop in properties:
raises(APIError, "api.unrestraint.option(pathwrite).property.set(properties)") api.forcepermissive.option(pathwrite).property.add(prop)
#raises(APIError, "api.unrestraint.option(pathwrite).property.reset()") api.forcepermissive.option(pathwrite).property.reset()
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
for prop in properties:
api.forcepermissive.option(pathwrite).property.add(prop)
api.forcepermissive.option(pathwrite).property.reset()
elif kwargs.get('permissive', False):
api.forcepermissive.option(pathwrite).property.reset()
_check_default_properties(api, pathread, confwrite, kwargs, default_props, default_props) _check_properties(api, pathread, confwrite, kwargs, default_props, default_props)
if confread != confwrite: if confread != confwrite:
_check_default_properties(api, pathread, confread, kwargs, default_props, default_props) _check_properties(api, pathread, confread, kwargs, default_props, default_props)
@autocheck @autocheck
def autocheck_context_owner(api, pathread, pathwrite, confread, confwrite, **kwargs): def autocheck_context_owner(api, pathread, pathwrite, confread, confwrite, **kwargs):
owner = api.owner.get() owner = api.owner.get()
assert owner == OWNER assert owner == kwargs['owner']
def _check_owner(api, pathread, conf, kwargs, owner, permissive_owner): def _check_owner(api, pathread, conf, kwargs, owner, permissive_owner):
@ -826,11 +801,11 @@ def _check_owner(api, pathread, conf, kwargs, owner, permissive_owner):
assert api.config(conf).option(pathread).owner.get() == owner assert api.config(conf).option(pathread).owner.get() == owner
assert api.forcepermissive.config(conf).option(pathread).owner.get() == owner assert api.forcepermissive.config(conf).option(pathread).owner.get() == owner
elif not kwargs.get('propertyerror', False): elif not kwargs.get('propertyerror', False):
#raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()") raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
assert api.forcepermissive.config(conf).option(pathread).owner.get() == permissive_owner assert api.forcepermissive.config(conf).option(pathread).owner.get() == permissive_owner
#else: else:
# raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()") raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
# raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.get()") raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.get()")
else: else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.config(conf).option(pathread, 0).owner.get() == 'default' assert api.config(conf).option(pathread, 0).owner.get() == 'default'
@ -852,9 +827,9 @@ def autocheck_owner_with_value(api, pathread, pathwrite, confread, confwrite, **
"""value is now changed, check owner in this case """value is now changed, check owner in this case
""" """
_set_value(api, pathwrite, confwrite, **kwargs) _set_value(api, pathwrite, confwrite, **kwargs)
_check_owner(api, pathread, confwrite, kwargs, OWNER, OWNER) _check_owner(api, pathread, confwrite, kwargs, kwargs['owner'], kwargs['owner'])
if confread != confwrite: if confread != confwrite:
_check_owner(api, pathread, confread, kwargs, owners.meta, owners.meta) _check_owner(api, pathread, confread, kwargs, kwargs['owner'], kwargs['owner'])
@autocheck @autocheck
@ -868,7 +843,7 @@ def autocheck_default_owner_with_value(api, pathread, pathwrite, confread, confw
assert api.config(confwrite).option(pathread).owner.isdefault() is False assert api.config(confwrite).option(pathread).owner.isdefault() is False
if confwrite != confread: if confwrite != confread:
assert api.config(confread).option(pathread).owner.isdefault() is False assert api.config(confread).option(pathread).owner.isdefault() is False
#else: #FIXME else:
# raises(PropertiesOptionError, "api.config(confwrite).option(pathread).owner.isdefault()") # raises(PropertiesOptionError, "api.config(confwrite).option(pathread).owner.isdefault()")
# raises(PropertiesOptionError, "api.config(confread).option(pathread).owner.isdefault()") # raises(PropertiesOptionError, "api.config(confread).option(pathread).owner.isdefault()")
else: else:
@ -878,9 +853,9 @@ def autocheck_default_owner_with_value(api, pathread, pathwrite, confread, confw
if confwrite != confread: if confwrite != confread:
assert api.config(confread).option(pathread, 0).owner.isdefault() is True assert api.config(confread).option(pathread, 0).owner.isdefault() is True
assert api.config(confread).option(pathread, 1).owner.isdefault() is False assert api.config(confread).option(pathread, 1).owner.isdefault() is False
else: #FIXME else:
raises(PropertiesOptionError, "api.config(confwrite).option(pathread, 0).owner.isdefault()") # raises(PropertiesOptionError, "api.config(confwrite).option(pathread, 0).owner.isdefault()")
raises(PropertiesOptionError, "api.config(confread).option(pathread, 0).owner.isdefault()") # raises(PropertiesOptionError, "api.config(confread).option(pathread, 0).owner.isdefault()")
@autocheck @autocheck
@ -898,7 +873,7 @@ def autocheck_default_owner_with_value_permissive(api, pathread, pathwrite, conf
else: else:
assert api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() is True assert api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() is True
assert api.forcepermissive.config(conf).option(pathread, 1).owner.isdefault() is False assert api.forcepermissive.config(conf).option(pathread, 1).owner.isdefault() is False
#else: #FIXME else:
# raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.isdefault()") # raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.isdefault()")
do(confwrite) do(confwrite)
if confwrite != confread: if confwrite != confread:
@ -929,17 +904,17 @@ def autocheck_set_owner(api, pathread, pathwrite, confread, confwrite, **kwargs)
raises(ConfigError, "api.config(confwrite).option(pathwrite).owner.set('default')") raises(ConfigError, "api.config(confwrite).option(pathwrite).owner.set('default')")
raises(ConfigError, "api.config(confwrite).option(pathwrite).owner.set('forced')") raises(ConfigError, "api.config(confwrite).option(pathwrite).owner.set('forced')")
raises(ConfigError, "api.config(confwrite).option(pathwrite).owner.set('meta')") raises(ConfigError, "api.config(confwrite).option(pathwrite).owner.set('meta')")
#else: #FIXME else:
# raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).owner.set('new_user')") # raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).owner.set('new_user')")
else: else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.option(pathwrite, 1).owner.set('new_user') api.option(pathwrite, 1).owner.set('new_user')
else: #FIXME else:
raises(PropertiesOptionError, "api.option(pathwrite, 1).owner.set('new_user')") # raises(PropertiesOptionError, "api.option(pathwrite, 1).owner.set('new_user')")
_check_owner(api, pathread, confwrite, kwargs, owners.new_user, OWNER) _check_owner(api, pathread, confwrite, kwargs, owners.new_user, kwargs['owner'])
if confwrite != confread: if confwrite != confread:
_check_owner(api, pathread, confread, kwargs, owners.meta, owners.meta) _check_owner(api, pathread, confread, kwargs, owners.new_user, owners.meta)
@autocheck @autocheck
@ -954,7 +929,7 @@ def autocheck_set_owner_permissive(api, pathread, pathwrite, confread, confwrite
api.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1') api.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1')
else: else:
api.forcepermissive.option(pathwrite, 1).owner.set('new_user1') api.forcepermissive.option(pathwrite, 1).owner.set('new_user1')
#else: #FIXME else:
# if not isslave: # if not isslave:
# raises(PropertiesOptionError, # raises(PropertiesOptionError,
# "api.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1')") # "api.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1')")
@ -964,40 +939,40 @@ def autocheck_set_owner_permissive(api, pathread, pathwrite, confread, confwrite
_check_owner(api, pathread, confwrite, kwargs, 'new_user1', 'new_user1') _check_owner(api, pathread, confwrite, kwargs, 'new_user1', 'new_user1')
if confwrite != confread: if confwrite != confread:
_check_owner(api, pathread, confread, kwargs, owners.meta, owners.meta) _check_owner(api, pathread, confread, kwargs, 'new_user1', 'new_user1')
@autocheck #FIXME @autocheck
def autocheck_option(api, pathread, pathwrite, confread, confwrite, **kwargs): #def autocheck_option(api, pathread, pathwrite, confread, confwrite, **kwargs):
expected_name = pathread.split('.')[-1] # expected_name = pathread.split('.')[-1]
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): # if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
current_name = api.option(pathread).option.name # current_name = api.option(pathread).option.name
assert current_name == api.forcepermissive.option(pathread).option.name # assert current_name == api.forcepermissive.option(pathread).option.name
assert current_name == api.unrestraint.option(pathread).option.name # assert current_name == api.unrestraint.option(pathread).option.name
doc = api.option(pathread).option.doc() # doc = api.option(pathread).option.doc()
assert doc == api.forcepermissive.option(pathread).option.doc() # assert doc == api.forcepermissive.option(pathread).option.doc()
assert doc == api.unrestraint.option(pathread).option.doc() # assert doc == api.unrestraint.option(pathread).option.doc()
elif not kwargs.get('propertyerror', False): # elif not kwargs.get('propertyerror', False):
#raises(PropertiesOptionError, "api.option(pathread).option.name") # raises(PropertiesOptionError, "api.option(pathread).option.name")
current_name = api.forcepermissive.option(pathread).option.name # current_name = api.forcepermissive.option(pathread).option.name
assert current_name == api.unrestraint.option(pathread).option.name # assert current_name == api.unrestraint.option(pathread).option.name
#raises(PropertiesOptionError, "api.option(pathread).option.doc()") # raises(PropertiesOptionError, "api.option(pathread).option.doc()")
doc = api.forcepermissive.option(pathread).option.doc() # doc = api.forcepermissive.option(pathread).option.doc()
assert doc == api.unrestraint.option(pathread).option.doc() # assert doc == api.unrestraint.option(pathread).option.doc()
else: # else:
# raises(PropertiesOptionError, "api.option(pathread).option.name") # raises(PropertiesOptionError, "api.option(pathread).option.name")
# raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.name") # raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.name")
current_name = api.unrestraint.option(pathread).option.name # current_name = api.unrestraint.option(pathread).option.name
# raises(PropertiesOptionError, "api.option(pathread).option.doc()") # raises(PropertiesOptionError, "api.option(pathread).option.doc()")
# raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.doc()") # raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.doc()")
doc = api.unrestraint.option(pathread).option.doc() # doc = api.unrestraint.option(pathread).option.doc()
assert current_name == expected_name # assert current_name == expected_name
if expected_name.endswith('val1') or expected_name.endswith('val2'): # if expected_name.endswith('val1') or expected_name.endswith('val2'):
expected_name = expected_name[:-4] # expected_name = expected_name[:-4]
if kwargs['symlink']: # if kwargs['symlink']:
assert doc == "{}'s option link".format(expected_name) # assert doc == "{}'s option link".format(expected_name)
else: # else:
assert doc == "{}'s option".format(expected_name) # assert doc == "{}'s option".format(expected_name)
@autocheck @autocheck
@ -1336,6 +1311,12 @@ def check_all(cfg, paths, path, meta, multi, default, default_multi, require, co
weakrefs.append(weakref.ref(cfg)) weakrefs.append(weakref.ref(cfg))
api = getapi(ncfg) api = getapi(ncfg)
ckwargs = copy(kwargs) ckwargs = copy(kwargs)
if meta:
api.owner.set('meta')
ckwargs['owner'] = owners.meta
else:
ckwargs['owner'] = OWNER
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'
@ -1469,6 +1450,8 @@ def make_conf(options, meta, multi, default, default_multi, require, consistency
if in_master and symlink: if in_master and symlink:
return None, None, None return None, None, None
if option_infos is not None: if option_infos is not None:
if require:
return None, None, None
for prop in PROPERTIES: for prop in PROPERTIES:
if option_infos.get(prop, False) is True: if option_infos.get(prop, False) is True:
if not require: if not require:
@ -1537,7 +1520,7 @@ def make_conf(options, meta, multi, default, default_multi, require, consistency
gopt = goptions[1] gopt = goptions[1]
else: else:
gopt = goptions[0] gopt = goptions[0]
obj.impl_add_consistency('not_equal', gopt, warnings_only=True) obj.impl_add_consistency('not_equal', gopt, warnings_only=True, transitive=False)
return obj, objcall, sobj return obj, objcall, sobj
def make_optiondescriptions(path, collected): def make_optiondescriptions(path, collected):
@ -1643,63 +1626,63 @@ def make_conf(options, meta, multi, default, default_multi, require, consistency
DICT_PATHS = [ DICT_PATHS = [
#test a config without optiondescription ##test a config without optiondescription
OrderedDict([('first', {}), #OrderedDict([('first', {}),
('second', {'second': {'disabled': True}}), # ('second', {'second': {'disabled': True}}),
('third', {'third': {'hidden': True}}) # ('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 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}}),
('odmaster.third', {'odmaster': {'master': True}, 'third': {'hidden': True, 'slave': True}})]), # ('odmaster.third', {'odmaster': {'master': True}, 'third': {'hidden': True, 'slave': True}})]),
#test a config with dynoption ##test a config with dynoption
OrderedDict([('subod.first', {'subod': {'dyn': True}}), #OrderedDict([('subod.first', {'subod': {'dyn': True}}),
('subod.second', {'second': {'disabled': True}}), # ('subod.second', {'second': {'disabled': True}}),
('subod.third', {'third': {'hidden': True}}), # ('subod.third', {'third': {'hidden': True}}),
('subodval1.firstval1', None), # ('subodval1.firstval1', None),
('subodval1.secondval1', None), # ('subodval1.secondval1', None),
('subodval1.thirdval1', None), # ('subodval1.thirdval1', None),
('subodval2.firstval2', None), # ('subodval2.firstval2', None),
('subodval2.secondval2', None), # ('subodval2.secondval2', None),
('subodval2.thirdval2', None)]), # ('subodval2.thirdval2', None)]),
#test a config with dynoption subdir ##test a config with dynoption subdir
OrderedDict([('subod.subsubod.first', {'subsubod': {'dyn': True}}), #OrderedDict([('subod.subsubod.first', {'subsubod': {'dyn': True}}),
('subod.subsubod.second', {'subsubod': {'dyn': True}, 'second': {'disabled': True}}), # ('subod.subsubod.second', {'subsubod': {'dyn': True}, 'second': {'disabled': True}}),
('subod.subsubod.third', {'subsubod': {'dyn': True}, 'third': {'hidden': True}}), # ('subod.subsubod.third', {'subsubod': {'dyn': True}, 'third': {'hidden': True}}),
('subod.subsubodval1.firstval1', None), # ('subod.subsubodval1.firstval1', None),
('subod.subsubodval1.secondval1', None), # ('subod.subsubodval1.secondval1', None),
('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 hidden subsubod ##test a config with hidden subsubod
OrderedDict([('subod.subsubod.first', {'subsubod': {'hidden': True}}), OrderedDict([('subod.subsubod.first', {'subsubod': {'hidden': True}}),
('subod.subsubod.second', {'subsubod': {'hidden': True}}), ('subod.subsubod.second', {'subsubod': {'hidden': True}}),
('subod.subsubod.third', {'subsubod': {'hidden': True}})]), ('subod.subsubod.third', {'subsubod': {'hidden': True}})]),
#test a config with hidden dyn subsubod ##test a config with hidden dyn subsubod
OrderedDict([('subod.subsubod.first', {'subsubod': {'dyn': True, 'hidden': True}}), #OrderedDict([('subod.subsubod.first', {'subsubod': {'dyn': True, 'hidden': True}}),
('subod.subsubod.second', {'subsubod': {'dyn': True, 'hidden': True}}), # ('subod.subsubod.second', {'subsubod': {'dyn': True, 'hidden': True}}),
('subod.subsubod.third', {'subsubod': {'dyn': True, 'hidden': True}}), # ('subod.subsubod.third', {'subsubod': {'dyn': True, 'hidden': True}}),
('subod.subsubodval1.firstval1', None), # ('subod.subsubodval1.firstval1', None),
('subod.subsubodval1.secondval1', None), # ('subod.subsubodval1.secondval1', None),
('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 ##test a config with dyn subsubod with masterslave
OrderedDict([('subod.subsubod.first', {'subod': {'dyn': True}, 'subsubod': {'master': True}}), #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.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}}), # ('subod.subsubod.third', {'subod': {'dyn': True}, 'subsubod': {'master': True}, 'third': {'hidden': True, 'slave': True}}),
('subodval1.subsubodval1.firstval1', None), # ('subodval1.subsubodval1.firstval1', None),
('subodval1.subsubodval1.secondval1', None), # ('subodval1.subsubodval1.secondval1', None),
('subodval1.subsubodval1.thirdval1', None), # ('subodval1.subsubodval1.thirdval1', None),
('subodval2.subsubodval2.firstval2', None), # ('subodval2.subsubodval2.firstval2', None),
('subodval2.subsubodval2.secondval2', None), # ('subodval2.subsubodval2.secondval2', None),
('subodval2.subsubodval2.thirdval2', None)]), # ('subodval2.subsubodval2.thirdval2', None)]),
] ]
@ -1734,16 +1717,27 @@ def test_options(paths):
return kwargs return kwargs
lpaths = list(paths.keys()) lpaths = list(paths.keys())
for meta in (False, True):
for callback in (False, True): # for meta in (False, True):
for consistency in (False, True): # for callback in (False, True):
for require in (False, True): # for consistency in (False, True):
for default_multi in (False, True): # for require in (False, True):
for symlink in (False, True): # for default_multi in (False, True):
# for symlink in (False, True):
# if callback and default_multi:
# continue
# for default in (False, True):
# for multi in (False, True, submulti):
for meta in (False,):
for callback in (False,):
for consistency in (False,):
for require in (False,):
for default_multi in (False,):
for symlink in (False,):
if callback and default_multi: if callback and default_multi:
continue continue
for default in (False, True): for default in (False,):
for multi in (False, True, submulti): for multi in (False,):
if multi is submulti and default: if multi is submulti and default:
continue continue
if multi is submulti and consistency: if multi is submulti and consistency:

View file

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# ____________________________________________________________ # ____________________________________________________________
from inspect import ismethod, getdoc from inspect import ismethod, getdoc
from .error import APIError, PropertiesOptionError, ConfigError from .error import APIError, ConfigError, SlaveError
from .i18n import _ from .i18n import _
from .setting import ConfigBag, owners, undefined from .setting import ConfigBag, owners, undefined
from .option import ChoiceOption from .option import ChoiceOption
@ -90,6 +90,12 @@ class CommonTiramisu(object):
self.config_bag, self.config_bag,
self.subconfig) self.subconfig)
self.config_bag.option = option self.config_bag.option = option
if self.index is not None and option.impl_is_master_slaves('slave') and \
self.index >= self.subconfig.cfgimpl_get_length():
raise SlaveError(_('index "{}" is higher than the master length "{}" '
'for option "{}"').format(self.index,
self.subconfig.cfgimpl_get_length(),
option.impl_get_display_name()))
if not self.allow_optiondescription and option.impl_is_optiondescription(): if not self.allow_optiondescription and option.impl_is_optiondescription():
raise APIError(_('option must not be an optiondescription')) raise APIError(_('option must not be an optiondescription'))
return option return option
@ -115,7 +121,7 @@ class CommonTiramisuOption(CommonTiramisu):
self.subconfig = subconfig self.subconfig = subconfig
if self.slave_need_index: if self.slave_need_index:
self._test_slave_index() self._test_slave_index()
if not self.allow_unrestraint: if not self.allow_unrestraint and self.config_bag.force_unrestraint:
self._unrestraint_not_allowed(self.config_bag.force_unrestraint) self._unrestraint_not_allowed(self.config_bag.force_unrestraint)
def _test_slave_index(self): def _test_slave_index(self):
@ -127,9 +133,8 @@ class CommonTiramisuOption(CommonTiramisu):
raise APIError('index must be set only with a slave option') raise APIError('index must be set only with a slave option')
def _unrestraint_not_allowed(self, force_unrestraint): def _unrestraint_not_allowed(self, force_unrestraint):
if force_unrestraint: name = self.__class__.__name__[14:].lower()
name = self.__class__.__name__[14:].lower() raise APIError(_('{} cannot be unrestraint').format(name))
raise APIError(_('{} cannot be unrestraint').format(name))
def __getattr__(self, name): def __getattr__(self, name):
if name == 'help': if name == 'help':
@ -138,7 +143,7 @@ class CommonTiramisuOption(CommonTiramisu):
if not hasattr(CommonTiramisuOption, name): if not hasattr(CommonTiramisuOption, name):
raise APIError(_('unknown method {}').format(name)) raise APIError(_('unknown method {}').format(name))
else: else:
super(CommonTiramisuOption, self).__getattribute__(name) super().__getattribute__(name)
def _help(self): def _help(self):
txt = [] txt = []
@ -240,7 +245,6 @@ class TiramisuOptionOption(CommonTiramisuOption):
class TiramisuOptionOwner(CommonTiramisuOption): class TiramisuOptionOwner(CommonTiramisuOption):
"""manager option's owner""" """manager option's owner"""
allow_unrestraint = True
def __init__(self, def __init__(self,
name, name,
@ -249,17 +253,17 @@ class TiramisuOptionOwner(CommonTiramisuOption):
subconfig, subconfig,
config_bag): config_bag):
super(TiramisuOptionOwner, self).__init__(name, super().__init__(name,
path, path,
index, index,
subconfig, subconfig,
config_bag) config_bag)
self.values = self.config_bag.config.cfgimpl_get_values() self.values = self.config_bag.config.cfgimpl_get_values()
@count @count
def get(self): def get(self):
"""get owner for a specified option""" """get owner for a specified option"""
self._get_option() option = self._get_option()
return self.values.getowner(self.path, return self.values.getowner(self.path,
self.index, self.index,
self.config_bag) self.config_bag)
@ -302,11 +306,11 @@ class TiramisuOptionProperty(CommonTiramisuOption):
index, index,
subconfig, subconfig,
config_bag): config_bag):
super(TiramisuOptionProperty, self).__init__(name, super().__init__(name,
path, path,
index, index,
subconfig, subconfig,
config_bag) config_bag)
self.settings = config_bag.config.cfgimpl_get_settings() self.settings = config_bag.config.cfgimpl_get_settings()
@count @count
@ -358,11 +362,11 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
index, index,
subconfig, subconfig,
config_bag): config_bag):
super(TiramisuOptionPermissive, self).__init__(name, super().__init__(name,
path, path,
index, index,
subconfig, subconfig,
config_bag) config_bag)
self.settings = config_bag.config.cfgimpl_get_settings() self.settings = config_bag.config.cfgimpl_get_settings()
@count @count
@ -469,6 +473,10 @@ class TiramisuOptionValue(CommonTiramisuOption):
def _len(self): def _len(self):
self._get_option() self._get_option()
subconfig_path = self.path.rsplit('.', 1)[0] subconfig_path = self.path.rsplit('.', 1)[0]
if self.config_bag.setting_properties is not None:
self.config_bag.config.cfgimpl_get_settings().validate_properties(self.path,
self.index,
self.config_bag)
config_bag = self.config_bag.copy('nooption') config_bag = self.config_bag.copy('nooption')
subconfig = config_bag.config.getattr(subconfig_path, subconfig = config_bag.config.getattr(subconfig_path,
None, None,
@ -726,9 +734,12 @@ class TiramisuContextOption(TiramisuContext):
@count @count
def get(self, path): def get(self, path):
config_bag = self.config_bag.copy()
config_bag.validate = False
config_bag.force_unrestraint = True
config_bag.setting_properties = None
return self.config_bag.config.unwrap_from_path(path, return self.config_bag.config.unwrap_from_path(path,
None, config_bag)
self.config_bag)
@count @count
def make_dict(self, def make_dict(self,
@ -782,8 +793,6 @@ class TiramisuDispatcherOption(TiramisuContextOption):
return self return self
config_bag = self.config_bag.copy() config_bag = self.config_bag.copy()
validate = not config_bag.force_unrestraint validate = not config_bag.force_unrestraint
#config_bag.validate = validate
#config_bag.validate_properties = validate
if not validate: if not validate:
config_bag.setting_properties = None config_bag.setting_properties = None
subconfig, name = config_bag.config.cfgimpl_get_home_by_path(path, subconfig, name = config_bag.config.cfgimpl_get_home_by_path(path,

View file

@ -570,7 +570,6 @@ class SubConfig(object):
if config_bag.validate_properties: if config_bag.validate_properties:
try: try:
self.unwrap_from_path(path, self.unwrap_from_path(path,
None,
config_bag) config_bag)
self.cfgimpl_get_settings().validate_properties(path, self.cfgimpl_get_settings().validate_properties(path,
None, None,
@ -662,7 +661,6 @@ class SubConfig(object):
config_bag=config_bag): config_bag=config_bag):
path = '.'.join(path.split('.')[:-1]) path = '.'.join(path.split('.')[:-1])
opt = context.unwrap_from_path(path, opt = context.unwrap_from_path(path,
None,
config_bag) config_bag)
sconfig_bag = config_bag.copy('nooption') sconfig_bag = config_bag.copy('nooption')
sconfig_bag.option = opt sconfig_bag.option = opt
@ -779,7 +777,6 @@ class _CommonConfig(SubConfig):
def unwrap_from_path(self, def unwrap_from_path(self,
path, path,
index,
config_bag): config_bag):
"""convenience method to extract and Option() object from the Config() """convenience method to extract and Option() object from the Config()
and it is **fast**: finds the option directly in the appropriate and it is **fast**: finds the option directly in the appropriate
@ -805,17 +802,6 @@ class _CommonConfig(SubConfig):
else: else:
true_path = path true_path = path
config_bag.option = option config_bag.option = option
#if not option.impl_is_optiondescription() and index is None and \
# config_bag.option.impl_is_master_slaves('slave'):
# subpath = self._get_subpath(true_path)
# self.cfgimpl_get_settings().validate_properties(subpath,
# index,
# config_bag)
# return option
#self.getattr(path,
# index,
# config_bag,
# returns_option=True)
return option return option
def cfgimpl_get_path(self, dyn=True): def cfgimpl_get_path(self, dyn=True):

View file

@ -326,7 +326,9 @@ class Values(object):
context = self._getcontext() context = self._getcontext()
owner = context.cfgimpl_get_settings().getowner() owner = context.cfgimpl_get_settings().getowner()
if 'validator' in config_bag.setting_properties and config_bag.validate: if config_bag.setting_properties is not None and \
'validator' in config_bag.setting_properties and \
config_bag.validate:
if index is not None or config_bag.option._has_consistencies(context): if index is not None or config_bag.option._has_consistencies(context):
# set value to a fake config when option has dependency # set value to a fake config when option has dependency
# validation will be complet in this case (consistency, ...) # validation will be complet in this case (consistency, ...)
@ -490,11 +492,16 @@ class Values(object):
config_bag.option = opt config_bag.option = opt
path = opt.impl_getpath(context) path = opt.impl_getpath(context)
self_properties = config_bag.properties self_properties = config_bag.properties
settings = context.cfgimpl_get_settings()
if self_properties is None: if self_properties is None:
self_properties = context.cfgimpl_get_settings().getproperties(path, self_properties = settings.getproperties(path,
index, index,
config_bag) config_bag)
config_bag.properties = self_properties config_bag.properties = self_properties
if config_bag.setting_properties is not None:
settings.validate_properties(path,
index,
config_bag)
if 'frozen' in self_properties and 'force_default_on_freeze' in self_properties: if 'frozen' in self_properties and 'force_default_on_freeze' in self_properties:
return owners.default return owners.default
if only_default: if only_default: