diff options
Diffstat (limited to 'lib/bb')
-rw-r--r-- | lib/bb/__init__.py | 22 | ||||
-rw-r--r-- | lib/bb/build.py | 10 | ||||
-rw-r--r-- | lib/bb/msg.py | 84 | ||||
-rw-r--r-- | lib/bb/providers.py | 13 | ||||
-rw-r--r-- | lib/bb/shell.py | 4 | ||||
-rw-r--r-- | lib/bb/utils.py | 40 |
6 files changed, 144 insertions, 29 deletions
diff --git a/lib/bb/__init__.py b/lib/bb/__init__.py index 8d825dbe8..46043239f 100644 --- a/lib/bb/__init__.py +++ b/lib/bb/__init__.py @@ -69,19 +69,16 @@ __all__ = [ whitespace = '\t\n\x0b\x0c\r ' lowercase = 'abcdefghijklmnopqrstuvwxyz' -import sys, os, types, re, string +import sys, os, types, re, string, bb +from bb import msg #projectdir = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) projectdir = os.getcwd() -debug_level = 0 - if "BBDEBUG" in os.environ: level = int(os.environ["BBDEBUG"]) if level: - debug_level = level - else: - debug_level = 0 + bb.msg.set_debug_level(level) class VarExpandError(Exception): pass @@ -100,22 +97,17 @@ class MalformedUrl(Exception): ####################################################################### ####################################################################### -debug_prepend = '' - - def debug(lvl, *args): - if debug_level >= lvl: - print debug_prepend + 'DEBUG:', ''.join(args) + bb.msg.std_debug(lvl, ''.join(args)) def note(*args): - print debug_prepend + 'NOTE:', ''.join(args) + bb.msg.std_note(''.join(args)) def error(*args): - print debug_prepend + 'ERROR:', ''.join(args) + bb.msg.std_error(''.join(args)) def fatal(*args): - print debug_prepend + 'ERROR:', ''.join(args) - sys.exit(1) + bb.msg.std_fatal(''.join(args)) ####################################################################### diff --git a/lib/bb/build.py b/lib/bb/build.py index c8928deb1..99fb29079 100644 --- a/lib/bb/build.py +++ b/lib/bb/build.py @@ -25,7 +25,7 @@ You should have received a copy of the GNU General Public License along with Based on functions from the base bb module, Copyright 2003 Holger Schurig """ -from bb import debug, data, fetch, fatal, error, note, event, mkdirhier, utils +from bb import data, fetch, fatal, error, note, event, mkdirhier, utils import bb, os # events @@ -146,7 +146,7 @@ def exec_func_shell(func, d): f = open(runfile, "w") f.write("#!/bin/sh -e\n") - if bb.debug_level > 0: f.write("set -x\n") + if bb.msg.debug_level > 0: f.write("set -x\n") data.emit_env(f, d) f.write("cd %s\n" % os.getcwd()) @@ -160,7 +160,7 @@ def exec_func_shell(func, d): # open logs si = file('/dev/null', 'r') try: - if bb.debug_level > 0: + if bb.msg.debug_level > 0: so = os.popen("tee \"%s\"" % logfile, "w") else: so = file(logfile, 'w') @@ -208,7 +208,7 @@ def exec_func_shell(func, d): os.close(ose[0]) if ret==0: - if bb.debug_level > 0: + if bb.msg.debug_level > 0: os.remove(runfile) # os.remove(logfile) return @@ -265,7 +265,7 @@ def exec_task(task, d): return 1 try: - debug(1, "Executing task %s" % item) + bb.msg.debug(1, bb.msg.domain.Build, "Executing task %s" % item) old_overrides = data.getVar('OVERRIDES', d, 0) localdata = data.createCopy(d) data.setVar('OVERRIDES', 'task_%s:%s' % (item, old_overrides), localdata) diff --git a/lib/bb/msg.py b/lib/bb/msg.py new file mode 100644 index 000000000..1de0e4591 --- /dev/null +++ b/lib/bb/msg.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python +# 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 + +# 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 as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +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., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA. + +""" + +import os, re, bb +from bb import utils + +debug_level = 0 + +verbose = False + +domain = bb.utils.Enum('Depends', 'Provider', 'Build', 'Parsing', 'Collection') + +# +# Message control functions +# + +def set_debug_level(level): + bb.msg.debug_level = level + +def set_verbose(level): + bb.msg.verbose = level + +# +# Message handling functions +# + +def debug(level, domain, msg, fn = None): + std_debug(level, msg) + +def note(level, domain, msg, fn = None): + if level == 1 or verbose: + std_note(msg) + +def warn(domain, msg, fn = None): + std_warn(msg) + +def error(domain, msg, fn = None): + std_error(msg) + +def fatal(domain, msg, fn = None): + std_fatal(msg) + +# +# Compatibility functions for the original message interface +# +def std_debug(lvl, msg): + if debug_level >= lvl: + print 'DEBUG: ' + msg + +def std_note(msg): + print 'NOTE: ' + msg + +def std_warn(msg): + print 'WARNING: ' + msg + +def std_error(msg): + print 'ERROR: ' + msg + +def std_fatal(msg): + print 'ERROR: ' + msg + sys.exit(1) + diff --git a/lib/bb/providers.py b/lib/bb/providers.py index 10190b186..b97b3ee9d 100644 --- a/lib/bb/providers.py +++ b/lib/bb/providers.py @@ -76,9 +76,9 @@ def findBestProvider(pn, cfgData, dataCache, pkg_pn = None): else: pv_str = preferred_v if preferred_file is None: - bb.note("preferred version %s of %s not available" % (pv_str, pn)) + bb.msg.note(1, bb.msg.domain.Provider, "preferred version %s of %s not available" % (pv_str, pn)) else: - bb.debug(1, "selecting %s as PREFERRED_VERSION %s of package %s" % (preferred_file, pv_str, pn)) + bb.msg.debug(1, bb.msg.domain.Provider, "selecting %s as PREFERRED_VERSION %s of package %s" % (preferred_file, pv_str, pn)) del localdata @@ -101,7 +101,7 @@ def findBestProvider(pn, cfgData, dataCache, pkg_pn = None): return (latest,latest_f,preferred_ver, preferred_file) -def filterProviders(providers, item, cfgData, dataCache, build_cache_fail, verbose): +def filterProviders(providers, item, cfgData, dataCache, build_cache_fail): """ Take a list of providers and filter/reorder according to the environment variables and previous build results @@ -117,7 +117,7 @@ def filterProviders(providers, item, cfgData, dataCache, build_cache_fail, verbo pkg_pn[pn] = [] pkg_pn[pn].append(p) - bb.debug(1, "providers for %s are: %s" % (item, pkg_pn.keys())) + bb.msg.debug(1, bb.msg.domain.Provider, "providers for %s are: %s" % (item, pkg_pn.keys())) for pn in pkg_pn.keys(): preferred_versions[pn] = bb.providers.findBestProvider(pn, cfgData, dataCache, pkg_pn)[2:4] @@ -126,7 +126,7 @@ def filterProviders(providers, item, cfgData, dataCache, build_cache_fail, verbo for p in eligible: if p in build_cache_fail: - bb.debug(1, "rejecting already-failed %s" % p) + bb.msg.debug(1, bb.msg.domain.Provider, "rejecting already-failed %s" % p) eligible.remove(p) if len(eligible) == 0: @@ -152,8 +152,7 @@ def filterProviders(providers, item, cfgData, dataCache, build_cache_fail, verbo else: extra_chat = "Selecting already-staged %s (%s) to satisfy %s" % (pn, oldver, item) - if verbose: - bb.note("%s" % extra_chat) + bb.msg.note(2, bb.msg.domain.Provider, "%s" % extra_chat) eligible.remove(fn) eligible = [fn] + eligible discriminated = True diff --git a/lib/bb/shell.py b/lib/bb/shell.py index 5db488554..803b8f971 100644 --- a/lib/bb/shell.py +++ b/lib/bb/shell.py @@ -107,7 +107,7 @@ class BitBakeShellCommands: preferred = data.getVar( "PREFERRED_PROVIDER_%s" % item, cooker.configuration.data, 1 ) if not preferred: preferred = item try: - lv, lf, pv, pf = bb.providers.findBestProvider(preferred, cooker.configuration.data, cooker.status, cooker.build_cache_fail, cooker.configuration.verbose) + lv, lf, pv, pf = bb.providers.findBestProvider(preferred, cooker.configuration.data, cooker.status, cooker.build_cache_fail) except KeyError: if item in cooker.status.providers: pf = cooker.status.providers[item][0] @@ -537,7 +537,7 @@ SRC_URI = "" if not preferred: preferred = item try: - lv, lf, pv, pf = bb.providers.findBestProvider(preferred, cooker.configuration.data, cooker.status, cooker.build_cache_fail, cooker.configuration.verbose) + lv, lf, pv, pf = bb.providers.findBestProvider(preferred, cooker.configuration.data, cooker.status, cooker.build_cache_fail) except KeyError: lv, lf, pv, pf = (None,)*4 diff --git a/lib/bb/utils.py b/lib/bb/utils.py index 5b3cb38d8..b63c4e530 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -160,3 +160,43 @@ def better_exec(code, context, text, realfile): _print_trace( text.split('\n'), line ) raise + +def Enum(*names): + """ + A simple class to give Enum support + """ + + assert names, "Empty enums are not supported" + + class EnumClass(object): + __slots__ = names + def __iter__(self): return iter(constants) + def __len__(self): return len(constants) + def __getitem__(self, i): return constants[i] + def __repr__(self): return 'Enum' + str(names) + def __str__(self): return 'enum ' + str(constants) + + class EnumValue(object): + __slots__ = ('__value') + def __init__(self, value): self.__value = value + Value = property(lambda self: self.__value) + EnumType = property(lambda self: EnumType) + def __hash__(self): return hash(self.__value) + def __cmp__(self, other): + # C fans might want to remove the following assertion + # to make all enums comparable by ordinal value {;)) + assert self.EnumType is other.EnumType, "Only values from the same enum are comparable" + return cmp(self.__value, other.__value) + def __invert__(self): return constants[maximum - self.__value] + def __nonzero__(self): return bool(self.__value) + def __repr__(self): return str(names[self.__value]) + + maximum = len(names) - 1 + constants = [None] * len(names) + for i, each in enumerate(names): + val = EnumValue(i) + setattr(EnumClass, each, val) + constants[i] = val + constants = tuple(constants) + EnumType = EnumClass() + return EnumType |