diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-04-09 19:22:52 -0700 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-07-02 15:41:32 +0100 |
commit | 943ece8610fce9e6e5fda1b524ee479f013e8c5b (patch) | |
tree | d39ea721e450f19f029eebb750b91b6cf43ea0e8 /bitbake | |
parent | 9f2d7d816cfe36d9e3cb895f0bd4e8d81ae3bde0 (diff) | |
download | poky-943ece8610fce9e6e5fda1b524ee479f013e8c5b.tar.gz |
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 <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/msg.py | 40 | ||||
-rw-r--r-- | 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 9cb1d4c143..cf79314017 100644 --- a/bitbake/lib/bb/msg.py +++ b/bitbake/lib/bb/msg.py | |||
@@ -23,13 +23,17 @@ Message handling infrastructure for bitbake | |||
23 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 23 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
24 | 24 | ||
25 | import sys, bb | 25 | import sys, bb |
26 | import collections | ||
26 | from bb import event | 27 | from bb import event |
27 | 28 | ||
28 | debug_level = {} | 29 | debug_level = collections.defaultdict(lambda: 0) |
29 | |||
30 | verbose = False | 30 | verbose = False |
31 | 31 | ||
32 | domain = bb.utils.Enum( | 32 | def _NamedTuple(name, fields): |
33 | Tuple = collections.namedtuple(name, " ".join(fields)) | ||
34 | return Tuple(*range(len(fields))) | ||
35 | |||
36 | domain = _NamedTuple("Domain",( | ||
33 | 'Build', | 37 | 'Build', |
34 | 'Cache', | 38 | 'Cache', |
35 | 'Collection', | 39 | 'Collection', |
@@ -41,7 +45,7 @@ domain = bb.utils.Enum( | |||
41 | 'Provider', | 45 | 'Provider', |
42 | 'RunQueue', | 46 | 'RunQueue', |
43 | 'TaskData', | 47 | 'TaskData', |
44 | 'Util') | 48 | 'Util')) |
45 | 49 | ||
46 | 50 | ||
47 | class MsgBase(bb.event.Event): | 51 | class MsgBase(bb.event.Event): |
@@ -74,23 +78,21 @@ class MsgPlain(MsgBase): | |||
74 | # | 78 | # |
75 | 79 | ||
76 | def set_debug_level(level): | 80 | def set_debug_level(level): |
77 | bb.msg.debug_level = {} | 81 | for d in domain: |
78 | for domain in bb.msg.domain: | 82 | debug_level[d] = level |
79 | bb.msg.debug_level[domain] = level | 83 | debug_level['default'] = level |
80 | bb.msg.debug_level['default'] = level | ||
81 | 84 | ||
82 | def set_verbose(level): | 85 | def set_verbose(level): |
83 | bb.msg.verbose = level | 86 | verbose = level |
84 | 87 | ||
85 | def set_debug_domains(domains): | 88 | def set_debug_domains(domain_strings): |
86 | for domain in domains: | 89 | for domainstr in domain_strings: |
87 | found = False | 90 | for d in domain: |
88 | for ddomain in bb.msg.domain: | 91 | if domain._fields[d] == domainstr: |
89 | if domain == str(ddomain): | 92 | debug_level[d] += 1 |
90 | bb.msg.debug_level[ddomain] = bb.msg.debug_level[ddomain] + 1 | 93 | break |
91 | found = True | 94 | else: |
92 | if not found: | 95 | warn(None, "Logging domain %s is not valid, ignoring" % domain) |
93 | bb.msg.warn(None, "Logging domain %s is not valid, ignoring" % domain) | ||
94 | 96 | ||
95 | # | 97 | # |
96 | # Message handling functions | 98 | # Message handling functions |
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 83304e4a01..eee97276a2 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -371,46 +371,6 @@ def simple_exec(code, context): | |||
371 | def better_eval(source, locals): | 371 | def better_eval(source, locals): |
372 | return eval(source, _context, locals) | 372 | return eval(source, _context, locals) |
373 | 373 | ||
374 | def Enum(*names): | ||
375 | """ | ||
376 | A simple class to give Enum support | ||
377 | """ | ||
378 | |||
379 | assert names, "Empty enums are not supported" | ||
380 | |||
381 | class EnumClass(object): | ||
382 | __slots__ = names | ||
383 | def __iter__(self): return iter(constants) | ||
384 | def __len__(self): return len(constants) | ||
385 | def __getitem__(self, i): return constants[i] | ||
386 | def __repr__(self): return 'Enum' + str(names) | ||
387 | def __str__(self): return 'enum ' + str(constants) | ||
388 | |||
389 | class EnumValue(object): | ||
390 | __slots__ = ('__value') | ||
391 | def __init__(self, value): self.__value = value | ||
392 | Value = property(lambda self: self.__value) | ||
393 | EnumType = property(lambda self: EnumType) | ||
394 | def __hash__(self): return hash(self.__value) | ||
395 | def __cmp__(self, other): | ||
396 | # C fans might want to remove the following assertion | ||
397 | # to make all enums comparable by ordinal value {;)) | ||
398 | assert self.EnumType is other.EnumType, "Only values from the same enum are comparable" | ||
399 | return cmp(self.__value, other.__value) | ||
400 | def __invert__(self): return constants[maximum - self.__value] | ||
401 | def __nonzero__(self): return bool(self.__value) | ||
402 | def __repr__(self): return str(names[self.__value]) | ||
403 | |||
404 | maximum = len(names) - 1 | ||
405 | constants = [None] * len(names) | ||
406 | for i, each in enumerate(names): | ||
407 | val = EnumValue(i) | ||
408 | setattr(EnumClass, each, val) | ||
409 | constants[i] = val | ||
410 | constants = tuple(constants) | ||
411 | EnumType = EnumClass() | ||
412 | return EnumType | ||
413 | |||
414 | def lockfile(name): | 374 | def lockfile(name): |
415 | """ | 375 | """ |
416 | Use the file fn as a lock file, return when the lock has been acquired. | 376 | Use the file fn as a lock file, return when the lock has been acquired. |