From 943ece8610fce9e6e5fda1b524ee479f013e8c5b Mon Sep 17 00:00:00 2001 From: Chris Larson Date: Fri, 9 Apr 2010 19:22:52 -0700 Subject: Implement bb.msg.domain as a named tuple, drop the Enum class Also fixes some bb.msg references from within bb.msg. (Bitbake rev: db95af590f742c8186e84046ad9704fae1733720) Signed-off-by: Chris Larson Signed-off-by: Richard Purdie --- bitbake/lib/bb/msg.py | 40 +++++++++++++++++++++------------------- bitbake/lib/bb/utils.py | 40 ---------------------------------------- 2 files changed, 21 insertions(+), 59 deletions(-) diff --git a/bitbake/lib/bb/msg.py b/bitbake/lib/bb/msg.py index 9cb1d4c14..cf7931401 100644 --- a/bitbake/lib/bb/msg.py +++ b/bitbake/lib/bb/msg.py @@ -23,13 +23,17 @@ Message handling infrastructure for bitbake # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import sys, bb +import collections from bb import event -debug_level = {} - +debug_level = collections.defaultdict(lambda: 0) verbose = False -domain = bb.utils.Enum( +def _NamedTuple(name, fields): + Tuple = collections.namedtuple(name, " ".join(fields)) + return Tuple(*range(len(fields))) + +domain = _NamedTuple("Domain",( 'Build', 'Cache', 'Collection', @@ -41,7 +45,7 @@ domain = bb.utils.Enum( 'Provider', 'RunQueue', 'TaskData', - 'Util') + 'Util')) class MsgBase(bb.event.Event): @@ -74,23 +78,21 @@ class MsgPlain(MsgBase): # def set_debug_level(level): - bb.msg.debug_level = {} - for domain in bb.msg.domain: - bb.msg.debug_level[domain] = level - bb.msg.debug_level['default'] = level + for d in domain: + debug_level[d] = level + debug_level['default'] = level def set_verbose(level): - bb.msg.verbose = level - -def set_debug_domains(domains): - for domain in domains: - found = False - for ddomain in bb.msg.domain: - if domain == str(ddomain): - bb.msg.debug_level[ddomain] = bb.msg.debug_level[ddomain] + 1 - found = True - if not found: - bb.msg.warn(None, "Logging domain %s is not valid, ignoring" % domain) + verbose = level + +def set_debug_domains(domain_strings): + for domainstr in domain_strings: + for d in domain: + if domain._fields[d] == domainstr: + debug_level[d] += 1 + break + else: + warn(None, "Logging domain %s is not valid, ignoring" % domain) # # Message handling functions diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 83304e4a0..eee97276a 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py @@ -371,46 +371,6 @@ def simple_exec(code, context): def better_eval(source, locals): return eval(source, _context, locals) -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 - def lockfile(name): """ Use the file fn as a lock file, return when the lock has been acquired. -- cgit v1.2.3