improvement

This commit is contained in:
Emmanuel Garette 2018-04-22 10:43:19 +02:00
parent b8b0d7f6ed
commit 2018a92b66
6 changed files with 38 additions and 14 deletions

View File

@ -803,7 +803,7 @@ class TiramisuContextProperty(TiramisuContext):
"""set configuration to read only mode"""
settings = self.config_bag.config.cfgimpl_get_settings()
settings.read_only()
self.config_bag.setting_properties = settings.get_context_properties()
self.config_bag.delete('setting_properties')
@count
def read_write(self):
@ -812,7 +812,7 @@ class TiramisuContextProperty(TiramisuContext):
settings.read_write()
# #FIXME ?
settings.set_context_permissive(frozenset(['hidden']))
self.config_bag.setting_properties = settings.get_context_properties()
self.config_bag.delete('setting_properties')
#/FIXME ?
@count
@ -821,7 +821,6 @@ class TiramisuContextProperty(TiramisuContext):
props = self.get()
props.add(prop)
self.set(frozenset(props))
self.config_bag.setting_properties = self.config_bag.config.cfgimpl_get_settings().get_context_properties()
@count
def pop(self, prop):
@ -830,7 +829,6 @@ class TiramisuContextProperty(TiramisuContext):
if prop in props:
props.remove(prop)
self.set(frozenset(props))
self.config_bag.setting_properties = self.config_bag.config.cfgimpl_get_settings().get_context_properties()
@count
def get(self):
@ -841,7 +839,6 @@ class TiramisuContextProperty(TiramisuContext):
def set(self, props):
"""personalise configuration properties"""
self.config_bag.config.cfgimpl_get_settings().set_context_properties(props)
self.config_bag.setting_properties = self.config_bag.config.cfgimpl_get_settings().get_context_properties()
@count
def reset(self):

View File

@ -46,6 +46,8 @@ class Param:
class ParamOption(Param):
__slots__ = ('option', 'notraisepropertyerror')
def __init__(self, option, notraisepropertyerror=False):
if not hasattr(option, 'impl_is_symlinkoption'):
raise ValueError(_('paramoption needs an option not {}').format(type(option)))
if option.impl_is_symlinkoption():
cur_opt = option.impl_getopt()
else:

View File

@ -469,8 +469,7 @@ def validate_requires_arg(new_option,
"""
def get_option(require):
option = require['option']
#FIXME etrange ...
if not hasattr(option, 'impl_is_symlinkoption'):
if not isinstance(option, BaseOption):
raise ValueError(_('malformed requirements '
'must be an option in option {0}').format(name))
if not multi and option.impl_is_multi():
@ -509,8 +508,7 @@ def validate_requires_arg(new_option,
if set(exp.keys()) != {'option', 'value'}:
raise ValueError(_('malformed requirements expected must have '
'option and value for option {0}').format(name))
option = exp['option']
option._add_dependency(new_option)
option = get_option(exp)
if option is not None:
try:
option._validate(exp['value'], undefined)
@ -534,7 +532,6 @@ def validate_requires_arg(new_option,
raise ValueError(_('malformed requirements expected value '
'must be valid for option {0}'
': {1}').format(name, err))
option._add_dependency(new_option)
_set_expected(action,
inverse,
transitive,

View File

@ -29,9 +29,29 @@ class IntOption(Option):
__slots__ = tuple()
_display_name = _('integer')
def __init__(self,
name,
*args,
min_number=None,
max_number=None,
**kwargs):
extra = {}
if min_number is not None:
extra['min_number'] = min_number
if max_number is not None:
extra['max_number'] = min_number
super().__init__(name, extra=extra, *args, **kwargs)
def _validate(self,
value,
*args,
**kwargs):
if not isinstance(value, int):
raise ValueError()
min_number = self._get_extra('min_number')
if min_number and value < min_number:
raise ValueError(_('value must be greater than "{0}"'.format(min_number)))
max_number = self._get_extra('max_number')
if max_number and value > max_number:
raise ValueError(_('value must be less than "{0}"'.format(max_number)))

View File

@ -112,7 +112,7 @@ class Option(OnlyOption):
else:
val_call = (validator, validator_params)
self._val_call = (val_call, None)
if extra is not None:
if extra is not None and extra != {}:
_setattr(self, '_extra', extra)
if unique != undefined and not isinstance(unique, bool):
raise ValueError(_('unique must be a boolean, not "{}"').format(unique))
@ -723,11 +723,13 @@ class Option(OnlyOption):
def _get_extra(self,
key):
extra = self._extra
extra = getattr(self, '_extra', {})
if isinstance(extra, tuple):
return extra[1][extra[0].index(key)]
if key in extra[0]:
return extra[1][extra[0].index(key)]
return None
else:
return extra[key]
return extra.get(key)
def impl_is_submulti(self):
return getattr(self, '_multi', 1) == 2

View File

@ -154,6 +154,12 @@ class ConfigBag(object):
return self.setting_properties
return self.default.get(key)
def delete(self, key):
try:
return self.__delattr__(key)
except AttributeError:
pass
def copy(self, filters='all'):
kwargs = {}
for key in self.__slots__: