2005-08-31 10:47:56 +00:00
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2007-01-08 23:53:01 +00:00
|
|
|
#
|
|
|
|
# BitBake Build System Python Library
|
|
|
|
#
|
|
|
|
# Copyright (C) 2003 Holger Schurig
|
|
|
|
# Copyright (C) 2003, 2004 Chris Larson
|
|
|
|
#
|
|
|
|
# Based on Gentoo's portage.py.
|
|
|
|
#
|
|
|
|
# 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.
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2010-04-15 15:05:10 +00:00
|
|
|
__version__ = "1.11.0"
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2010-04-15 15:45:15 +00:00
|
|
|
import sys
|
|
|
|
if sys.version_info < (2, 6, 0):
|
|
|
|
raise RuntimeError("Sorry, python 2.6.0 or later is required for this version of bitbake")
|
|
|
|
|
2010-04-08 17:22:29 +00:00
|
|
|
import os
|
2010-06-09 23:17:29 +00:00
|
|
|
import logging
|
2010-09-10 00:57:33 +00:00
|
|
|
import traceback
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2010-06-09 23:17:29 +00:00
|
|
|
class NullHandler(logging.Handler):
|
|
|
|
def emit(self, record):
|
|
|
|
pass
|
|
|
|
|
2010-06-10 17:35:31 +00:00
|
|
|
Logger = logging.getLoggerClass()
|
|
|
|
class BBLogger(Logger):
|
|
|
|
def __init__(self, name):
|
|
|
|
if name.split(".")[0] == "BitBake":
|
|
|
|
self.debug = self.bbdebug
|
|
|
|
Logger.__init__(self, name)
|
|
|
|
|
|
|
|
def bbdebug(self, level, msg, *args, **kwargs):
|
|
|
|
return self.log(logging.DEBUG - level - 1, msg, *args, **kwargs)
|
|
|
|
|
|
|
|
def plain(self, msg, *args, **kwargs):
|
|
|
|
return self.log(logging.INFO + 1, msg, *args, **kwargs)
|
|
|
|
|
|
|
|
def verbose(self, msg, *args, **kwargs):
|
|
|
|
return self.log(logging.INFO - 1, msg, *args, **kwargs)
|
|
|
|
|
2010-09-10 00:57:33 +00:00
|
|
|
def exception(self, msg, *args, **kwargs):
|
|
|
|
return self.critical("%s\n%s" % (msg, traceback.format_exc()), *args, **kwargs)
|
|
|
|
|
2010-06-09 23:17:29 +00:00
|
|
|
logging.raiseExceptions = False
|
2010-06-10 17:35:31 +00:00
|
|
|
logging.setLoggerClass(BBLogger)
|
|
|
|
|
2010-06-09 23:17:29 +00:00
|
|
|
logger = logging.getLogger("BitBake")
|
|
|
|
logger.addHandler(NullHandler())
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
2010-09-08 18:31:36 +00:00
|
|
|
# This has to be imported after the setLoggerClass, as the import of bb.msg
|
|
|
|
# can result in construction of the various loggers.
|
|
|
|
import bb.msg
|
|
|
|
|
2005-08-31 10:47:56 +00:00
|
|
|
if "BBDEBUG" in os.environ:
|
|
|
|
level = int(os.environ["BBDEBUG"])
|
|
|
|
if level:
|
2006-11-16 15:02:15 +00:00
|
|
|
bb.msg.set_debug_level(level)
|
2005-08-31 10:47:56 +00:00
|
|
|
|
|
|
|
|
2009-07-20 04:57:09 +00:00
|
|
|
# Messaging convenience functions
|
2007-08-15 08:39:19 +00:00
|
|
|
def plain(*args):
|
2010-06-10 17:35:31 +00:00
|
|
|
logger.plain(''.join(args))
|
2007-08-15 08:39:19 +00:00
|
|
|
|
2005-08-31 10:47:56 +00:00
|
|
|
def debug(lvl, *args):
|
2010-06-10 17:35:31 +00:00
|
|
|
logger.debug(lvl, ''.join(args))
|
2005-08-31 10:47:56 +00:00
|
|
|
|
|
|
|
def note(*args):
|
2010-06-10 17:35:31 +00:00
|
|
|
logger.info(''.join(args))
|
2007-08-15 08:39:19 +00:00
|
|
|
|
|
|
|
def warn(*args):
|
2010-06-10 17:35:31 +00:00
|
|
|
logger.warn(''.join(args))
|
2005-08-31 10:47:56 +00:00
|
|
|
|
|
|
|
def error(*args):
|
2010-06-10 17:35:31 +00:00
|
|
|
logger.error(''.join(args))
|
2005-08-31 10:47:56 +00:00
|
|
|
|
|
|
|
def fatal(*args):
|
2010-06-10 17:35:31 +00:00
|
|
|
logger.critical(''.join(args))
|
|
|
|
sys.exit(1)
|
2005-08-31 10:47:56 +00:00
|
|
|
|
|
|
|
|
2010-04-09 23:51:09 +00:00
|
|
|
def deprecated(func, name = None, advice = ""):
|
|
|
|
"""This is a decorator which can be used to mark functions
|
|
|
|
as deprecated. It will result in a warning being emmitted
|
|
|
|
when the function is used."""
|
|
|
|
import warnings
|
|
|
|
|
|
|
|
if advice:
|
|
|
|
advice = ": %s" % advice
|
|
|
|
if name is None:
|
|
|
|
name = func.__name__
|
|
|
|
|
|
|
|
def newFunc(*args, **kwargs):
|
|
|
|
warnings.warn("Call to deprecated function %s%s." % (name,
|
|
|
|
advice),
|
2010-06-10 16:43:39 +00:00
|
|
|
category = PendingDeprecationWarning,
|
2010-04-09 23:51:09 +00:00
|
|
|
stacklevel = 2)
|
|
|
|
return func(*args, **kwargs)
|
|
|
|
newFunc.__name__ = func.__name__
|
|
|
|
newFunc.__doc__ = func.__doc__
|
|
|
|
newFunc.__dict__.update(func.__dict__)
|
|
|
|
return newFunc
|
|
|
|
|
2009-07-19 16:54:46 +00:00
|
|
|
# For compatibility
|
2010-04-09 23:51:09 +00:00
|
|
|
def deprecate_import(current, modulename, fromlist, renames = None):
|
|
|
|
"""Import objects from one module into another, wrapping them with a DeprecationWarning"""
|
|
|
|
import sys
|
|
|
|
|
|
|
|
module = __import__(modulename, fromlist = fromlist)
|
|
|
|
for position, objname in enumerate(fromlist):
|
|
|
|
obj = getattr(module, objname)
|
|
|
|
newobj = deprecated(obj, "{0}.{1}".format(current, objname),
|
|
|
|
"Please use {0}.{1} instead".format(modulename, objname))
|
|
|
|
if renames:
|
|
|
|
newname = renames[position]
|
|
|
|
else:
|
|
|
|
newname = objname
|
|
|
|
|
|
|
|
setattr(sys.modules[current], newname, newobj)
|
|
|
|
|
|
|
|
deprecate_import(__name__, "bb.fetch", ("MalformedUrl", "encodeurl", "decodeurl"))
|
|
|
|
deprecate_import(__name__, "bb.utils", ("mkdirhier", "movefile", "copyfile", "which"))
|
|
|
|
deprecate_import(__name__, "bb.utils", ["vercmp_string"], ["vercmp"])
|