some adaptation for tiramisu-web
This commit is contained in:
parent
9f68d71a83
commit
050c3125fa
132
tiramisu/api.py
132
tiramisu/api.py
@ -83,7 +83,7 @@ def display_count():
|
||||
class CommonTiramisu(object):
|
||||
allow_optiondescription = True
|
||||
|
||||
def get_option(self):
|
||||
def _get_option(self):
|
||||
option = self.config_bag.option
|
||||
if option is None:
|
||||
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)
|
||||
|
||||
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 \
|
||||
option.impl_is_master_slaves('slave'):
|
||||
raise APIError('index must be set with a slave option')
|
||||
@ -155,63 +155,96 @@ class TiramisuOptionOption(CommonTiramisuOption):
|
||||
slave_need_index = False
|
||||
|
||||
@count
|
||||
def ismulti(self):
|
||||
def get(self):
|
||||
return self._get_option()
|
||||
|
||||
@count
|
||||
def _ismulti(self):
|
||||
"""test if option could have multi value"""
|
||||
option = self.get_option()
|
||||
option = self._get_option()
|
||||
return option.impl_is_multi()
|
||||
|
||||
@count
|
||||
def issubmulti(self):
|
||||
def _issubmulti(self):
|
||||
"""test if option could have submulti value"""
|
||||
option = self.get_option()
|
||||
option = self._get_option()
|
||||
return option.impl_is_submulti()
|
||||
|
||||
@count
|
||||
def ismasterslaves(self):
|
||||
"""test if option is a master or a slave"""
|
||||
option = self.get_option()
|
||||
option = self._get_option()
|
||||
return option.impl_is_master_slaves()
|
||||
|
||||
@count
|
||||
def ismaster(self):
|
||||
def _ismaster(self):
|
||||
"""test if option is a master"""
|
||||
option = self.get_option()
|
||||
option = self._get_option()
|
||||
return option.impl_is_master_slaves('master')
|
||||
|
||||
@count
|
||||
def isslave(self):
|
||||
def _isslave(self):
|
||||
"""test if option is a slave"""
|
||||
option = self.get_option()
|
||||
option = self._get_option()
|
||||
return option.impl_is_master_slaves('slave')
|
||||
|
||||
@count
|
||||
def getname(self):
|
||||
option = self.get_option()
|
||||
def name(self):
|
||||
option = self._get_option()
|
||||
return option.impl_getname()
|
||||
|
||||
@count
|
||||
def getdoc(self):
|
||||
option = self.get_option()
|
||||
def doc(self):
|
||||
option = self._get_option()
|
||||
return option.impl_get_display_name()
|
||||
|
||||
@count
|
||||
def default(self):
|
||||
option = self.get_option()
|
||||
def _default(self):
|
||||
option = self._get_option()
|
||||
return option.impl_getdefault()
|
||||
|
||||
@count
|
||||
def defaultmulti(self):
|
||||
option = self.get_option()
|
||||
def _defaultmulti(self):
|
||||
option = self._get_option()
|
||||
return option.impl_getdefault_multi()
|
||||
|
||||
@count
|
||||
def has_dependency(self, self_is_dep=True):
|
||||
option = self.get_option()
|
||||
option = self._get_option()
|
||||
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):
|
||||
"""manager option's owner"""
|
||||
allow_unrestraint = True
|
||||
|
||||
def __init__(self,
|
||||
name,
|
||||
@ -230,7 +263,7 @@ class TiramisuOptionOwner(CommonTiramisuOption):
|
||||
@count
|
||||
def get(self):
|
||||
"""get owner for a specified option"""
|
||||
self.get_option()
|
||||
self._get_option()
|
||||
return self.values.getowner(self.path,
|
||||
self.index,
|
||||
self.config_bag)
|
||||
@ -238,7 +271,7 @@ class TiramisuOptionOwner(CommonTiramisuOption):
|
||||
@count
|
||||
def isdefault(self):
|
||||
"""is option has defaut value"""
|
||||
self.get_option()
|
||||
self._get_option()
|
||||
return self.values.is_default_owner(self.path,
|
||||
self.index,
|
||||
self.config_bag)
|
||||
@ -246,7 +279,7 @@ class TiramisuOptionOwner(CommonTiramisuOption):
|
||||
@count
|
||||
def set(self, owner):
|
||||
"""get owner for a specified option"""
|
||||
self.get_option()
|
||||
self._get_option()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
if owner in ['default', 'forced', 'meta']:
|
||||
raise ConfigError()
|
||||
@ -263,7 +296,6 @@ class TiramisuOptionOwner(CommonTiramisuOption):
|
||||
|
||||
class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
"""manager option's property"""
|
||||
#allow_unrestraint = True
|
||||
allow_optiondescription = True
|
||||
allow_unrestraint = True
|
||||
slave_need_index = False
|
||||
@ -283,7 +315,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
|
||||
@count
|
||||
def get(self):
|
||||
self.get_option()
|
||||
self._get_option()
|
||||
self._test_slave_index()
|
||||
properties = self.settings.getproperties(self.path,
|
||||
self.index,
|
||||
@ -295,14 +327,14 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
@count
|
||||
def add(self, prop):
|
||||
#FIXME not index !!
|
||||
self.get_option()
|
||||
self._get_option()
|
||||
self.settings.addproperty(self.path,
|
||||
prop,
|
||||
self.config_bag)
|
||||
|
||||
@count
|
||||
def pop(self, prop):
|
||||
self.get_option()
|
||||
self._get_option()
|
||||
self.settings.popproperty(self.path,
|
||||
prop,
|
||||
self.config_bag)
|
||||
@ -311,7 +343,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
def reset(self):
|
||||
"""reset all personalised properties
|
||||
"""
|
||||
self.get_option()
|
||||
self._get_option()
|
||||
self.settings.reset(opt=self.config_bag.option,
|
||||
path=self.path)
|
||||
|
||||
@ -341,14 +373,14 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
|
||||
if TIRAMISU_VERSION == 2:
|
||||
args = [self.setting_properties, self.path]
|
||||
else:
|
||||
args = [self.get_option(), self.path]
|
||||
args = [self._get_option(), self.path]
|
||||
return self.settings.getpermissive(*args)
|
||||
|
||||
@count
|
||||
def set(self, permissives):
|
||||
if TIRAMISU_VERSION == 2:
|
||||
permissive = tuple(permissives)
|
||||
self.settings.setpermissive(opt=self.get_option(),
|
||||
self.settings.setpermissive(opt=self._get_option(),
|
||||
path=self.path,
|
||||
permissives=permissives)
|
||||
|
||||
@ -360,21 +392,23 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
|
||||
|
||||
|
||||
class TiramisuOptionInformation(CommonTiramisuOption):
|
||||
allow_unrestraint = True
|
||||
allow_optiondescription = True
|
||||
|
||||
@count
|
||||
def get(self, name, default=undefined):
|
||||
option = self.get_option()
|
||||
option = self._get_option()
|
||||
return option.impl_get_information(name, default)
|
||||
|
||||
|
||||
class TiramisuOptionValue(CommonTiramisuOption):
|
||||
"""manager option's value"""
|
||||
slave_need_index = False
|
||||
allow_unrestraint = True
|
||||
|
||||
@count
|
||||
def get(self):
|
||||
self.get_option()
|
||||
self._get_option()
|
||||
self._test_slave_index()
|
||||
settings = self.config_bag.config.cfgimpl_get_settings()
|
||||
value = self.subconfig.getattr(self.name,
|
||||
@ -387,7 +421,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
@count
|
||||
def set(self, value):
|
||||
"""set a value for a specified option"""
|
||||
self.get_option()
|
||||
self._get_option()
|
||||
self._test_slave_index()
|
||||
values = self.config_bag.config.cfgimpl_get_values()
|
||||
if isinstance(value, list):
|
||||
@ -410,7 +444,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
def _pop(self, index):
|
||||
"""pop value for a specified master values
|
||||
"""
|
||||
self.get_option()
|
||||
self._get_option()
|
||||
self.config_bag.config.delattr(self.path,
|
||||
index,
|
||||
self.config_bag)
|
||||
@ -418,7 +452,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
@count
|
||||
def reset(self):
|
||||
"""reset value for a value"""
|
||||
self.get_option()
|
||||
self._get_option()
|
||||
self._test_slave_index()
|
||||
self.config_bag.config.delattr(self.path,
|
||||
self.index,
|
||||
@ -426,7 +460,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
|
||||
@count
|
||||
def _len(self):
|
||||
self.get_option()
|
||||
self._get_option()
|
||||
subconfig_path = self.path.rsplit('.', 1)[0]
|
||||
subconfig = self.config.getattr(subconfig_path,
|
||||
None,
|
||||
@ -434,11 +468,11 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
return subconfig.cfgimpl_get_length()
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
raise APIError(_('{} is unknown').format(name))
|
||||
|
||||
@ -491,11 +525,11 @@ class TiramisuOption(CommonTiramisu):
|
||||
self.config_bag)
|
||||
elif subfunc == '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
|
||||
elif subfunc == 'list' and self.get_option().impl_is_optiondescription():
|
||||
elif subfunc == 'list' and self._get_option().impl_is_optiondescription():
|
||||
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
|
||||
else:
|
||||
raise APIError(_('please specify a valid sub function ({})').format(subfunc))
|
||||
@ -516,7 +550,7 @@ class TiramisuOption(CommonTiramisu):
|
||||
|
||||
@count
|
||||
def group_type(self):
|
||||
return self.get_option().impl_get_group_type()
|
||||
return self._get_option().impl_get_group_type()
|
||||
|
||||
@count
|
||||
def _list(self, type='all', group_type=None):
|
||||
@ -682,11 +716,11 @@ class TiramisuContextOption(TiramisuContext):
|
||||
type_=type,
|
||||
config_bag=self.config_bag)
|
||||
|
||||
@count
|
||||
def get(self, path):
|
||||
return self.config_bag.config.unwrap_from_path(path,
|
||||
None,
|
||||
self.config_bag)
|
||||
#@count
|
||||
#def get(self, path):
|
||||
# return self.config_bag.config.unwrap_from_path(path,
|
||||
# None,
|
||||
# self.config_bag)
|
||||
|
||||
@count
|
||||
def make_dict(self,
|
||||
@ -732,6 +766,8 @@ class TiramisuDispatcherConfig(TiramisuContextConfig):
|
||||
|
||||
class TiramisuDispatcherOption(TiramisuContextOption):
|
||||
def __call__(self, path, index=None):
|
||||
if path is None:
|
||||
return self
|
||||
config_bag = self.config_bag.copy()
|
||||
validate = not config_bag.force_unrestraint
|
||||
#config_bag.validate = validate
|
||||
|
@ -238,13 +238,14 @@ class SubConfig(object):
|
||||
nconfig_bag.option = opt
|
||||
name = opt.impl_getname()
|
||||
subpath = self._get_subpath(name)
|
||||
try:
|
||||
context.cfgimpl_get_settings().validate_properties(subpath,
|
||||
None,
|
||||
nconfig_bag)
|
||||
yield name
|
||||
except PropertiesOptionError:
|
||||
pass
|
||||
if nconfig_bag.setting_properties is not None:
|
||||
try:
|
||||
context.cfgimpl_get_settings().validate_properties(subpath,
|
||||
None,
|
||||
nconfig_bag)
|
||||
except PropertiesOptionError:
|
||||
continue
|
||||
yield name
|
||||
|
||||
# ______________________________________________________________________
|
||||
|
||||
|
@ -175,5 +175,5 @@ class MasterSlaves(OptionDescription):
|
||||
raise SlaveError(_('cannot reduce length of the master "{}"'
|
||||
'').format(option.impl_get_display_name()))
|
||||
|
||||
def is_masterslaves(self):
|
||||
def impl_is_master_slaves(self):
|
||||
return True
|
||||
|
@ -484,7 +484,7 @@ class Option(OnlyOption):
|
||||
consistencies = descr._cache_consistencies.get(option)
|
||||
else:
|
||||
# is no context, get consistencies in option
|
||||
consistencies = option._get_consistencies()
|
||||
consistencies = option.get_consistencies()
|
||||
if consistencies is not None:
|
||||
for cons_id, func, all_cons_opts, params in consistencies:
|
||||
warnings_only = params.get('warnings_only', False)
|
||||
@ -759,7 +759,7 @@ class Option(OnlyOption):
|
||||
def _del_consistency(self):
|
||||
self._consistencies.pop(-1)
|
||||
|
||||
def _get_consistencies(self):
|
||||
def get_consistencies(self):
|
||||
return getattr(self, '_consistencies', STATIC_TUPLE)
|
||||
|
||||
def _has_consistencies(self, context):
|
||||
|
@ -76,7 +76,7 @@ class CacheOptionDescription(BaseOption):
|
||||
is_multi = option.impl_is_multi()
|
||||
if not option.impl_is_symlinkoption() and 'force_store_value' in option.impl_getproperties():
|
||||
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)
|
||||
if func not in ALLOWED_CONST_LIST and is_multi:
|
||||
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
|
||||
self._group_type = groups.default
|
||||
|
||||
def is_masterslaves(self):
|
||||
def impl_is_master_slaves(self):
|
||||
return False
|
||||
|
||||
def impl_getdoc(self):
|
||||
|
@ -42,7 +42,8 @@ class SymLinkOption(OnlyOption):
|
||||
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 False, cannot has validation or callback, so return False
|
||||
"""
|
||||
@ -78,10 +79,11 @@ class SymLinkOption(OnlyOption):
|
||||
#def _is_subdyn(self):
|
||||
# return getattr(self._opt, '_subdyn', None) is not None
|
||||
|
||||
def _get_consistencies(self):
|
||||
def get_consistencies(self):
|
||||
return ()
|
||||
|
||||
def _has_consistencies(self, context):
|
||||
def _has_consistencies(self,
|
||||
context):
|
||||
return option._opt._has_consistencies(context)
|
||||
|
||||
|
||||
|
@ -705,7 +705,7 @@ class Values(object):
|
||||
config_bag.force_permissive = True
|
||||
config_bag.display_warnings = False
|
||||
def _mandatory_warnings(description, currpath, config):
|
||||
is_masterslaves = description.is_masterslaves()
|
||||
is_masterslaves = description.impl_is_master_slaves()
|
||||
lenmaster = None
|
||||
optmaster = None
|
||||
pathmaster = None
|
||||
|
Loading…
Reference in New Issue
Block a user