summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/tinfoil.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/tinfoil.py')
-rw-r--r--bitbake/lib/bb/tinfoil.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tinfoil.py b/bitbake/lib/bb/tinfoil.py
new file mode 100644
index 0000000000..73d8fe92a8
--- /dev/null
+++ b/bitbake/lib/bb/tinfoil.py
@@ -0,0 +1,98 @@
1# tinfoil: a simple wrapper around cooker for bitbake-based command-line utilities
2#
3# Copyright (C) 2012 Intel Corporation
4# Copyright (C) 2011 Mentor Graphics Corporation
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License version 2 as
8# published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19import logging
20import warnings
21import os
22import sys
23
24import bb.cache
25import bb.cooker
26import bb.providers
27import bb.utils
28from bb.cooker import state
29import bb.fetch2
30
31class Tinfoil:
32 def __init__(self):
33 # Needed to avoid deprecation warnings with python 2.6
34 warnings.filterwarnings("ignore", category=DeprecationWarning)
35
36 # Set up logging
37 self.logger = logging.getLogger('BitBake')
38 console = logging.StreamHandler(sys.stdout)
39 format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
40 bb.msg.addDefaultlogFilter(console)
41 console.setFormatter(format)
42 self.logger.addHandler(console)
43
44 initialenv = os.environ.copy()
45 bb.utils.clean_environment()
46 self.config = TinfoilConfig(parse_only=True)
47 self.cooker = bb.cooker.BBCooker(self.config,
48 self.register_idle_function,
49 initialenv)
50 self.config_data = self.cooker.configuration.data
51 bb.providers.logger.setLevel(logging.ERROR)
52 self.cooker_data = None
53
54 def register_idle_function(self, function, data):
55 pass
56
57 def parseRecipes(self):
58 sys.stderr.write("Parsing recipes..")
59 self.logger.setLevel(logging.WARNING)
60
61 try:
62 while self.cooker.state in (state.initial, state.parsing):
63 self.cooker.updateCache()
64 except KeyboardInterrupt:
65 self.cooker.shutdown()
66 self.cooker.updateCache()
67 sys.exit(2)
68
69 self.logger.setLevel(logging.INFO)
70 sys.stderr.write("done.\n")
71
72 self.cooker_data = self.cooker.status
73
74 def prepare(self, config_only = False):
75 if not self.cooker_data:
76 if config_only:
77 self.cooker.parseConfiguration()
78 self.cooker_data = self.cooker.status
79 else:
80 self.parseRecipes()
81
82
83class TinfoilConfig(object):
84 def __init__(self, **options):
85 self.pkgs_to_build = []
86 self.debug_domains = []
87 self.extra_assume_provided = []
88 self.prefile = []
89 self.postfile = []
90 self.debug = 0
91 self.__dict__.update(options)
92
93 def __getattr__(self, attribute):
94 try:
95 return super(TinfoilConfig, self).__getattribute__(attribute)
96 except AttributeError:
97 return None
98