now there are two warnings_only's level:

- option's level for validation and _second_level_validation
- consistencies level
This commit is contained in:
Emmanuel Garette 2014-03-13 14:12:44 +01:00
parent 88b5af9810
commit f43ef2dafe
1 changed files with 13 additions and 11 deletions

View File

@ -429,10 +429,6 @@ class Option(BaseOption):
try: try:
# valid with self._validator # valid with self._validator
val_validator(_value) val_validator(_value)
# if context launch consistency validation
if context is not None:
descr._valid_consistency(self, _value, context, _index,
self._warnings_only)
self._second_level_validation(_value, self._warnings_only) self._second_level_validation(_value, self._warnings_only)
except ValueError as error: except ValueError as error:
if self._warnings_only: if self._warnings_only:
@ -440,6 +436,15 @@ class Option(BaseOption):
error = None error = None
except ValueWarning as warning: except ValueWarning as warning:
pass pass
if error is None and warning is None:
try:
# if context launch consistency validation
if context is not None:
descr._valid_consistency(self, _value, context, _index)
except ValueError as error:
pass
except ValueWarning as warning:
pass
if warning: if warning:
msg = _("warning on the value of the option {0}: {1}").format( msg = _("warning on the value of the option {0}: {1}").format(
self._name, warning) self._name, warning)
@ -1346,26 +1351,23 @@ class OptionDescription(BaseOption):
def impl_get_group_type(self): def impl_get_group_type(self):
return self._group_type return self._group_type
def _valid_consistency(self, option, value, context, index, warnings_only): def _valid_consistency(self, option, value, context, index):
if self._cache_consistencies is None: if self._cache_consistencies is None:
return True return True
#consistencies is something like [('_cons_not_equal', (opt1, opt2))] #consistencies is something like [('_cons_not_equal', (opt1, opt2))]
consistencies = self._cache_consistencies.get(option) consistencies = self._cache_consistencies.get(option)
if consistencies is not None: if consistencies is not None:
for func, all_cons_opts, params in consistencies: for func, all_cons_opts, params in consistencies:
if not warnings_only: warnings_only = params.get('warnings_only', False)
l_warnings_only = params.get('warnings_only', False)
else:
l_warnings_only = warnings_only
#all_cons_opts[0] is the option where func is set #all_cons_opts[0] is the option where func is set
try: try:
all_cons_opts[0]._launch_consistency(func, option, all_cons_opts[0]._launch_consistency(func, option,
value, value,
context, index, context, index,
all_cons_opts, all_cons_opts,
l_warnings_only) warnings_only)
except ValueError as err: except ValueError as err:
if l_warnings_only: if warnings_only:
raise ValueWarning(err.message, option) raise ValueWarning(err.message, option)
else: else:
raise err raise err