ec_iface: Additional PyECLibEnum helpers
Signed-off-by: Tushar Gohad <tushar.gohad@intel.com>
This commit is contained in:
parent
4519d55ad9
commit
eafb1b721b
@ -39,7 +39,7 @@ class PyECLibEnum(Enum):
|
|||||||
return list(self)
|
return list(self)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_member(cls, name):
|
def has_enum(cls, name):
|
||||||
# returns True if name is a valid member of the enum
|
# returns True if name is a valid member of the enum
|
||||||
try:
|
try:
|
||||||
cls.__getattr__(name)
|
cls.__getattr__(name)
|
||||||
@ -47,6 +47,22 @@ class PyECLibEnum(Enum):
|
|||||||
return False
|
return False
|
||||||
return True
|
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):
|
def __str__(self):
|
||||||
return "%s: %d" % (self.name, self.value)
|
return "%s: %d" % (self.name, self.value)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user