From 4651e6cf84fea69c52d88b57f7ccc9a322933d7b Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Sat, 8 Jul 2006 16:30:02 +0000 Subject: bitbake/lib/bb/__init__.py: bitbake/lib/bb/build.py: bitbake/lib/bb/utils.py: bitbake/lib/bb/shell.py: bitbake/lib/bb/providers.py: bitbake/lib/bb/msg.py: bitbake/bin/bitbake: bitbake/bin/bitdoc: bitbake/classes/base.bbclass: Start an overhaul of the message handling in bitbake: - Introduce a new msg module to replace the existing simple calls. - The msg module adds the conncept of message domains so ultimately we can select which kinds of debug messages we want to see (it uses an Enum class for this) - Add a warn logging level for things the user should really pay attention to as note is a little overloaded at present - Start converting to use the new fuctions --- lib/bb/utils.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lib/bb/utils.py') diff --git a/lib/bb/utils.py b/lib/bb/utils.py index 5b3cb38d8..b63c4e530 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -160,3 +160,43 @@ def better_exec(code, context, text, realfile): _print_trace( text.split('\n'), line ) raise + +def Enum(*names): + """ + A simple class to give Enum support + """ + + assert names, "Empty enums are not supported" + + class EnumClass(object): + __slots__ = names + def __iter__(self): return iter(constants) + def __len__(self): return len(constants) + def __getitem__(self, i): return constants[i] + def __repr__(self): return 'Enum' + str(names) + def __str__(self): return 'enum ' + str(constants) + + class EnumValue(object): + __slots__ = ('__value') + def __init__(self, value): self.__value = value + Value = property(lambda self: self.__value) + EnumType = property(lambda self: EnumType) + def __hash__(self): return hash(self.__value) + def __cmp__(self, other): + # C fans might want to remove the following assertion + # to make all enums comparable by ordinal value {;)) + assert self.EnumType is other.EnumType, "Only values from the same enum are comparable" + return cmp(self.__value, other.__value) + def __invert__(self): return constants[maximum - self.__value] + def __nonzero__(self): return bool(self.__value) + def __repr__(self): return str(names[self.__value]) + + maximum = len(names) - 1 + constants = [None] * len(names) + for i, each in enumerate(names): + val = EnumValue(i) + setattr(EnumClass, each, val) + constants[i] = val + constants = tuple(constants) + EnumType = EnumClass() + return EnumType -- cgit 1.2.3-korg