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.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tinfoil.py b/bitbake/lib/bb/tinfoil.py
new file mode 100644
index 0000000000..6bcbd47ab3
--- /dev/null
+++ b/bitbake/lib/bb/tinfoil.py
@@ -0,0 +1,99 @@
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, BBCooker, CookerFeatures
29from bb.cookerdata import CookerConfiguration, ConfigParameters
30import bb.fetch2
31
32class Tinfoil:
33 def __init__(self, output=sys.stdout, tracking=False):
34 # Needed to avoid deprecation warnings with python 2.6
35 warnings.filterwarnings("ignore", category=DeprecationWarning)
36
37 # Set up logging
38 self.logger = logging.getLogger('BitBake')
39 console = logging.StreamHandler(output)
40 bb.msg.addDefaultlogFilter(console)
41 format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
42 if output.isatty():
43 format.enable_color()
44 console.setFormatter(format)
45 self.logger.addHandler(console)
46
47 self.config = CookerConfiguration()
48 configparams = TinfoilConfigParameters(parse_only=True)
49 self.config.setConfigParameters(configparams)
50 self.config.setServerRegIdleCallback(self.register_idle_function)
51 features = []
52 if tracking:
53 features.append(CookerFeatures.BASEDATASTORE_TRACKING)
54 self.cooker = BBCooker(self.config, features)
55 self.config_data = self.cooker.data
56 bb.providers.logger.setLevel(logging.ERROR)
57 self.cooker_data = None
58
59 def register_idle_function(self, function, data):
60 pass
61
62 def parseRecipes(self):
63 sys.stderr.write("Parsing recipes..")
64 self.logger.setLevel(logging.WARNING)
65
66 try:
67 while self.cooker.state in (state.initial, state.parsing):
68 self.cooker.updateCache()
69 except KeyboardInterrupt:
70 self.cooker.shutdown()
71 self.cooker.updateCache()
72 sys.exit(2)
73
74 self.logger.setLevel(logging.INFO)
75 sys.stderr.write("done.\n")
76
77 self.cooker_data = self.cooker.recipecache
78
79 def prepare(self, config_only = False):
80 if not self.cooker_data:
81 if config_only:
82 self.cooker.parseConfiguration()
83 self.cooker_data = self.cooker.recipecache
84 else:
85 self.parseRecipes()
86
87class TinfoilConfigParameters(ConfigParameters):
88
89 def __init__(self, **options):
90 self.initial_options = options
91 super(TinfoilConfigParameters, self).__init__()
92
93 def parseCommandLine(self):
94 class DummyOptions:
95 def __init__(self, initial_options):
96 for key, val in initial_options.items():
97 setattr(self, key, val)
98
99 return DummyOptions(self.initial_options), None