some adaptation for tiramisu-web

This commit is contained in:
Emmanuel Garette 2018-01-05 23:32:00 +01:00
parent 9f68d71a83
commit 050c3125fa
7 changed files with 103 additions and 64 deletions

View File

@ -83,7 +83,7 @@ def display_count():
class CommonTiramisu(object): class CommonTiramisu(object):
allow_optiondescription = True allow_optiondescription = True
def get_option(self): def _get_option(self):
option = self.config_bag.option option = self.config_bag.option
if option is None: if option is None:
option = self.subconfig.cfgimpl_get_description().impl_getchild(self.name, option = self.subconfig.cfgimpl_get_description().impl_getchild(self.name,
@ -119,7 +119,7 @@ class CommonTiramisuOption(CommonTiramisu):
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):
option = self.get_option() option = self._get_option()
if not option.impl_is_optiondescription() and self.index is None and \ if not option.impl_is_optiondescription() and self.index is None and \
option.impl_is_master_slaves('slave'): option.impl_is_master_slaves('slave'):
raise APIError('index must be set with a slave option') raise APIError('index must be set with a slave option')
@ -155,63 +155,96 @@ class TiramisuOptionOption(CommonTiramisuOption):
slave_need_index = False slave_need_index = False
@count @count
def ismulti(self): def get(self):
return self._get_option()
@count
def _ismulti(self):
"""test if option could have multi value""" """test if option could have multi value"""
option = self.get_option() option = self._get_option()
return option.impl_is_multi() return option.impl_is_multi()
@count @count
def issubmulti(self): def _issubmulti(self):
"""test if option could have submulti value""" """test if option could have submulti value"""
option = self.get_option() option = self._get_option()
return option.impl_is_submulti() return option.impl_is_submulti()
@count @count
def ismasterslaves(self): def ismasterslaves(self):
"""test if option is a master or a slave""" """test if option is a master or a slave"""
option = self.get_option() option = self._get_option()
return option.impl_is_master_slaves() return option.impl_is_master_slaves()
@count @count
def ismaster(self): def _ismaster(self):
"""test if option is a master""" """test if option is a master"""
option = self.get_option() option = self._get_option()
return option.impl_is_master_slaves('master') return option.impl_is_master_slaves('master')
@count @count
def isslave(self): def _isslave(self):
"""test if option is a slave""" """test if option is a slave"""
option = self.get_option() option = self._get_option()
return option.impl_is_master_slaves('slave') return option.impl_is_master_slaves('slave')
@count @count
def getname(self): def name(self):
option = self.get_option() option = self._get_option()
return option.impl_getname() return option.impl_getname()
@count @count
def getdoc(self): def doc(self):
option = self.get_option() option = self._get_option()
return option.impl_get_display_name() return option.impl_get_display_name()
@count @count
def default(self): def _default(self):
option = self.get_option() option = self._get_option()
return option.impl_getdefault() return option.impl_getdefault()
@count @count
def defaultmulti(self): def _defaultmulti(self):
option = self.get_option() option = self._get_option()
return option.impl_getdefault_multi() return option.impl_getdefault_multi()
@count @count
def has_dependency(self, self_is_dep=True): def has_dependency(self, self_is_dep=True):
option = self.get_option() option = self._get_option()
return option.impl_has_dependency(self_is_dep) return option.impl_has_dependency(self_is_dep)
@count
def _consistencies(self):
option = self._get_option()
return option.get_consistencies()
@count
def _callbacks(self):
option = self._get_option()
return option.impl_get_callback()
@count
def requires(self):
option = self._get_option()
return option.impl_getrequires()
def __getattr__(self, name):
if not self._get_option().impl_is_optiondescription() and name != 'get_option':
subkey = '_' + name
if subkey in dir(self):
func = getattr(self, subkey)
if callable(func):
return func
raise APIError(_('{} is unknown').format(name))
def isoptiondescription(self):
return self._get_option().impl_is_optiondescription()
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,
@ -230,7 +263,7 @@ class TiramisuOptionOwner(CommonTiramisuOption):
@count @count
def get(self): def get(self):
"""get owner for a specified option""" """get owner for a specified option"""
self.get_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)
@ -238,7 +271,7 @@ class TiramisuOptionOwner(CommonTiramisuOption):
@count @count
def isdefault(self): def isdefault(self):
"""is option has defaut value""" """is option has defaut value"""
self.get_option() self._get_option()
return self.values.is_default_owner(self.path, return self.values.is_default_owner(self.path,
self.index, self.index,
self.config_bag) self.config_bag)
@ -246,7 +279,7 @@ class TiramisuOptionOwner(CommonTiramisuOption):
@count @count
def set(self, owner): def set(self, owner):
"""get owner for a specified option""" """get owner for a specified option"""
self.get_option() self._get_option()
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
if owner in ['default', 'forced', 'meta']: if owner in ['default', 'forced', 'meta']:
raise ConfigError() raise ConfigError()
@ -263,7 +296,6 @@ class TiramisuOptionOwner(CommonTiramisuOption):
class TiramisuOptionProperty(CommonTiramisuOption): class TiramisuOptionProperty(CommonTiramisuOption):
"""manager option's property""" """manager option's property"""
#allow_unrestraint = True
allow_optiondescription = True allow_optiondescription = True
allow_unrestraint = True allow_unrestraint = True
slave_need_index = False slave_need_index = False
@ -283,7 +315,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
@count @count
def get(self): def get(self):
self.get_option() self._get_option()
self._test_slave_index() self._test_slave_index()
properties = self.settings.getproperties(self.path, properties = self.settings.getproperties(self.path,
self.index, self.index,
@ -295,14 +327,14 @@ class TiramisuOptionProperty(CommonTiramisuOption):
@count @count
def add(self, prop): def add(self, prop):
#FIXME not index !! #FIXME not index !!
self.get_option() self._get_option()
self.settings.addproperty(self.path, self.settings.addproperty(self.path,
prop, prop,
self.config_bag) self.config_bag)
@count @count
def pop(self, prop): def pop(self, prop):
self.get_option() self._get_option()
self.settings.popproperty(self.path, self.settings.popproperty(self.path,
prop, prop,
self.config_bag) self.config_bag)
@ -311,7 +343,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
def reset(self): def reset(self):
"""reset all personalised properties """reset all personalised properties
""" """
self.get_option() self._get_option()
self.settings.reset(opt=self.config_bag.option, self.settings.reset(opt=self.config_bag.option,
path=self.path) path=self.path)
@ -341,14 +373,14 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
args = [self.setting_properties, self.path] args = [self.setting_properties, self.path]
else: else:
args = [self.get_option(), self.path] args = [self._get_option(), self.path]
return self.settings.getpermissive(*args) return self.settings.getpermissive(*args)
@count @count
def set(self, permissives): def set(self, permissives):
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
permissive = tuple(permissives) permissive = tuple(permissives)
self.settings.setpermissive(opt=self.get_option(), self.settings.setpermissive(opt=self._get_option(),
path=self.path, path=self.path,
permissives=permissives) permissives=permissives)
@ -360,21 +392,23 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
class TiramisuOptionInformation(CommonTiramisuOption): class TiramisuOptionInformation(CommonTiramisuOption):
allow_unrestraint = True
allow_optiondescription = True allow_optiondescription = True
@count @count
def get(self, name, default=undefined): def get(self, name, default=undefined):
option = self.get_option() option = self._get_option()
return option.impl_get_information(name, default) return option.impl_get_information(name, default)
class TiramisuOptionValue(CommonTiramisuOption): class TiramisuOptionValue(CommonTiramisuOption):
"""manager option's value""" """manager option's value"""
slave_need_index = False slave_need_index = False
allow_unrestraint = True
@count @count
def get(self): def get(self):
self.get_option() self._get_option()
self._test_slave_index() self._test_slave_index()
settings = self.config_bag.config.cfgimpl_get_settings() settings = self.config_bag.config.cfgimpl_get_settings()
value = self.subconfig.getattr(self.name, value = self.subconfig.getattr(self.name,
@ -387,7 +421,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
@count @count
def set(self, value): def set(self, value):
"""set a value for a specified option""" """set a value for a specified option"""
self.get_option() self._get_option()
self._test_slave_index() self._test_slave_index()
values = self.config_bag.config.cfgimpl_get_values() values = self.config_bag.config.cfgimpl_get_values()
if isinstance(value, list): if isinstance(value, list):
@ -410,7 +444,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
def _pop(self, index): def _pop(self, index):
"""pop value for a specified master values """pop value for a specified master values
""" """
self.get_option() self._get_option()
self.config_bag.config.delattr(self.path, self.config_bag.config.delattr(self.path,
index, index,
self.config_bag) self.config_bag)
@ -418,7 +452,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
@count @count
def reset(self): def reset(self):
"""reset value for a value""" """reset value for a value"""
self.get_option() self._get_option()
self._test_slave_index() self._test_slave_index()
self.config_bag.config.delattr(self.path, self.config_bag.config.delattr(self.path,
self.index, self.index,
@ -426,7 +460,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
@count @count
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]
subconfig = self.config.getattr(subconfig_path, subconfig = self.config.getattr(subconfig_path,
None, None,
@ -434,11 +468,11 @@ class TiramisuOptionValue(CommonTiramisuOption):
return subconfig.cfgimpl_get_length() return subconfig.cfgimpl_get_length()
def __getattr__(self, name): def __getattr__(self, name):
if name == 'list' and isinstance(self.get_option(), ChoiceOption): if name == 'list' and isinstance(self._get_option(), ChoiceOption):
return self._list return self._list
elif name == 'pop' and self.get_option().impl_is_master_slaves('master'): elif name == 'pop' and self._get_option().impl_is_master_slaves('master'):
return self._pop return self._pop
elif name == 'len' and self.get_option().impl_is_master_slaves('slave'): elif name == 'len' and self._get_option().impl_is_master_slaves('slave'):
return self._len return self._len
raise APIError(_('{} is unknown').format(name)) raise APIError(_('{} is unknown').format(name))
@ -491,11 +525,11 @@ class TiramisuOption(CommonTiramisu):
self.config_bag) self.config_bag)
elif subfunc == 'help': elif subfunc == 'help':
return self._help() return self._help()
elif subfunc == 'make_dict' and self.get_option().impl_is_optiondescription(): elif subfunc == 'make_dict' and self._get_option().impl_is_optiondescription():
return self._make_dict return self._make_dict
elif subfunc == 'list' and self.get_option().impl_is_optiondescription(): elif subfunc == 'list' and self._get_option().impl_is_optiondescription():
return self._list return self._list
elif subfunc == 'group_type' and self.get_option().impl_is_optiondescription(): elif subfunc == 'group_type' and self._get_option().impl_is_optiondescription():
return self._group_type return self._group_type
else: else:
raise APIError(_('please specify a valid sub function ({})').format(subfunc)) raise APIError(_('please specify a valid sub function ({})').format(subfunc))
@ -516,7 +550,7 @@ class TiramisuOption(CommonTiramisu):
@count @count
def group_type(self): def group_type(self):
return self.get_option().impl_get_group_type() return self._get_option().impl_get_group_type()
@count @count
def _list(self, type='all', group_type=None): def _list(self, type='all', group_type=None):
@ -682,11 +716,11 @@ class TiramisuContextOption(TiramisuContext):
type_=type, type_=type,
config_bag=self.config_bag) config_bag=self.config_bag)
@count #@count
def get(self, path): #def get(self, path):
return self.config_bag.config.unwrap_from_path(path, # return self.config_bag.config.unwrap_from_path(path,
None, # None,
self.config_bag) # self.config_bag)
@count @count
def make_dict(self, def make_dict(self,
@ -732,6 +766,8 @@ class TiramisuDispatcherConfig(TiramisuContextConfig):
class TiramisuDispatcherOption(TiramisuContextOption): class TiramisuDispatcherOption(TiramisuContextOption):
def __call__(self, path, index=None): def __call__(self, path, index=None):
if path is None:
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 = validate

View File

@ -238,13 +238,14 @@ class SubConfig(object):
nconfig_bag.option = opt nconfig_bag.option = opt
name = opt.impl_getname() name = opt.impl_getname()
subpath = self._get_subpath(name) subpath = self._get_subpath(name)
if nconfig_bag.setting_properties is not None:
try: try:
context.cfgimpl_get_settings().validate_properties(subpath, context.cfgimpl_get_settings().validate_properties(subpath,
None, None,
nconfig_bag) nconfig_bag)
yield name
except PropertiesOptionError: except PropertiesOptionError:
pass continue
yield name
# ______________________________________________________________________ # ______________________________________________________________________

View File

@ -175,5 +175,5 @@ class MasterSlaves(OptionDescription):
raise SlaveError(_('cannot reduce length of the master "{}"' raise SlaveError(_('cannot reduce length of the master "{}"'
'').format(option.impl_get_display_name())) '').format(option.impl_get_display_name()))
def is_masterslaves(self): def impl_is_master_slaves(self):
return True return True

View File

@ -484,7 +484,7 @@ class Option(OnlyOption):
consistencies = descr._cache_consistencies.get(option) consistencies = descr._cache_consistencies.get(option)
else: else:
# is no context, get consistencies in option # is no context, get consistencies in option
consistencies = option._get_consistencies() consistencies = option.get_consistencies()
if consistencies is not None: if consistencies is not None:
for cons_id, func, all_cons_opts, params in consistencies: for cons_id, func, all_cons_opts, params in consistencies:
warnings_only = params.get('warnings_only', False) warnings_only = params.get('warnings_only', False)
@ -759,7 +759,7 @@ class Option(OnlyOption):
def _del_consistency(self): def _del_consistency(self):
self._consistencies.pop(-1) self._consistencies.pop(-1)
def _get_consistencies(self): def get_consistencies(self):
return getattr(self, '_consistencies', STATIC_TUPLE) return getattr(self, '_consistencies', STATIC_TUPLE)
def _has_consistencies(self, context): def _has_consistencies(self, context):

View File

@ -76,7 +76,7 @@ class CacheOptionDescription(BaseOption):
is_multi = option.impl_is_multi() is_multi = option.impl_is_multi()
if not option.impl_is_symlinkoption() and 'force_store_value' in option.impl_getproperties(): if not option.impl_is_symlinkoption() and 'force_store_value' in option.impl_getproperties():
force_store_values.append((subpath, option)) force_store_values.append((subpath, option))
for cons_id, func, all_cons_opts, params in option._get_consistencies(): for cons_id, func, all_cons_opts, params in option.get_consistencies():
option._valid_consistencies(all_cons_opts[1:], init=False) option._valid_consistencies(all_cons_opts[1:], init=False)
if func not in ALLOWED_CONST_LIST and is_multi: if func not in ALLOWED_CONST_LIST and is_multi:
is_masterslaves = option.impl_is_master_slaves() is_masterslaves = option.impl_is_master_slaves()
@ -473,7 +473,7 @@ 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): def impl_is_master_slaves(self):
return False return False
def impl_getdoc(self): def impl_getdoc(self):

View File

@ -42,7 +42,8 @@ class SymLinkOption(OnlyOption):
name): name):
return getattr(self._opt, name) return getattr(self._opt, name)
def impl_has_dependency(self, self_is_dep=True): def impl_has_dependency(self,
self_is_dep=True):
"""If self_is_dep is True, it has dependency (self._opt), so return True """If self_is_dep is True, it has dependency (self._opt), so return True
if self_is_dep is False, cannot has validation or callback, so return False if self_is_dep is False, cannot has validation or callback, so return False
""" """
@ -78,10 +79,11 @@ class SymLinkOption(OnlyOption):
#def _is_subdyn(self): #def _is_subdyn(self):
# return getattr(self._opt, '_subdyn', None) is not None # return getattr(self._opt, '_subdyn', None) is not None
def _get_consistencies(self): def get_consistencies(self):
return () return ()
def _has_consistencies(self, context): def _has_consistencies(self,
context):
return option._opt._has_consistencies(context) return option._opt._has_consistencies(context)

View File

@ -705,7 +705,7 @@ class Values(object):
config_bag.force_permissive = True config_bag.force_permissive = True
config_bag.display_warnings = False config_bag.display_warnings = False
def _mandatory_warnings(description, currpath, config): def _mandatory_warnings(description, currpath, config):
is_masterslaves = description.is_masterslaves() is_masterslaves = description.impl_is_master_slaves()
lenmaster = None lenmaster = None
optmaster = None optmaster = None
pathmaster = None pathmaster = None