2017-10-22 09:48:08 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright (C) 2017 Team tiramisu (see AUTHORS for all contributors)
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
# Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
# option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# ____________________________________________________________
|
|
|
|
from inspect import ismethod, getdoc
|
2017-11-13 22:45:53 +01:00
|
|
|
from .error import APIError, PropertiesOptionError
|
2017-10-22 09:48:08 +02:00
|
|
|
from .i18n import _
|
|
|
|
from .setting import owners, undefined
|
2017-11-05 15:40:27 +01:00
|
|
|
try:
|
|
|
|
from .value import Multi
|
|
|
|
except:
|
|
|
|
Multi = list
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
class CommonTiramisuOption(object):
|
2017-10-22 09:48:08 +02:00
|
|
|
icon = '\u2937'
|
|
|
|
tmpl_help = u' {} {}: {}'
|
2017-10-25 08:46:22 +02:00
|
|
|
allow_unrestraint = False
|
2017-11-05 15:40:27 +01:00
|
|
|
slave_need_index = True
|
|
|
|
|
|
|
|
def __init__(self,
|
|
|
|
opt,
|
|
|
|
path,
|
|
|
|
index,
|
|
|
|
config,
|
2017-11-12 20:11:56 +01:00
|
|
|
setting_properties,
|
2017-11-05 15:40:27 +01:00
|
|
|
force_permissive,
|
|
|
|
force_unrestraint):
|
|
|
|
self.opt = opt
|
|
|
|
self.path = path
|
|
|
|
self.index = index
|
|
|
|
if self.slave_need_index:
|
|
|
|
self._test_slave_index()
|
|
|
|
self.config = config
|
2017-11-12 20:11:56 +01:00
|
|
|
self.setting_properties = setting_properties
|
2017-11-05 15:40:27 +01:00
|
|
|
self.force_permissive = force_permissive
|
|
|
|
self.force_unrestraint = force_unrestraint
|
2017-10-25 08:46:22 +02:00
|
|
|
if not self.allow_unrestraint:
|
|
|
|
self._unrestraint_not_allowed(force_unrestraint)
|
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def _test_slave_index(self):
|
|
|
|
if self.index is None and self.opt.impl_is_master_slaves('slave'):
|
|
|
|
raise APIError('index must be set with a slave option')
|
|
|
|
|
2017-10-25 08:46:22 +02:00
|
|
|
def _unrestraint_not_allowed(self, force_unrestraint):
|
|
|
|
if force_unrestraint:
|
2017-11-05 15:40:27 +01:00
|
|
|
name = self.__class__.__name__[14:].lower()
|
2017-10-25 08:46:22 +02:00
|
|
|
raise APIError(_('{} cannot be unrestraint').format(name))
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
def __getattr__(self, name):
|
|
|
|
if name == 'help':
|
|
|
|
return self._help()
|
|
|
|
else:
|
2017-11-16 21:30:07 +01:00
|
|
|
if not hasattr(CommonTiramisuOption, name):
|
2017-10-22 09:48:08 +02:00
|
|
|
raise APIError(_('unknown method {}').format(name))
|
|
|
|
else:
|
2017-11-16 21:30:07 +01:00
|
|
|
super(CommonTiramisuOption, self).__getattribute__(name)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
def _help(self):
|
|
|
|
txt = []
|
|
|
|
for func_name in dir(self):
|
|
|
|
if not func_name.startswith('_'):
|
|
|
|
func = getattr(self, func_name)
|
|
|
|
if ismethod(func):
|
|
|
|
txt.append(self.tmpl_help.format(self.icon, func_name, getdoc(func)))
|
|
|
|
return '\n'.join(txt)
|
|
|
|
|
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
class TiramisuOptionOption(CommonTiramisuOption):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""get information from an option"""
|
2017-10-25 08:46:22 +02:00
|
|
|
allow_unrestraint = True
|
2017-11-05 15:40:27 +01:00
|
|
|
slave_need_index = False
|
|
|
|
|
2017-11-12 20:11:56 +01:00
|
|
|
def __init__(self,
|
|
|
|
opt,
|
|
|
|
path,
|
|
|
|
index,
|
|
|
|
config,
|
|
|
|
setting_properties,
|
|
|
|
force_permissive,
|
|
|
|
force_unrestraint):
|
2017-11-05 15:40:27 +01:00
|
|
|
super(TiramisuOptionOption, self).__init__(opt,
|
|
|
|
path,
|
|
|
|
index,
|
|
|
|
config,
|
2017-11-12 20:11:56 +01:00
|
|
|
setting_properties,
|
2017-11-05 15:40:27 +01:00
|
|
|
force_permissive,
|
|
|
|
force_unrestraint)
|
2017-10-22 09:48:08 +02:00
|
|
|
if config:
|
|
|
|
self.values = self.config.cfgimpl_get_values()
|
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def ismulti(self):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""test if option could have multi value"""
|
2017-11-05 15:40:27 +01:00
|
|
|
return self.opt.impl_is_multi()
|
2017-11-16 21:30:07 +01:00
|
|
|
|
|
|
|
def issubmulti(self):
|
|
|
|
"""test if option could have submulti value"""
|
|
|
|
return self.opt.impl_is_submulti()
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def ismasterslaves(self):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""test if option is a master or a slave"""
|
2017-11-05 15:40:27 +01:00
|
|
|
return self.opt.impl_is_master_slaves()
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def ismaster(self):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""test if option is a master"""
|
2017-11-05 15:40:27 +01:00
|
|
|
return self.opt.impl_is_master_slaves('master')
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def isslave(self):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""test if option is a slave"""
|
2017-11-05 15:40:27 +01:00
|
|
|
return self.opt.impl_is_master_slaves('slave')
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def getname(self):
|
|
|
|
return self.opt.impl_getname()
|
2017-10-25 08:46:22 +02:00
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def getdoc(self):
|
|
|
|
return self.opt.impl_get_display_name()
|
2017-10-25 08:46:22 +02:00
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
def getdefault(self):
|
|
|
|
return self.opt.impl_getdefault()
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
def getdefaultmulti(self):
|
|
|
|
return self.opt.impl_getdefault_multi()
|
|
|
|
|
|
|
|
|
|
|
|
class TiramisuOptionOwner(CommonTiramisuOption):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""manager option's owner"""
|
|
|
|
|
2017-11-12 20:11:56 +01:00
|
|
|
def __init__(self,
|
|
|
|
opt,
|
|
|
|
path,
|
|
|
|
index,
|
|
|
|
config,
|
|
|
|
setting_properties,
|
|
|
|
force_permissive,
|
|
|
|
force_unrestraint):
|
2017-11-05 15:40:27 +01:00
|
|
|
super(TiramisuOptionOwner, self).__init__(opt,
|
|
|
|
path,
|
|
|
|
index,
|
|
|
|
config,
|
2017-11-12 20:11:56 +01:00
|
|
|
setting_properties,
|
2017-11-05 15:40:27 +01:00
|
|
|
force_permissive,
|
|
|
|
force_unrestraint)
|
2017-10-22 09:48:08 +02:00
|
|
|
if config:
|
|
|
|
self.values = self.config.cfgimpl_get_values()
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
"""get owner for a specified option"""
|
2017-11-05 15:40:27 +01:00
|
|
|
return self.values.getowner(self.opt,
|
|
|
|
index=self.index,
|
|
|
|
force_permissive=self.force_permissive)
|
|
|
|
|
|
|
|
def isdefault(self):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""is option has defaut value"""
|
2017-11-05 15:40:27 +01:00
|
|
|
return self.values.is_default_owner(self.opt,
|
2017-11-12 20:11:56 +01:00
|
|
|
index=self.index,
|
2017-10-22 09:48:08 +02:00
|
|
|
force_permissive=self.force_permissive)
|
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def set(self, owner):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""get owner for a specified option"""
|
|
|
|
try:
|
|
|
|
obj_owner = getattr(owners, owner)
|
|
|
|
except AttributeError:
|
|
|
|
owners.addowner(owner)
|
|
|
|
obj_owner = getattr(owners, owner)
|
2017-11-05 15:40:27 +01:00
|
|
|
self.values.setowner(self.opt,
|
2017-10-22 09:48:08 +02:00
|
|
|
obj_owner,
|
2017-11-05 15:40:27 +01:00
|
|
|
self.index,
|
2017-10-22 09:48:08 +02:00
|
|
|
force_permissive=self.force_permissive)
|
|
|
|
|
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
class TiramisuOptionProperty(CommonTiramisuOption):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""manager option's property"""
|
2017-11-05 15:40:27 +01:00
|
|
|
#allow_unrestraint = True
|
|
|
|
slave_need_index = False
|
|
|
|
|
2017-11-12 20:11:56 +01:00
|
|
|
def __init__(self,
|
|
|
|
opt,
|
|
|
|
path,
|
|
|
|
index,
|
|
|
|
config,
|
|
|
|
setting_properties,
|
|
|
|
force_permissive,
|
|
|
|
force_unrestraint):
|
2017-11-05 15:40:27 +01:00
|
|
|
super(TiramisuOptionProperty, self).__init__(opt,
|
|
|
|
path,
|
|
|
|
index,
|
|
|
|
config,
|
2017-11-12 20:11:56 +01:00
|
|
|
setting_properties,
|
2017-11-05 15:40:27 +01:00
|
|
|
force_permissive,
|
|
|
|
force_unrestraint)
|
2017-10-22 09:48:08 +02:00
|
|
|
if config:
|
|
|
|
self.settings = config.cfgimpl_get_settings()
|
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def get(self):
|
|
|
|
self._test_slave_index()
|
2017-11-12 20:11:56 +01:00
|
|
|
return self.settings.getproperties(self.opt,
|
|
|
|
self.path,
|
|
|
|
index=self.index,
|
|
|
|
obj=False)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def set(self, properties):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""set properties for a specified option"""
|
|
|
|
self.settings.setproperties(set(properties),
|
2017-11-05 15:40:27 +01:00
|
|
|
self.opt,
|
|
|
|
self.path)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def reset(self):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""reset all personalised properties
|
|
|
|
"""
|
2017-11-05 15:40:27 +01:00
|
|
|
self.settings.reset(_path=self.path)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
class TiramisuOptionPermissive(CommonTiramisuOption):
|
2017-11-03 21:52:13 +01:00
|
|
|
"""manager option's property"""
|
2017-11-05 15:40:27 +01:00
|
|
|
allow_unrestraint = True
|
|
|
|
slave_need_index = False
|
|
|
|
|
2017-11-12 20:11:56 +01:00
|
|
|
def __init__(self,
|
|
|
|
opt,
|
|
|
|
path,
|
|
|
|
index,
|
|
|
|
config,
|
|
|
|
setting_properties,
|
|
|
|
force_permissive,
|
|
|
|
force_unrestraint):
|
2017-11-05 15:40:27 +01:00
|
|
|
super(TiramisuOptionPermissive, self).__init__(opt,
|
|
|
|
path,
|
|
|
|
index,
|
|
|
|
config,
|
2017-11-12 20:11:56 +01:00
|
|
|
setting_properties,
|
2017-11-05 15:40:27 +01:00
|
|
|
force_permissive,
|
|
|
|
force_unrestraint)
|
2017-11-03 21:52:13 +01:00
|
|
|
if config:
|
|
|
|
self.settings = config.cfgimpl_get_settings()
|
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def get(self):
|
2017-11-03 21:52:13 +01:00
|
|
|
"""get permissive value for a specified path"""
|
2017-11-12 20:11:56 +01:00
|
|
|
return self.settings.getpermissive(self.setting_properties, self.path)
|
2017-11-03 21:52:13 +01:00
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def set(self, permissive):
|
|
|
|
self.settings.setpermissive(permissive, opt=self.opt, path=self.path)
|
2017-11-03 21:52:13 +01:00
|
|
|
|
|
|
|
#def reset(self, path):
|
|
|
|
# """reset all personalised properties
|
|
|
|
# """
|
|
|
|
# self._get_obj_by_path(path)
|
|
|
|
# self.settings.reset(_path=path)
|
|
|
|
|
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
class TiramisuOptionValue(CommonTiramisuOption):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""manager option's value"""
|
2017-11-16 21:30:07 +01:00
|
|
|
slave_need_index = False
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-12 20:11:56 +01:00
|
|
|
def __init__(self,
|
|
|
|
opt,
|
|
|
|
path,
|
|
|
|
index,
|
|
|
|
config,
|
|
|
|
setting_properties,
|
|
|
|
force_permissive,
|
|
|
|
force_unrestraint):
|
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
super(TiramisuOptionValue, self).__init__(opt,
|
|
|
|
path,
|
|
|
|
index,
|
|
|
|
config,
|
2017-11-12 20:11:56 +01:00
|
|
|
setting_properties,
|
2017-11-05 15:40:27 +01:00
|
|
|
force_permissive,
|
|
|
|
force_unrestraint)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
def get(self):
|
2017-11-16 21:30:07 +01:00
|
|
|
self._test_slave_index()
|
2017-11-12 20:11:56 +01:00
|
|
|
settings = self.config.cfgimpl_get_settings()
|
2017-11-05 15:40:27 +01:00
|
|
|
value = self.config.getattr(self.path,
|
|
|
|
index=self.index,
|
2017-11-12 20:11:56 +01:00
|
|
|
setting_properties=self.setting_properties,
|
2017-10-22 09:48:08 +02:00
|
|
|
force_permissive=self.force_permissive)
|
2017-11-05 15:40:27 +01:00
|
|
|
if isinstance(value, Multi):
|
|
|
|
value = list(value)
|
|
|
|
return value
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def set(self, value):
|
|
|
|
"""set a value for a specified option"""
|
2017-11-16 21:30:07 +01:00
|
|
|
self._test_slave_index()
|
2017-11-05 15:40:27 +01:00
|
|
|
values = self.config.cfgimpl_get_values()
|
|
|
|
if isinstance(value, list):
|
|
|
|
while undefined in value:
|
|
|
|
idx = value.index(undefined)
|
2017-11-12 20:11:56 +01:00
|
|
|
value[idx] = values.getdefaultvalue(self.opt,
|
|
|
|
self.path,
|
|
|
|
idx)
|
2017-11-05 15:40:27 +01:00
|
|
|
else:
|
|
|
|
if value == undefined:
|
2017-11-12 20:11:56 +01:00
|
|
|
value = values.getdefaultvalue(self.opt,
|
|
|
|
self.path,
|
|
|
|
self.index)
|
2017-11-05 15:40:27 +01:00
|
|
|
self.config.setattr(self.path,
|
2017-10-22 09:48:08 +02:00
|
|
|
value,
|
2017-11-05 15:40:27 +01:00
|
|
|
index=self.index,
|
2017-10-22 09:48:08 +02:00
|
|
|
force_permissive=self.force_permissive)
|
|
|
|
|
2017-11-12 20:11:56 +01:00
|
|
|
def pop(self, index):
|
|
|
|
"""pop value for a specified master values
|
|
|
|
"""
|
2017-11-16 21:30:07 +01:00
|
|
|
self._test_slave_index()
|
|
|
|
#FIXME only for master
|
2017-11-12 20:11:56 +01:00
|
|
|
self.config.delattr(self.path,
|
|
|
|
index=index,
|
|
|
|
setting_properties=self.setting_properties,
|
|
|
|
force_permissive=self.force_permissive)
|
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def reset(self):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""reset value for a value"""
|
2017-11-16 21:30:07 +01:00
|
|
|
self._test_slave_index()
|
2017-11-12 20:11:56 +01:00
|
|
|
self.config.delattr(self.path,
|
|
|
|
index=self.index,
|
|
|
|
setting_properties=self.setting_properties,
|
|
|
|
force_permissive=self.force_permissive)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
def len(self):
|
|
|
|
#FIXME only for slave
|
|
|
|
subconfig_path = self.path.rsplit('.', 1)[0]
|
|
|
|
subconfig = self.config.getattr(subconfig_path,
|
|
|
|
setting_properties=self.setting_properties,
|
|
|
|
force_permissive=self.force_permissive)
|
|
|
|
return subconfig.cfgimpl_get_length()
|
|
|
|
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
class TiramisuOption(object):
|
2017-10-22 09:48:08 +02:00
|
|
|
icon = '\u2937'
|
|
|
|
tmpl_help = ' {} {}: {}'
|
|
|
|
|
2017-11-12 20:11:56 +01:00
|
|
|
def __init__(self,
|
|
|
|
opt,
|
|
|
|
path,
|
|
|
|
index,
|
|
|
|
config,
|
|
|
|
setting_properties,
|
|
|
|
force_permissive,
|
|
|
|
force_unrestraint):
|
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
self.opt = opt
|
|
|
|
self.path = path
|
|
|
|
self.index = index
|
2017-10-22 09:48:08 +02:00
|
|
|
self.config = config
|
2017-11-12 20:11:56 +01:00
|
|
|
self.setting_properties = setting_properties
|
2017-10-22 09:48:08 +02:00
|
|
|
self.force_permissive = force_permissive
|
2017-10-25 08:46:22 +02:00
|
|
|
self.force_unrestraint = force_unrestraint
|
2017-10-22 09:48:08 +02:00
|
|
|
self.registers = {}
|
|
|
|
self.prefix = self.__class__.__name__
|
|
|
|
for module_name in globals().keys():
|
|
|
|
if module_name != self.prefix and module_name.startswith(self.prefix):
|
|
|
|
module = globals()[module_name]
|
2017-11-05 15:40:27 +01:00
|
|
|
func_name = module_name[len(self.prefix):].lower()
|
2017-10-22 09:48:08 +02:00
|
|
|
self.registers[func_name] = module
|
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def _help(self):
|
|
|
|
txt = []
|
|
|
|
for module_name, module in self.registers.items():
|
|
|
|
module_doc = getdoc(module)
|
|
|
|
txt.append(self.tmpl_help.format(self.icon, module_name, module_doc))
|
|
|
|
txt.append(module(None, None).help)
|
|
|
|
return '\n'.join(txt)
|
|
|
|
|
2017-10-22 09:48:08 +02:00
|
|
|
def __getattr__(self, subfunc):
|
|
|
|
if subfunc in self.registers:
|
2017-11-05 15:40:27 +01:00
|
|
|
return self.registers[subfunc](self.opt,
|
|
|
|
self.path,
|
|
|
|
self.index,
|
|
|
|
self.config,
|
2017-11-12 20:11:56 +01:00
|
|
|
self.setting_properties,
|
2017-10-25 08:46:22 +02:00
|
|
|
self.force_permissive,
|
|
|
|
self.force_unrestraint)
|
2017-11-05 15:40:27 +01:00
|
|
|
elif subfunc == 'help':
|
|
|
|
return self._help()
|
|
|
|
else:
|
|
|
|
raise APIError(_('please specify a valid sub function'))
|
|
|
|
|
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
class TiramisuContext(object):
|
|
|
|
def __init__(self, config):
|
|
|
|
self.config = config
|
|
|
|
|
|
|
|
class TiramisuContextOwner(TiramisuContext):
|
|
|
|
def get(self):
|
|
|
|
return self.config.cfgimpl_get_settings().getowner()
|
|
|
|
|
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
class TiramisuAPI(object):
|
|
|
|
icon = '\u2937'
|
|
|
|
tmpl_help = ' {} {}: {}'
|
|
|
|
|
2017-11-12 20:11:56 +01:00
|
|
|
def __init__(self,
|
|
|
|
config,
|
|
|
|
force_permissive=False,
|
|
|
|
force_unrestraint=False):
|
2017-11-05 15:40:27 +01:00
|
|
|
self.config = config
|
|
|
|
self.force_permissive = force_permissive
|
|
|
|
self.force_unrestraint = force_unrestraint
|
2017-11-12 20:11:56 +01:00
|
|
|
settings = self.config.cfgimpl_get_settings()
|
2017-11-13 22:45:53 +01:00
|
|
|
# #FIXME ?
|
2017-11-05 15:40:27 +01:00
|
|
|
self.config.read_write()
|
2017-11-12 20:11:56 +01:00
|
|
|
settings.setpermissive(('hidden',))
|
2017-11-05 15:40:27 +01:00
|
|
|
#/FIXME ?
|
|
|
|
|
|
|
|
def option(self, path, index=None):
|
|
|
|
validate = not self.force_unrestraint
|
2017-11-12 20:11:56 +01:00
|
|
|
settings = self.config.cfgimpl_get_settings()
|
2017-11-16 21:30:07 +01:00
|
|
|
setting_properties = settings.get_context_properties()
|
2017-11-13 22:45:53 +01:00
|
|
|
if validate:
|
|
|
|
s_properties = setting_properties
|
|
|
|
else:
|
|
|
|
s_properties = None
|
2017-11-05 15:40:27 +01:00
|
|
|
opt = self.config.unwrap_from_path(path,
|
2017-11-13 22:45:53 +01:00
|
|
|
setting_properties=s_properties,
|
2017-11-05 15:40:27 +01:00
|
|
|
validate=validate,
|
|
|
|
validate_properties=validate,
|
|
|
|
force_permissive=self.force_permissive,
|
|
|
|
index=index)
|
|
|
|
if index is not None and not opt.impl_is_master_slaves('slave'):
|
|
|
|
raise APIError('index must be set only with a slave option')
|
|
|
|
return TiramisuOption(opt,
|
|
|
|
path,
|
|
|
|
index,
|
|
|
|
self.config,
|
2017-11-12 20:11:56 +01:00
|
|
|
setting_properties,
|
|
|
|
self.force_permissive,
|
|
|
|
self.force_unrestraint)
|
2017-11-05 15:40:27 +01:00
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
def __getattr__(self, subfunc):
|
|
|
|
if subfunc == 'forcepermissive':
|
2017-11-12 20:11:56 +01:00
|
|
|
return TiramisuAPI(self.config,
|
|
|
|
force_permissive=True,
|
|
|
|
force_unrestraint=self.force_unrestraint)
|
2017-10-25 08:46:22 +02:00
|
|
|
elif subfunc == 'unrestraint':
|
2017-11-12 20:11:56 +01:00
|
|
|
return TiramisuAPI(self.config,
|
|
|
|
force_permissive=self.force_permissive,
|
|
|
|
force_unrestraint=True)
|
2017-10-22 09:48:08 +02:00
|
|
|
elif subfunc == 'help':
|
|
|
|
return self._help()
|
2017-11-16 21:30:07 +01:00
|
|
|
elif subfunc == 'owner':
|
|
|
|
return TiramisuContextOwner(self.config)
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
|
|
|
raise APIError(_('please specify a valid sub function'))
|
|
|
|
|
|
|
|
def _help(self):
|
2017-11-03 21:52:13 +01:00
|
|
|
txt = ['[forcepermissive]']
|
2017-10-22 09:48:08 +02:00
|
|
|
for module_name, module in self.registers.items():
|
|
|
|
module_doc = getdoc(module)
|
|
|
|
txt.append(self.tmpl_help.format(self.icon, module_name, module_doc))
|
|
|
|
txt.append(module(None, None).help)
|
|
|
|
return '\n'.join(txt)
|
|
|
|
|
|
|
|
|
|
|
|
def getapi(config):
|
|
|
|
"""instanciate TiramisuAPI
|
|
|
|
|
|
|
|
:param config: Config object
|
|
|
|
:type descr: an instance of ``config.Config``
|
|
|
|
"""
|
|
|
|
return TiramisuAPI(config)
|