for a multi mandatory, allow [] with allow_empty_list attribut
This commit is contained in:
@ -99,7 +99,7 @@ class Base(StorageBase):
|
||||
def __init__(self, name, doc, default=None, default_multi=None,
|
||||
requires=None, multi=False, callback=None,
|
||||
callback_params=None, validator=None, validator_params=None,
|
||||
properties=None, warnings_only=False, extra=None):
|
||||
properties=None, warnings_only=False, extra=None, allow_empty_list=False):
|
||||
if not valid_name(name): # pragma: optional cover
|
||||
raise ValueError(_("invalid name: {0} for option").format(name))
|
||||
if requires is not None:
|
||||
@ -134,7 +134,7 @@ class Base(StorageBase):
|
||||
'requirement {0}'.format(
|
||||
list(set_forbidden_properties)))
|
||||
StorageBase.__init__(self, name, _multi, warnings_only, doc, extra,
|
||||
calc_properties, requires, properties)
|
||||
calc_properties, requires, properties, allow_empty_list)
|
||||
if multi is not False and default is None:
|
||||
default = []
|
||||
self.impl_validate(default)
|
||||
@ -905,7 +905,7 @@ class SymLinkOption(OnlyOption):
|
||||
'for symlink {0}').format(name))
|
||||
super(Base, self).__init__(name, undefined, undefined, undefined,
|
||||
undefined, undefined, undefined, undefined,
|
||||
opt)
|
||||
False, opt)
|
||||
self.commit()
|
||||
|
||||
def __getattr__(self, name, context=undefined):
|
||||
|
@ -467,7 +467,7 @@ class Settings(object):
|
||||
else:
|
||||
if 'mandatory' in properties and \
|
||||
not self._getcontext().cfgimpl_get_values()._isempty(
|
||||
opt_or_descr, value):
|
||||
opt_or_descr, value, opt_or_descr.impl_allow_empty_list()):
|
||||
properties.remove('mandatory')
|
||||
if is_write and 'everything_frozen' in self_properties:
|
||||
properties.add('frozen')
|
||||
|
@ -32,7 +32,8 @@ class StorageBase(object):
|
||||
'_multi',
|
||||
'_extra',
|
||||
'_warnings_only',
|
||||
#valeur
|
||||
'_allow_empty_list',
|
||||
#value
|
||||
'_default',
|
||||
'_default_multi',
|
||||
#calcul
|
||||
@ -41,10 +42,7 @@ class StorageBase(object):
|
||||
'_properties',
|
||||
'_calc_properties',
|
||||
'_val_call',
|
||||
#'_validator',
|
||||
#'_validator_params',
|
||||
#'_callback',
|
||||
#'_callback_params',
|
||||
#
|
||||
'_consistencies',
|
||||
'_master_slaves',
|
||||
'_choice_values',
|
||||
@ -62,7 +60,7 @@ class StorageBase(object):
|
||||
)
|
||||
|
||||
def __init__(self, name, multi, warnings_only, doc, extra, calc_properties,
|
||||
requires, properties, opt=undefined):
|
||||
requires, properties, allow_empty_list, opt=undefined):
|
||||
self._name = name
|
||||
if doc is not undefined:
|
||||
self._informations = {'doc': doc}
|
||||
@ -81,6 +79,8 @@ class StorageBase(object):
|
||||
self._properties = properties
|
||||
if opt is not undefined:
|
||||
self._opt = opt
|
||||
if allow_empty_list is not False:
|
||||
self._allow_empty_list = allow_empty_list
|
||||
|
||||
def _set_default_values(self, default, default_multi):
|
||||
if ((self.impl_is_multi() and default != tuple()) or
|
||||
@ -298,6 +298,13 @@ class StorageBase(object):
|
||||
_multi = 1
|
||||
return _multi == 2
|
||||
|
||||
def impl_allow_empty_list(self):
|
||||
try:
|
||||
return self._allow_empty_list
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
|
||||
def _get_extra(self, key):
|
||||
extra = self._extra
|
||||
if isinstance(extra, tuple):
|
||||
@ -308,7 +315,7 @@ class StorageBase(object):
|
||||
def _is_warnings_only(self):
|
||||
try:
|
||||
return self._warnings_only
|
||||
except:
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
def impl_getdefault(self):
|
||||
|
@ -175,13 +175,13 @@ class Values(object):
|
||||
if hasvalue:
|
||||
self._p_.resetvalue(path)
|
||||
|
||||
def _isempty(self, opt, value):
|
||||
def _isempty(self, opt, value, allow_empty_list):
|
||||
"convenience method to know if an option is empty"
|
||||
empty = opt._empty
|
||||
if value is not undefined:
|
||||
empty_not_multi = not opt.impl_is_multi() and (value is None or
|
||||
value == empty)
|
||||
empty_multi = opt.impl_is_multi() and (value == [] or
|
||||
empty_multi = opt.impl_is_multi() and ((not allow_empty_list and value == []) or
|
||||
None in value or
|
||||
empty in value)
|
||||
else:
|
||||
|
Reference in New Issue
Block a user