consistencies now a list
This commit is contained in:
parent
9644dd3661
commit
fbcbbfbd2b
|
@ -79,7 +79,7 @@ class Option(BaseInformation):
|
|||
"""
|
||||
__slots__ = ('_name', '_requires', '_multi', '_validator', '_default_multi',
|
||||
'_default', '_properties', '_callback', '_multitype',
|
||||
'_master_slaves', '_consistency')
|
||||
'_master_slaves', '_consistencies')
|
||||
|
||||
def __init__(self, name, doc, default=None, default_multi=None,
|
||||
requires=None, multi=False, callback=None,
|
||||
|
@ -111,7 +111,7 @@ class Option(BaseInformation):
|
|||
validate_requires_arg(requires, self._name)
|
||||
self._requires = requires
|
||||
self._multi = multi
|
||||
self._consistency = None
|
||||
self._consistencies = None
|
||||
if validator is not None:
|
||||
if type(validator) != FunctionType:
|
||||
raise TypeError(_("validator must be a function"))
|
||||
|
@ -254,11 +254,22 @@ class Option(BaseInformation):
|
|||
if opt_ is not opt:
|
||||
path = descr.get_path_by_opt(opt_)
|
||||
val = context._getattr(path, validate=False)
|
||||
if val is not None:
|
||||
if val in values:
|
||||
return False
|
||||
values.append(val)
|
||||
return True
|
||||
|
||||
def add_consistency(self, func, opts):
|
||||
pass
|
||||
if self._consistencies is None:
|
||||
self._consistencies = []
|
||||
if self not in opts:
|
||||
opts = list(opts)
|
||||
opts.append(self)
|
||||
opts = tuple(opts)
|
||||
self._consistencies.append(('cons_{}'.format(func), opts))
|
||||
|
||||
|
||||
class ChoiceOption(Option):
|
||||
__slots__ = ('_values', '_open_values', 'opt_type')
|
||||
|
@ -333,9 +344,9 @@ class UnicodeOption(Option):
|
|||
|
||||
|
||||
class SymLinkOption(object):
|
||||
__slots__ = ('_name', 'opt', '_consistency')
|
||||
__slots__ = ('_name', 'opt', '_consistencies')
|
||||
opt_type = 'symlink'
|
||||
_consistency = None
|
||||
_consistencies = None
|
||||
|
||||
def __init__(self, name, path, opt):
|
||||
self._name = name
|
||||
|
@ -408,9 +419,9 @@ class NetmaskOption(Option):
|
|||
if opt_ip is None:
|
||||
pass
|
||||
elif isinstance(opt_ip, IPOption):
|
||||
self._consistency = ('cons_ip_netmask', (self, opt_ip))
|
||||
self._consistencies = [('cons_ip_netmask', (self, opt_ip))]
|
||||
elif isinstance(opt_ip, NetworkOption):
|
||||
self._consistency = ('cons_network_netmask', (self, opt_ip))
|
||||
self._consistencies = [('cons_network_netmask', (self, opt_ip))]
|
||||
else:
|
||||
raise ValueError(_('unknown type for opt_ip'))
|
||||
|
||||
|
@ -547,12 +558,13 @@ class OptionDescription(BaseInformation):
|
|||
cache_option.append(option)
|
||||
cache_path.append(str('.'.join(_currpath + [attr])))
|
||||
if not isinstance(option, OptionDescription):
|
||||
if option._consistency is not None:
|
||||
func, opts = option._consistency
|
||||
if option._consistencies is not None:
|
||||
for consistency in option._consistencies:
|
||||
func, opts = consistency
|
||||
for opt in opts:
|
||||
if opt in _consistencies:
|
||||
raise ValueError(_('opt {} already in consistency').format(opt._name))
|
||||
_consistencies[opt] = (func, opts)
|
||||
_consistencies.setdefault(opt, []).append((func, opts))
|
||||
else:
|
||||
_currpath.append(attr)
|
||||
option.build_cache(cache_path, cache_option, _currpath, _consistencies)
|
||||
|
@ -632,10 +644,13 @@ class OptionDescription(BaseInformation):
|
|||
return self._group_type
|
||||
|
||||
def valid_consistency(self, opt, value, context, index):
|
||||
cons = self._consistencies.get(opt)
|
||||
if cons is not None:
|
||||
func, opts = cons
|
||||
return getattr(opts[0], func)(opt, value, context, index, opts)
|
||||
consistencies = self._consistencies.get(opt)
|
||||
if consistencies is not None:
|
||||
for consistency in consistencies:
|
||||
func, opts = consistency
|
||||
ret = getattr(opts[0], func)(opt, value, context, index, opts)
|
||||
if ret is False:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue