diff options
author | Richard Purdie <rpurdie@linux.intel.com> | 2006-07-08 16:30:02 +0000 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2006-07-08 16:30:02 +0000 |
commit | 4651e6cf84fea69c52d88b57f7ccc9a322933d7b (patch) | |
tree | b9cbe20a8591f2fc1b2d74b807f07429a22bdd5e /lib/bb/utils.py | |
parent | da652d60033fc735e6d5000fa05c6c8174ab3125 (diff) | |
download | bitbake-4651e6cf84fea69c52d88b57f7ccc9a322933d7b.tar.gz |
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
Diffstat (limited to 'lib/bb/utils.py')
-rw-r--r-- | lib/bb/utils.py | 40 |
1 files changed, 40 insertions, 0 deletions
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 |