summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/utils.py
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-06-10 10:35:31 -0700
committerRichard Purdie <rpurdie@linux.intel.com>2011-01-04 14:46:33 +0000
commitecc68fa4fbb579e97ea45156e79a293b073697a0 (patch)
tree6d08682e43476e37ccf48ee14c8d81e208d1c897 /bitbake/lib/bb/utils.py
parentd3a45c7d41a88d79389fc40eb68816e4939fb6f9 (diff)
downloadpoky-ecc68fa4fbb579e97ea45156e79a293b073697a0.tar.gz
Switch bitbake internals to use logging directly rather than bb.msg
We use a custom Logger subclass for our loggers This logger provides: - 'debug' method which accepts a debug level - 'plain' method which bypasses log formatting - 'verbose' method which is more detail than info, but less than debug (Bitbake rev: 3b2c1fe5ca56daebb24073a9dd45723d3efd2a8d) Signed-off-by: Chris Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r--bitbake/lib/bb/utils.py47
1 files changed, 26 insertions, 21 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 8330c80b72..47fef8c1a9 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -21,11 +21,14 @@ BitBake Utility Functions
21 21
22import re, fcntl, os, string, stat, shutil, time 22import re, fcntl, os, string, stat, shutil, time
23import sys 23import sys
24import bb
25import errno 24import errno
25import logging
26import bb
26import bb.msg 27import bb.msg
27from commands import getstatusoutput 28from commands import getstatusoutput
28 29
30logger = logging.getLogger("BitBake.Util")
31
29# Version comparison 32# Version comparison
30separators = ".-" 33separators = ".-"
31 34
@@ -307,9 +310,9 @@ def _print_trace(body, line):
307 max_line = min(line + 4, len(body)) 310 max_line = min(line + 4, len(body))
308 for i in range(min_line, max_line + 1): 311 for i in range(min_line, max_line + 1):
309 if line == i: 312 if line == i:
310 bb.msg.error(bb.msg.domain.Util, " *** %.4d:%s" % (i, body[i-1]) ) 313 logger.error(" *** %.4d:%s" % (i, body[i-1]) )
311 else: 314 else:
312 bb.msg.error(bb.msg.domain.Util, " %.4d:%s" % (i, body[i-1]) ) 315 logger.error(" %.4d:%s" % (i, body[i-1]) )
313 316
314 317
315def better_compile(text, file, realfile, mode = "exec"): 318def better_compile(text, file, realfile, mode = "exec"):
@@ -322,16 +325,16 @@ def better_compile(text, file, realfile, mode = "exec"):
322 except Exception as e: 325 except Exception as e:
323 # split the text into lines again 326 # split the text into lines again
324 body = text.split('\n') 327 body = text.split('\n')
325 bb.msg.error(bb.msg.domain.Util, "Error in compiling python function in: %s" % (realfile)) 328 logger.error("Error in compiling python function in: %s" % (realfile))
326 bb.msg.error(bb.msg.domain.Util, str(e)) 329 logger.error(str(e))
327 if e.lineno: 330 if e.lineno:
328 bb.msg.error(bb.msg.domain.Util, "The lines leading to this error were:") 331 logger.error("The lines leading to this error were:")
329 bb.msg.error(bb.msg.domain.Util, "\t%d:%s:'%s'" % (e.lineno, e.__class__.__name__, body[e.lineno-1])) 332 logger.error("\t%d:%s:'%s'" % (e.lineno, e.__class__.__name__, body[e.lineno-1]))
330 _print_trace(body, e.lineno) 333 _print_trace(body, e.lineno)
331 else: 334 else:
332 bb.msg.error(bb.msg.domain.Util, "The function causing this error was:") 335 logger.error("The function causing this error was:")
333 for line in body: 336 for line in body:
334 bb.msg.error(bb.msg.domain.Util, line) 337 logger.error(line)
335 raise 338 raise
336 339
337def better_exec(code, context, text, realfile = "<code>"): 340def better_exec(code, context, text, realfile = "<code>"):
@@ -351,9 +354,11 @@ def better_exec(code, context, text, realfile = "<code>"):
351 if t in [bb.parse.SkipPackage, bb.build.FuncFailed]: 354 if t in [bb.parse.SkipPackage, bb.build.FuncFailed]:
352 raise 355 raise
353 356
357 logger.exception("Error executing python function in '%s'", code.co_filename)
358
354 # print the Header of the Error Message 359 # print the Header of the Error Message
355 bb.msg.error(bb.msg.domain.Util, "There was an error when executing a python function in: %s" % code.co_filename) 360 logger.error("There was an error when executing a python function in: %s" % code.co_filename)
356 bb.msg.error(bb.msg.domain.Util, "Exception:%s Message:%s" % (t, value)) 361 logger.error("Exception:%s Message:%s" % (t, value))
357 362
358 # Strip 'us' from the stack (better_exec call) 363 # Strip 'us' from the stack (better_exec call)
359 tb = tb.tb_next 364 tb = tb.tb_next
@@ -364,13 +369,13 @@ def better_exec(code, context, text, realfile = "<code>"):
364 369
365 tbextract = traceback.extract_tb(tb) 370 tbextract = traceback.extract_tb(tb)
366 tbformat = "\n".join(traceback.format_list(tbextract)) 371 tbformat = "\n".join(traceback.format_list(tbextract))
367 bb.msg.error(bb.msg.domain.Util, "The stack trace of python calls that resulted in thie exception/failure was:") 372 logger.error("The stack trace of python calls that resulted in thie exception/failure was:")
368 for line in tbformat.split('\n'): 373 for line in tbformat.split('\n'):
369 bb.msg.error(bb.msg.domain.Util, line) 374 logger.error(line)
370 375
371 bb.msg.error(bb.msg.domain.Util, "The code that was being executed was:") 376 logger.error("The code that was being executed was:")
372 _print_trace(textarray, linefailed) 377 _print_trace(textarray, linefailed)
373 bb.msg.error(bb.msg.domain.Util, "(file: '%s', lineno: %s, function: %s)" % (tbextract[0][0], tbextract[0][1], tbextract[0][2])) 378 logger.error("(file: '%s', lineno: %s, function: %s)" % (tbextract[0][0], tbextract[0][1], tbextract[0][2]))
374 379
375 # See if this is a function we constructed and has calls back into other functions in 380 # See if this is a function we constructed and has calls back into other functions in
376 # "text". If so, try and improve the context of the error by diving down the trace 381 # "text". If so, try and improve the context of the error by diving down the trace
@@ -379,7 +384,7 @@ def better_exec(code, context, text, realfile = "<code>"):
379 while nexttb is not None: 384 while nexttb is not None:
380 if tbextract[level][0] == tbextract[level+1][0] and tbextract[level+1][2] == tbextract[level][0]: 385 if tbextract[level][0] == tbextract[level+1][0] and tbextract[level+1][2] == tbextract[level][0]:
381 _print_trace(textarray, tbextract[level+1][1]) 386 _print_trace(textarray, tbextract[level+1][1])
382 bb.msg.error(bb.msg.domain.Util, "(file: '%s', lineno: %s, function: %s)" % (tbextract[level+1][0], tbextract[level+1][1], tbextract[level+1][2])) 387 logger.error("(file: '%s', lineno: %s, function: %s)" % (tbextract[level+1][0], tbextract[level+1][1], tbextract[level+1][2]))
383 else: 388 else:
384 break 389 break
385 nexttb = tb.tb_next 390 nexttb = tb.tb_next
@@ -400,11 +405,11 @@ def lockfile(name):
400 """ 405 """
401 path = os.path.dirname(name) 406 path = os.path.dirname(name)
402 if not os.path.isdir(path): 407 if not os.path.isdir(path):
403 bb.msg.error(bb.msg.domain.Util, "Error, lockfile path does not exist!: %s" % path) 408 logger.error("Lockfile path '%s' does not exist", path)
404 sys.exit(1) 409 sys.exit(1)
405 410
406 if not os.access(path, os.W_OK): 411 if not os.access(path, os.W_OK):
407 bb.msg.error(bb.msg.domain.Util, "Error, lockfile path is not writable!: %s" % path) 412 logger.error("Error, lockfile path is not writable!: %s" % path)
408 sys.exit(1) 413 sys.exit(1)
409 414
410 while True: 415 while True:
@@ -534,7 +539,7 @@ def filter_environment(good_vars):
534 del os.environ[key] 539 del os.environ[key]
535 540
536 if len(removed_vars): 541 if len(removed_vars):
537 bb.msg.debug(1, bb.msg.domain.Util, "Removed the following variables from the environment: %s" % (", ".join(removed_vars))) 542 logger.debug(1, "Removed the following variables from the environment: %s", ", ".join(removed_vars))
538 543
539 return removed_vars 544 return removed_vars
540 545
@@ -604,10 +609,10 @@ def mkdirhier(dir):
604 directory already exists like os.makedirs 609 directory already exists like os.makedirs
605 """ 610 """
606 611
607 bb.msg.debug(3, bb.msg.domain.Util, "mkdirhier(%s)" % dir) 612 logger.debug(3, "mkdirhier(%s)", dir)
608 try: 613 try:
609 os.makedirs(dir) 614 os.makedirs(dir)
610 bb.msg.debug(2, bb.msg.domain.Util, "created " + dir) 615 logger.debug(2, "created " + dir)
611 except OSError as e: 616 except OSError as e:
612 if e.errno != errno.EEXIST: 617 if e.errno != errno.EEXIST:
613 raise e 618 raise e