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

View file

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