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.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tinfoil.py b/bitbake/lib/bb/tinfoil.py
new file mode 100644
index 0000000..751a2d7
--- /dev/null
+++ b/bitbake/lib/bb/tinfoil.py
@@ -0,0 +1,96 @@
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
29from bb.cookerdata import CookerConfiguration, ConfigParameters
30import bb.fetch2
31
32class Tinfoil:
33 def __init__(self, output=sys.stdout):
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 self.cooker = BBCooker(self.config)
52 self.config_data = self.cooker.data
53 bb.providers.logger.setLevel(logging.ERROR)
54 self.cooker_data = None
55
56 def register_idle_function(self, function, data):
57 pass
58
59 def parseRecipes(self):
60 sys.stderr.write("Parsing recipes..")
61 self.logger.setLevel(logging.WARNING)
62
63 try:
64 while self.cooker.state in (state.initial, state.parsing):
65 self.cooker.updateCache()
66 except KeyboardInterrupt:
67 self.cooker.shutdown()
68 self.cooker.updateCache()
69 sys.exit(2)
70
71 self.logger.setLevel(logging.INFO)
72 sys.stderr.write("done.\n")
73
74 self.cooker_data = self.cooker.recipecache
75
76 def prepare(self, config_only = False):
77 if not self.cooker_data:
78 if config_only:
79 self.cooker.parseConfiguration()
80 self.cooker_data = self.cooker.recipecache
81 else:
82 self.parseRecipes()
83
84class TinfoilConfigParameters(ConfigParameters):
85
86 def __init__(self, **options):
87 self.initial_options = options
88 super(TinfoilConfigParameters, self).__init__()
89
90 def parseCommandLine(self):
91 class DummyOptions:
92 def __init__(self, initial_options):
93 for key, val in initial_options.items():
94 setattr(self, key, val)
95
96 return DummyOptions(self.initial_options), None