1 # ex:ts=4:sw=4:sts=4:et
2 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4 BitBake 'msg' implementation
6 Message handling infrastructure for bitbake
10 # Copyright (C) 2006 Richard Purdie
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License version 2 as
14 # published by the Free Software Foundation.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along
22 # with this program; if not, write to the Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 import sys, os, re, bb
26 from bb import utils, event
32 domain = bb.utils.Enum(
47 class MsgBase(bb.event.Event):
48 """Base class for messages"""
50 def __init__(self, msg, d ):
52 event.Event.__init__(self, d)
54 class MsgDebug(MsgBase):
57 class MsgNote(MsgBase):
60 class MsgWarn(MsgBase):
63 class MsgError(MsgBase):
66 class MsgFatal(MsgBase):
70 # Message control functions
73 def set_debug_level(level):
74 bb.msg.debug_level = {}
75 for domain in bb.msg.domain:
76 bb.msg.debug_level[domain] = level
77 bb.msg.debug_level['default'] = level
79 def set_verbose(level):
80 bb.msg.verbose = level
82 def set_debug_domains(domains):
83 for domain in domains:
85 for ddomain in bb.msg.domain:
86 if domain == str(ddomain):
87 bb.msg.debug_level[ddomain] = bb.msg.debug_level[ddomain] + 1
90 std_warn("Logging domain %s is not valid, ignoring" % domain)
93 # Message handling functions
96 def debug(level, domain, msg, fn = None):
97 if debug_level[domain] >= level:
98 bb.event.fire(MsgDebug(msg, None))
101 def note(level, domain, msg, fn = None):
102 if level == 1 or verbose or debug_level[domain] >= 1:
105 def warn(domain, msg, fn = None):
108 def error(domain, msg, fn = None):
111 def fatal(domain, msg, fn = None):
115 # Compatibility functions for the original message interface
117 def std_debug(lvl, msg):
118 if debug_level['default'] >= lvl:
119 bb.event.fire(MsgDebug(msg, None))
120 print 'DEBUG: ' + msg
123 bb.event.fire(MsgNote(msg, None))
127 bb.event.fire(MsgWarn(msg, None))
128 print 'WARNING: ' + msg
131 bb.event.fire(MsgError(msg, None))
132 print 'ERROR: ' + msg
135 bb.event.fire(MsgFatal(msg, None))
136 print 'ERROR: ' + msg