compare option
This commit is contained in:
@ -53,7 +53,7 @@ def valid_name(name):
|
||||
|
||||
|
||||
class BaseInformation(object):
|
||||
__slots__ = ('_informations')
|
||||
__slots__ = ('_informations',)
|
||||
|
||||
def optimpl_set_information(self, key, value):
|
||||
"""updates the information's attribute
|
||||
@ -172,6 +172,37 @@ class Option(BaseInformation):
|
||||
' must be a tuple').format(type(properties), self._name))
|
||||
self._properties = properties # 'hidden', 'disabled'...
|
||||
|
||||
def __eq__(self, other):
|
||||
"Option comparison"
|
||||
if not isinstance(other, Option):
|
||||
return False
|
||||
a = list(self.__slots__ + Option.__slots__ + BaseInformation.__slots__)
|
||||
#a.remove('_default_multi')
|
||||
a.remove('_master_slaves')
|
||||
a.remove('_multitype')
|
||||
for var in a:
|
||||
try:
|
||||
val1 = getattr(self, var)
|
||||
not_in1 = False
|
||||
except:
|
||||
not_in1 = True
|
||||
try:
|
||||
val2 = getattr(other, var)
|
||||
not_in2 = False
|
||||
except:
|
||||
not_in2 = True
|
||||
if True in (not_in1, not_in2):
|
||||
if not_in1 != not_in2:
|
||||
return False
|
||||
elif val1 != val2:
|
||||
return False
|
||||
return True
|
||||
|
||||
def __ne__(self, other):
|
||||
if not isinstance(other, Option):
|
||||
return False
|
||||
return not self == other
|
||||
|
||||
def optimpl_validate(self, value, context=None, validate=True):
|
||||
"""
|
||||
:param value: the option's value
|
||||
@ -342,7 +373,7 @@ class ChoiceOption(Option):
|
||||
|
||||
|
||||
class BoolOption(Option):
|
||||
__slots__ = ('_opt_type')
|
||||
__slots__ = ('_opt_type',)
|
||||
_opt_type = 'bool'
|
||||
|
||||
def _validate(self, value):
|
||||
@ -350,7 +381,7 @@ class BoolOption(Option):
|
||||
|
||||
|
||||
class IntOption(Option):
|
||||
__slots__ = ('_opt_type')
|
||||
__slots__ = ('_opt_type',)
|
||||
_opt_type = 'int'
|
||||
|
||||
def _validate(self, value):
|
||||
@ -358,7 +389,7 @@ class IntOption(Option):
|
||||
|
||||
|
||||
class FloatOption(Option):
|
||||
__slots__ = ('_opt_type')
|
||||
__slots__ = ('_opt_type',)
|
||||
_opt_type = 'float'
|
||||
|
||||
def _validate(self, value):
|
||||
@ -366,7 +397,7 @@ class FloatOption(Option):
|
||||
|
||||
|
||||
class StrOption(Option):
|
||||
__slots__ = ('_opt_type')
|
||||
__slots__ = ('_opt_type',)
|
||||
_opt_type = 'string'
|
||||
|
||||
def _validate(self, value):
|
||||
@ -374,7 +405,7 @@ class StrOption(Option):
|
||||
|
||||
|
||||
class UnicodeOption(Option):
|
||||
__slots__ = ('_opt_type')
|
||||
__slots__ = ('_opt_type',)
|
||||
_opt_type = 'unicode'
|
||||
_empty = u''
|
||||
|
||||
@ -428,7 +459,7 @@ class IPOption(Option):
|
||||
|
||||
|
||||
class NetworkOption(Option):
|
||||
__slots__ = ('_opt_type')
|
||||
__slots__ = ('_opt_type',)
|
||||
_opt_type = 'network'
|
||||
|
||||
def _validate(self, value):
|
||||
@ -440,7 +471,7 @@ class NetworkOption(Option):
|
||||
|
||||
|
||||
class NetmaskOption(Option):
|
||||
__slots__ = ('_opt_type')
|
||||
__slots__ = ('_opt_type',)
|
||||
_opt_type = 'netmask'
|
||||
|
||||
def __init__(self, name, doc, default=None, default_multi=None,
|
||||
|
Reference in New Issue
Block a user