ec_iface: Additional PyECLibEnum helpers

Signed-off-by: Tushar Gohad <tushar.gohad@intel.com>
This commit is contained in:
Tushar Gohad 2014-06-23 13:21:42 -07:00
parent 4519d55ad9
commit eafb1b721b

View File

@ -39,7 +39,7 @@ class PyECLibEnum(Enum):
return list(self)
@classmethod
def is_member(cls, name):
def has_enum(cls, name):
# returns True if name is a valid member of the enum
try:
cls.__getattr__(name)
@ -47,6 +47,22 @@ class PyECLibEnum(Enum):
return False
return True
@classmethod
def get_by_name(cls, name):
try:
obj = cls.__getattr__(name)
except AttributeError:
return None
return obj
@classmethod
def names(cls):
return [name for name, value in cls.__members__.items()]
@classmethod
def values(cls):
return [value for name, value in cls.__members__.items()]
def __str__(self):
return "%s: %d" % (self.name, self.value)