diff options
Diffstat (limited to 'bitbake-dev/lib/bb/event.py')
-rw-r--r-- | bitbake-dev/lib/bb/event.py | 302 |
1 files changed, 302 insertions, 0 deletions
diff --git a/bitbake-dev/lib/bb/event.py b/bitbake-dev/lib/bb/event.py new file mode 100644 index 0000000000..c13a0127a5 --- /dev/null +++ b/bitbake-dev/lib/bb/event.py | |||
@@ -0,0 +1,302 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | ||
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
3 | """ | ||
4 | BitBake 'Event' implementation | ||
5 | |||
6 | Classes and functions for manipulating 'events' in the | ||
7 | BitBake build tools. | ||
8 | """ | ||
9 | |||
10 | # Copyright (C) 2003, 2004 Chris Larson | ||
11 | # | ||
12 | # This program is free software; you can redistribute it and/or modify | ||
13 | # it under the terms of the GNU General Public License version 2 as | ||
14 | # published by the Free Software Foundation. | ||
15 | # | ||
16 | # This program is distributed in the hope that it will be useful, | ||
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | # GNU General Public License for more details. | ||
20 | # | ||
21 | # You should have received a copy of the GNU General Public License along | ||
22 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
23 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
24 | |||
25 | import os, re | ||
26 | import bb.utils | ||
27 | |||
28 | class Event: | ||
29 | """Base class for events""" | ||
30 | type = "Event" | ||
31 | |||
32 | def __init__(self, d): | ||
33 | self._data = d | ||
34 | |||
35 | def getData(self): | ||
36 | return self._data | ||
37 | |||
38 | def setData(self, data): | ||
39 | self._data = data | ||
40 | |||
41 | data = property(getData, setData, None, "data property") | ||
42 | |||
43 | NotHandled = 0 | ||
44 | Handled = 1 | ||
45 | |||
46 | Registered = 10 | ||
47 | AlreadyRegistered = 14 | ||
48 | |||
49 | # Internal | ||
50 | _handlers = {} | ||
51 | _ui_handlers = {} | ||
52 | _ui_handler_seq = 0 | ||
53 | |||
54 | def fire(event): | ||
55 | """Fire off an Event""" | ||
56 | |||
57 | for handler in _handlers: | ||
58 | h = _handlers[handler] | ||
59 | if type(h).__name__ == "code": | ||
60 | exec(h) | ||
61 | tmpHandler(event) | ||
62 | else: | ||
63 | h(event) | ||
64 | |||
65 | # Remove the event data elements for UI handlers - too much data otherwise | ||
66 | # They can request data if they need it | ||
67 | event.data = None | ||
68 | event._data = None | ||
69 | |||
70 | errors = [] | ||
71 | for h in _ui_handlers: | ||
72 | #print "Sending event %s" % event | ||
73 | classid = "%s.%s" % (event.__class__.__module__, event.__class__.__name__) | ||
74 | try: | ||
75 | _ui_handlers[h].event.send((classid, event)) | ||
76 | except: | ||
77 | errors.append(h) | ||
78 | for h in errors: | ||
79 | del _ui_handlers[h] | ||
80 | |||
81 | def register(name, handler): | ||
82 | """Register an Event handler""" | ||
83 | |||
84 | # already registered | ||
85 | if name in _handlers: | ||
86 | return AlreadyRegistered | ||
87 | |||
88 | if handler is not None: | ||
89 | # handle string containing python code | ||
90 | if type(handler).__name__ == "str": | ||
91 | tmp = "def tmpHandler(e):\n%s" % handler | ||
92 | comp = bb.utils.better_compile(tmp, "tmpHandler(e)", "bb.event._registerCode") | ||
93 | _handlers[name] = comp | ||
94 | else: | ||
95 | _handlers[name] = handler | ||
96 | |||
97 | return Registered | ||
98 | |||
99 | def remove(name, handler): | ||
100 | """Remove an Event handler""" | ||
101 | _handlers.pop(name) | ||
102 | |||
103 | def register_UIHhandler(handler): | ||
104 | bb.event._ui_handler_seq = bb.event._ui_handler_seq + 1 | ||
105 | _ui_handlers[_ui_handler_seq] = handler | ||
106 | return _ui_handler_seq | ||
107 | |||
108 | def unregister_UIHhandler(handlerNum): | ||
109 | if handlerNum in _ui_handlers: | ||
110 | del _ui_handlers[handlerNum] | ||
111 | return | ||
112 | |||
113 | def getName(e): | ||
114 | """Returns the name of a class or class instance""" | ||
115 | if getattr(e, "__name__", None) == None: | ||
116 | return e.__class__.__name__ | ||
117 | else: | ||
118 | return e.__name__ | ||
119 | |||
120 | class ConfigParsed(Event): | ||
121 | """Configuration Parsing Complete""" | ||
122 | |||
123 | class StampUpdate(Event): | ||
124 | """Trigger for any adjustment of the stamp files to happen""" | ||
125 | |||
126 | def __init__(self, targets, stampfns, d): | ||
127 | self._targets = targets | ||
128 | self._stampfns = stampfns | ||
129 | Event.__init__(self, d) | ||
130 | |||
131 | def getStampPrefix(self): | ||
132 | return self._stampfns | ||
133 | |||
134 | def getTargets(self): | ||
135 | return self._targets | ||
136 | |||
137 | stampPrefix = property(getStampPrefix) | ||
138 | targets = property(getTargets) | ||
139 | |||
140 | class PkgBase(Event): | ||
141 | """Base class for package events""" | ||
142 | |||
143 | def __init__(self, t, d): | ||
144 | self._pkg = t | ||
145 | Event.__init__(self, d) | ||
146 | self._message = "package %s: %s" % (bb.data.getVar("P", d, 1), getName(self)[3:]) | ||
147 | |||
148 | def getPkg(self): | ||
149 | return self._pkg | ||
150 | |||
151 | def setPkg(self, pkg): | ||
152 | self._pkg = pkg | ||
153 | |||
154 | pkg = property(getPkg, setPkg, None, "pkg property") | ||
155 | |||
156 | |||
157 | class BuildBase(Event): | ||
158 | """Base class for bbmake run events""" | ||
159 | |||
160 | def __init__(self, n, p, c, failures = 0): | ||
161 | self._name = n | ||
162 | self._pkgs = p | ||
163 | Event.__init__(self, c) | ||
164 | self._failures = failures | ||
165 | |||
166 | def getPkgs(self): | ||
167 | return self._pkgs | ||
168 | |||
169 | def setPkgs(self, pkgs): | ||
170 | self._pkgs = pkgs | ||
171 | |||
172 | def getName(self): | ||
173 | return self._name | ||
174 | |||
175 | def setName(self, name): | ||
176 | self._name = name | ||
177 | |||
178 | def getCfg(self): | ||
179 | return self.data | ||
180 | |||
181 | def setCfg(self, cfg): | ||
182 | self.data = cfg | ||
183 | |||
184 | def getFailures(self): | ||
185 | """ | ||
186 | Return the number of failed packages | ||
187 | """ | ||
188 | return self._failures | ||
189 | |||
190 | pkgs = property(getPkgs, setPkgs, None, "pkgs property") | ||
191 | name = property(getName, setName, None, "name property") | ||
192 | cfg = property(getCfg, setCfg, None, "cfg property") | ||
193 | |||
194 | |||
195 | class DepBase(PkgBase): | ||
196 | """Base class for dependency events""" | ||
197 | |||
198 | def __init__(self, t, data, d): | ||
199 | self._dep = d | ||
200 | PkgBase.__init__(self, t, data) | ||
201 | |||
202 | def getDep(self): | ||
203 | return self._dep | ||
204 | |||
205 | def setDep(self, dep): | ||
206 | self._dep = dep | ||
207 | |||
208 | dep = property(getDep, setDep, None, "dep property") | ||
209 | |||
210 | |||
211 | class PkgStarted(PkgBase): | ||
212 | """Package build started""" | ||
213 | |||
214 | |||
215 | class PkgFailed(PkgBase): | ||
216 | """Package build failed""" | ||
217 | |||
218 | |||
219 | class PkgSucceeded(PkgBase): | ||
220 | """Package build completed""" | ||
221 | |||
222 | |||
223 | class BuildStarted(BuildBase): | ||
224 | """bbmake build run started""" | ||
225 | |||
226 | |||
227 | class BuildCompleted(BuildBase): | ||
228 | """bbmake build run completed""" | ||
229 | |||
230 | |||
231 | class UnsatisfiedDep(DepBase): | ||
232 | """Unsatisfied Dependency""" | ||
233 | |||
234 | |||
235 | class RecursiveDep(DepBase): | ||
236 | """Recursive Dependency""" | ||
237 | |||
238 | class NoProvider(Event): | ||
239 | """No Provider for an Event""" | ||
240 | |||
241 | def __init__(self, item, data, runtime=False): | ||
242 | Event.__init__(self, data) | ||
243 | self._item = item | ||
244 | self._runtime = runtime | ||
245 | |||
246 | def getItem(self): | ||
247 | return self._item | ||
248 | |||
249 | def isRuntime(self): | ||
250 | return self._runtime | ||
251 | |||
252 | class MultipleProviders(Event): | ||
253 | """Multiple Providers""" | ||
254 | |||
255 | def __init__(self, item, candidates, data, runtime = False): | ||
256 | Event.__init__(self, data) | ||
257 | self._item = item | ||
258 | self._candidates = candidates | ||
259 | self._is_runtime = runtime | ||
260 | |||
261 | def isRuntime(self): | ||
262 | """ | ||
263 | Is this a runtime issue? | ||
264 | """ | ||
265 | return self._is_runtime | ||
266 | |||
267 | def getItem(self): | ||
268 | """ | ||
269 | The name for the to be build item | ||
270 | """ | ||
271 | return self._item | ||
272 | |||
273 | def getCandidates(self): | ||
274 | """ | ||
275 | Get the possible Candidates for a PROVIDER. | ||
276 | """ | ||
277 | return self._candidates | ||
278 | |||
279 | class ParseProgress(Event): | ||
280 | """ | ||
281 | Parsing Progress Event | ||
282 | """ | ||
283 | |||
284 | def __init__(self, d, cached, parsed, skipped, masked, errors, total): | ||
285 | Event.__init__(self, d) | ||
286 | self.cached = cached | ||
287 | self.parsed = parsed | ||
288 | self.skipped = skipped | ||
289 | self.masked = masked | ||
290 | self.errors = errors | ||
291 | self.sofar = cached + parsed + skipped | ||
292 | self.total = total | ||
293 | |||
294 | class DepTreeGenerated(Event): | ||
295 | """ | ||
296 | Event when a dependency tree has been generated | ||
297 | """ | ||
298 | |||
299 | def __init__(self, d, depgraph): | ||
300 | Event.__init__(self, d) | ||
301 | self._depgraph = depgraph | ||
302 | |||