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

View File

@ -46,6 +46,8 @@ class Param:
class ParamOption(Param): class ParamOption(Param):
__slots__ = ('option', 'notraisepropertyerror') __slots__ = ('option', 'notraisepropertyerror')
def __init__(self, option, notraisepropertyerror=False): 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(): if option.impl_is_symlinkoption():
cur_opt = option.impl_getopt() cur_opt = option.impl_getopt()
else: else:

View File

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

View File

@ -29,9 +29,29 @@ class IntOption(Option):
__slots__ = tuple() __slots__ = tuple()
_display_name = _('integer') _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, def _validate(self,
value, value,
*args, *args,
**kwargs): **kwargs):
if not isinstance(value, int): if not isinstance(value, int):
raise ValueError() 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: else:
val_call = (validator, validator_params) val_call = (validator, validator_params)
self._val_call = (val_call, None) self._val_call = (val_call, None)
if extra is not None: if extra is not None and extra != {}:
_setattr(self, '_extra', extra) _setattr(self, '_extra', extra)
if unique != undefined and not isinstance(unique, bool): if unique != undefined and not isinstance(unique, bool):
raise ValueError(_('unique must be a boolean, not "{}"').format(unique)) raise ValueError(_('unique must be a boolean, not "{}"').format(unique))
@ -723,11 +723,13 @@ class Option(OnlyOption):
def _get_extra(self, def _get_extra(self,
key): key):
extra = self._extra extra = getattr(self, '_extra', {})
if isinstance(extra, tuple): 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: else:
return extra[key] return extra.get(key)
def impl_is_submulti(self): def impl_is_submulti(self):
return getattr(self, '_multi', 1) == 2 return getattr(self, '_multi', 1) == 2

View File

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