2006-11-16 15:02:15 +00:00
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
"""
|
|
|
|
BitBake 'msg' implementation
|
|
|
|
|
|
|
|
Message handling infrastructure for bitbake
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2007-01-08 23:53:01 +00:00
|
|
|
# Copyright (C) 2006 Richard Purdie
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
2010-04-08 17:22:29 +00:00
|
|
|
import sys
|
2010-04-10 02:22:52 +00:00
|
|
|
import collections
|
2010-04-08 17:22:29 +00:00
|
|
|
import bb
|
|
|
|
import bb.event
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2010-04-10 02:22:52 +00:00
|
|
|
debug_level = collections.defaultdict(lambda: 0)
|
2006-11-16 15:02:15 +00:00
|
|
|
verbose = False
|
|
|
|
|
2010-04-10 02:22:52 +00:00
|
|
|
def _NamedTuple(name, fields):
|
|
|
|
Tuple = collections.namedtuple(name, " ".join(fields))
|
|
|
|
return Tuple(*range(len(fields)))
|
|
|
|
|
2010-03-24 23:56:12 +00:00
|
|
|
domain = _NamedTuple("Domain", (
|
2010-04-10 02:27:21 +00:00
|
|
|
"Default",
|
|
|
|
"Build",
|
|
|
|
"Cache",
|
|
|
|
"Collection",
|
|
|
|
"Data",
|
|
|
|
"Depends",
|
|
|
|
"Fetcher",
|
|
|
|
"Parsing",
|
|
|
|
"PersistData",
|
|
|
|
"Provider",
|
|
|
|
"RunQueue",
|
|
|
|
"TaskData",
|
|
|
|
"Util"))
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2007-04-01 15:04:49 +00:00
|
|
|
|
|
|
|
class MsgBase(bb.event.Event):
|
|
|
|
"""Base class for messages"""
|
|
|
|
|
2010-01-20 18:46:02 +00:00
|
|
|
def __init__(self, msg):
|
2007-04-01 15:04:49 +00:00
|
|
|
self._message = msg
|
2010-04-08 17:22:29 +00:00
|
|
|
bb.event.Event.__init__(self)
|
2007-04-01 15:04:49 +00:00
|
|
|
|
|
|
|
class MsgDebug(MsgBase):
|
|
|
|
"""Debug Message"""
|
|
|
|
|
|
|
|
class MsgNote(MsgBase):
|
|
|
|
"""Note Message"""
|
|
|
|
|
|
|
|
class MsgWarn(MsgBase):
|
|
|
|
"""Warning Message"""
|
|
|
|
|
|
|
|
class MsgError(MsgBase):
|
|
|
|
"""Error Message"""
|
|
|
|
|
|
|
|
class MsgFatal(MsgBase):
|
|
|
|
"""Fatal Message"""
|
|
|
|
|
2007-08-15 08:39:19 +00:00
|
|
|
class MsgPlain(MsgBase):
|
|
|
|
"""General output"""
|
|
|
|
|
2006-11-16 15:02:15 +00:00
|
|
|
#
|
|
|
|
# Message control functions
|
|
|
|
#
|
|
|
|
|
|
|
|
def set_debug_level(level):
|
2010-04-10 02:22:52 +00:00
|
|
|
for d in domain:
|
|
|
|
debug_level[d] = level
|
2010-04-10 02:27:21 +00:00
|
|
|
debug_level[domain.Default] = level
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2010-04-10 02:34:07 +00:00
|
|
|
def get_debug_level(msgdomain = domain.Default):
|
|
|
|
return debug_level[msgdomain]
|
|
|
|
|
2006-11-16 15:02:15 +00:00
|
|
|
def set_verbose(level):
|
2010-04-10 02:22:52 +00:00
|
|
|
verbose = level
|
|
|
|
|
2010-04-10 02:33:04 +00:00
|
|
|
def set_debug_domains(strdomains):
|
|
|
|
for domainstr in strdomains:
|
2010-04-10 02:22:52 +00:00
|
|
|
for d in domain:
|
|
|
|
if domain._fields[d] == domainstr:
|
|
|
|
debug_level[d] += 1
|
|
|
|
break
|
|
|
|
else:
|
2010-04-10 02:33:04 +00:00
|
|
|
warn(None, "Logging domain %s is not valid, ignoring" % domainstr)
|
2006-11-16 15:02:15 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Message handling functions
|
|
|
|
#
|
|
|
|
|
2010-04-10 02:27:21 +00:00
|
|
|
def debug(level, msgdomain, msg, fn = None):
|
|
|
|
if not msgdomain:
|
|
|
|
msgdomain = domain.Default
|
|
|
|
|
|
|
|
if debug_level[msgdomain] >= level:
|
2010-01-20 18:46:02 +00:00
|
|
|
bb.event.fire(MsgDebug(msg), None)
|
2010-04-09 22:55:17 +00:00
|
|
|
if not bb.event._ui_handlers:
|
2010-06-18 10:50:15 +00:00
|
|
|
print('DEBUG: %s' % (msg))
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2010-04-10 02:27:21 +00:00
|
|
|
def note(level, msgdomain, msg, fn = None):
|
|
|
|
if not msgdomain:
|
|
|
|
msgdomain = domain.Default
|
|
|
|
|
|
|
|
if level == 1 or verbose or debug_level[msgdomain] >= 1:
|
2010-01-20 18:46:02 +00:00
|
|
|
bb.event.fire(MsgNote(msg), None)
|
2010-04-09 22:55:17 +00:00
|
|
|
if not bb.event._ui_handlers:
|
2010-06-18 10:50:15 +00:00
|
|
|
print('NOTE: %s' % (msg))
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2010-04-10 02:27:21 +00:00
|
|
|
def warn(msgdomain, msg, fn = None):
|
2010-01-20 18:46:02 +00:00
|
|
|
bb.event.fire(MsgWarn(msg), None)
|
2010-04-09 22:55:17 +00:00
|
|
|
if not bb.event._ui_handlers:
|
2010-06-18 10:50:15 +00:00
|
|
|
print('WARNING: %s' % (msg))
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2010-04-10 02:27:21 +00:00
|
|
|
def error(msgdomain, msg, fn = None):
|
2010-01-20 18:46:02 +00:00
|
|
|
bb.event.fire(MsgError(msg), None)
|
2010-06-18 10:50:15 +00:00
|
|
|
print('ERROR: %s' % (msg))
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2010-04-10 02:27:21 +00:00
|
|
|
def fatal(msgdomain, msg, fn = None):
|
2010-01-20 18:46:02 +00:00
|
|
|
bb.event.fire(MsgFatal(msg), None)
|
2010-06-18 10:50:15 +00:00
|
|
|
print('FATAL: %s' % (msg))
|
2006-11-16 15:02:15 +00:00
|
|
|
sys.exit(1)
|
2007-08-15 08:39:19 +00:00
|
|
|
|
|
|
|
def plain(msg, fn = None):
|
2010-01-20 18:46:02 +00:00
|
|
|
bb.event.fire(MsgPlain(msg), None)
|
2010-04-09 22:55:17 +00:00
|
|
|
if not bb.event._ui_handlers:
|
2010-04-10 02:46:14 +00:00
|
|
|
print(msg)
|