some corrections
This commit is contained in:
@ -15,7 +15,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ____________________________________________________________
|
||||
from inspect import ismethod, getdoc
|
||||
from .error import APIError, PropertiesOptionError, ConfigError
|
||||
from .error import APIError, ConfigError, SlaveError
|
||||
from .i18n import _
|
||||
from .setting import ConfigBag, owners, undefined
|
||||
from .option import ChoiceOption
|
||||
@ -90,6 +90,12 @@ class CommonTiramisu(object):
|
||||
self.config_bag,
|
||||
self.subconfig)
|
||||
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():
|
||||
raise APIError(_('option must not be an optiondescription'))
|
||||
return option
|
||||
@ -115,7 +121,7 @@ class CommonTiramisuOption(CommonTiramisu):
|
||||
self.subconfig = subconfig
|
||||
if self.slave_need_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)
|
||||
|
||||
def _test_slave_index(self):
|
||||
@ -127,9 +133,8 @@ class CommonTiramisuOption(CommonTiramisu):
|
||||
raise APIError('index must be set only with a slave option')
|
||||
|
||||
def _unrestraint_not_allowed(self, force_unrestraint):
|
||||
if force_unrestraint:
|
||||
name = self.__class__.__name__[14:].lower()
|
||||
raise APIError(_('{} cannot be unrestraint').format(name))
|
||||
name = self.__class__.__name__[14:].lower()
|
||||
raise APIError(_('{} cannot be unrestraint').format(name))
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name == 'help':
|
||||
@ -138,7 +143,7 @@ class CommonTiramisuOption(CommonTiramisu):
|
||||
if not hasattr(CommonTiramisuOption, name):
|
||||
raise APIError(_('unknown method {}').format(name))
|
||||
else:
|
||||
super(CommonTiramisuOption, self).__getattribute__(name)
|
||||
super().__getattribute__(name)
|
||||
|
||||
def _help(self):
|
||||
txt = []
|
||||
@ -240,7 +245,6 @@ class TiramisuOptionOption(CommonTiramisuOption):
|
||||
|
||||
class TiramisuOptionOwner(CommonTiramisuOption):
|
||||
"""manager option's owner"""
|
||||
allow_unrestraint = True
|
||||
|
||||
def __init__(self,
|
||||
name,
|
||||
@ -249,17 +253,17 @@ class TiramisuOptionOwner(CommonTiramisuOption):
|
||||
subconfig,
|
||||
config_bag):
|
||||
|
||||
super(TiramisuOptionOwner, self).__init__(name,
|
||||
path,
|
||||
index,
|
||||
subconfig,
|
||||
config_bag)
|
||||
super().__init__(name,
|
||||
path,
|
||||
index,
|
||||
subconfig,
|
||||
config_bag)
|
||||
self.values = self.config_bag.config.cfgimpl_get_values()
|
||||
|
||||
@count
|
||||
def get(self):
|
||||
"""get owner for a specified option"""
|
||||
self._get_option()
|
||||
option = self._get_option()
|
||||
return self.values.getowner(self.path,
|
||||
self.index,
|
||||
self.config_bag)
|
||||
@ -302,11 +306,11 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
index,
|
||||
subconfig,
|
||||
config_bag):
|
||||
super(TiramisuOptionProperty, self).__init__(name,
|
||||
path,
|
||||
index,
|
||||
subconfig,
|
||||
config_bag)
|
||||
super().__init__(name,
|
||||
path,
|
||||
index,
|
||||
subconfig,
|
||||
config_bag)
|
||||
self.settings = config_bag.config.cfgimpl_get_settings()
|
||||
|
||||
@count
|
||||
@ -358,11 +362,11 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
|
||||
index,
|
||||
subconfig,
|
||||
config_bag):
|
||||
super(TiramisuOptionPermissive, self).__init__(name,
|
||||
path,
|
||||
index,
|
||||
subconfig,
|
||||
config_bag)
|
||||
super().__init__(name,
|
||||
path,
|
||||
index,
|
||||
subconfig,
|
||||
config_bag)
|
||||
self.settings = config_bag.config.cfgimpl_get_settings()
|
||||
|
||||
@count
|
||||
@ -469,6 +473,10 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
def _len(self):
|
||||
self._get_option()
|
||||
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')
|
||||
subconfig = config_bag.config.getattr(subconfig_path,
|
||||
None,
|
||||
@ -726,9 +734,12 @@ class TiramisuContextOption(TiramisuContext):
|
||||
|
||||
@count
|
||||
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,
|
||||
None,
|
||||
self.config_bag)
|
||||
config_bag)
|
||||
|
||||
@count
|
||||
def make_dict(self,
|
||||
@ -782,8 +793,6 @@ class TiramisuDispatcherOption(TiramisuContextOption):
|
||||
return self
|
||||
config_bag = self.config_bag.copy()
|
||||
validate = not config_bag.force_unrestraint
|
||||
#config_bag.validate = validate
|
||||
#config_bag.validate_properties = validate
|
||||
if not validate:
|
||||
config_bag.setting_properties = None
|
||||
subconfig, name = config_bag.config.cfgimpl_get_home_by_path(path,
|
||||
|
@ -570,7 +570,6 @@ class SubConfig(object):
|
||||
if config_bag.validate_properties:
|
||||
try:
|
||||
self.unwrap_from_path(path,
|
||||
None,
|
||||
config_bag)
|
||||
self.cfgimpl_get_settings().validate_properties(path,
|
||||
None,
|
||||
@ -662,7 +661,6 @@ class SubConfig(object):
|
||||
config_bag=config_bag):
|
||||
path = '.'.join(path.split('.')[:-1])
|
||||
opt = context.unwrap_from_path(path,
|
||||
None,
|
||||
config_bag)
|
||||
sconfig_bag = config_bag.copy('nooption')
|
||||
sconfig_bag.option = opt
|
||||
@ -779,7 +777,6 @@ class _CommonConfig(SubConfig):
|
||||
|
||||
def unwrap_from_path(self,
|
||||
path,
|
||||
index,
|
||||
config_bag):
|
||||
"""convenience method to extract and Option() object from the Config()
|
||||
and it is **fast**: finds the option directly in the appropriate
|
||||
@ -805,17 +802,6 @@ class _CommonConfig(SubConfig):
|
||||
else:
|
||||
true_path = path
|
||||
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
|
||||
|
||||
def cfgimpl_get_path(self, dyn=True):
|
||||
|
@ -326,7 +326,9 @@ class Values(object):
|
||||
|
||||
context = self._getcontext()
|
||||
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):
|
||||
# set value to a fake config when option has dependency
|
||||
# validation will be complet in this case (consistency, ...)
|
||||
@ -490,11 +492,16 @@ class Values(object):
|
||||
config_bag.option = opt
|
||||
path = opt.impl_getpath(context)
|
||||
self_properties = config_bag.properties
|
||||
settings = context.cfgimpl_get_settings()
|
||||
if self_properties is None:
|
||||
self_properties = context.cfgimpl_get_settings().getproperties(path,
|
||||
index,
|
||||
config_bag)
|
||||
self_properties = settings.getproperties(path,
|
||||
index,
|
||||
config_bag)
|
||||
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:
|
||||
return owners.default
|
||||
if only_default:
|
||||
|
Reference in New Issue
Block a user