summaryrefslogtreecommitdiffstats
path: root/bitbake-dev/lib/bb/event.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake-dev/lib/bb/event.py')
-rw-r--r--bitbake-dev/lib/bb/event.py275
1 files changed, 0 insertions, 275 deletions
diff --git a/bitbake-dev/lib/bb/event.py b/bitbake-dev/lib/bb/event.py
deleted file mode 100644
index 7251d78715..0000000000
--- a/bitbake-dev/lib/bb/event.py
+++ /dev/null
@@ -1,275 +0,0 @@
1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3"""
4BitBake 'Event' implementation
5
6Classes and functions for manipulating 'events' in the
7BitBake 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
25import os, re
26import bb.utils
27import pickle
28
29# This is the pid for which we should generate the event. This is set when
30# the runqueue forks off.
31worker_pid = 0
32worker_pipe = None
33
34class Event:
35 """Base class for events"""
36
37 def __init__(self):
38 self.pid = worker_pid
39
40NotHandled = 0
41Handled = 1
42
43Registered = 10
44AlreadyRegistered = 14
45
46# Internal
47_handlers = {}
48_ui_handlers = {}
49_ui_handler_seq = 0
50
51def fire(event, d):
52 """Fire off an Event"""
53
54 if worker_pid != 0:
55 worker_fire(event, d)
56 return
57
58 for handler in _handlers:
59 h = _handlers[handler]
60 event.data = d
61 if type(h).__name__ == "code":
62 exec(h)
63 tmpHandler(event)
64 else:
65 h(event)
66 del event.data
67
68 errors = []
69 for h in _ui_handlers:
70 #print "Sending event %s" % event
71 try:
72 # We use pickle here since it better handles object instances
73 # which xmlrpc's marshaller does not. Events *must* be serializable
74 # by pickle.
75 _ui_handlers[h].event.send((pickle.dumps(event)))
76 except:
77 errors.append(h)
78 for h in errors:
79 del _ui_handlers[h]
80
81def worker_fire(event, d):
82 data = "<event>" + pickle.dumps(event) + "</event>"
83 if os.write(worker_pipe, data) != len (data):
84 print "Error sending event to server (short write)"
85
86def fire_from_worker(event, d):
87 if not event.startswith("<event>") or not event.endswith("</event>"):
88 print "Error, not an event"
89 return
90 event = pickle.loads(event[7:-8])
91 bb.event.fire(event, d)
92
93def register(name, handler):
94 """Register an Event handler"""
95
96 # already registered
97 if name in _handlers:
98 return AlreadyRegistered
99
100 if handler is not None:
101 # handle string containing python code
102 if type(handler).__name__ == "str":
103 tmp = "def tmpHandler(e):\n%s" % handler
104 comp = bb.utils.better_compile(tmp, "tmpHandler(e)", "bb.event._registerCode")
105 _handlers[name] = comp
106 else:
107 _handlers[name] = handler
108
109 return Registered
110
111def remove(name, handler):
112 """Remove an Event handler"""
113 _handlers.pop(name)
114
115def register_UIHhandler(handler):
116 bb.event._ui_handler_seq = bb.event._ui_handler_seq + 1
117 _ui_handlers[_ui_handler_seq] = handler
118 return _ui_handler_seq
119
120def unregister_UIHhandler(handlerNum):
121 if handlerNum in _ui_handlers:
122 del _ui_handlers[handlerNum]
123 return
124
125def getName(e):
126 """Returns the name of a class or class instance"""
127 if getattr(e, "__name__", None) == None:
128 return e.__class__.__name__
129 else:
130 return e.__name__
131
132class ConfigParsed(Event):
133 """Configuration Parsing Complete"""
134
135class RecipeParsed(Event):
136 """ Recipe Parsing Complete """
137
138 def __init__(self, fn):
139 self.fn = fn
140 Event.__init__(self)
141
142class StampUpdate(Event):
143 """Trigger for any adjustment of the stamp files to happen"""
144
145 def __init__(self, targets, stampfns):
146 self._targets = targets
147 self._stampfns = stampfns
148 Event.__init__(self)
149
150 def getStampPrefix(self):
151 return self._stampfns
152
153 def getTargets(self):
154 return self._targets
155
156 stampPrefix = property(getStampPrefix)
157 targets = property(getTargets)
158
159class BuildBase(Event):
160 """Base class for bbmake run events"""
161
162 def __init__(self, n, p, failures = 0):
163 self._name = n
164 self._pkgs = p
165 Event.__init__(self)
166 self._failures = failures
167
168 def getPkgs(self):
169 return self._pkgs
170
171 def setPkgs(self, pkgs):
172 self._pkgs = pkgs
173
174 def getName(self):
175 return self._name
176
177 def setName(self, name):
178 self._name = name
179
180 def getCfg(self):
181 return self.data
182
183 def setCfg(self, cfg):
184 self.data = cfg
185
186 def getFailures(self):
187 """
188 Return the number of failed packages
189 """
190 return self._failures
191
192 pkgs = property(getPkgs, setPkgs, None, "pkgs property")
193 name = property(getName, setName, None, "name property")
194 cfg = property(getCfg, setCfg, None, "cfg property")
195
196
197
198
199
200class BuildStarted(BuildBase):
201 """bbmake build run started"""
202
203
204class BuildCompleted(BuildBase):
205 """bbmake build run completed"""
206
207
208
209
210class NoProvider(Event):
211 """No Provider for an Event"""
212
213 def __init__(self, item, runtime=False):
214 Event.__init__(self)
215 self._item = item
216 self._runtime = runtime
217
218 def getItem(self):
219 return self._item
220
221 def isRuntime(self):
222 return self._runtime
223
224class MultipleProviders(Event):
225 """Multiple Providers"""
226
227 def __init__(self, item, candidates, runtime = False):
228 Event.__init__(self)
229 self._item = item
230 self._candidates = candidates
231 self._is_runtime = runtime
232
233 def isRuntime(self):
234 """
235 Is this a runtime issue?
236 """
237 return self._is_runtime
238
239 def getItem(self):
240 """
241 The name for the to be build item
242 """
243 return self._item
244
245 def getCandidates(self):
246 """
247 Get the possible Candidates for a PROVIDER.
248 """
249 return self._candidates
250
251class ParseProgress(Event):
252 """
253 Parsing Progress Event
254 """
255
256 def __init__(self, cached, parsed, skipped, masked, virtuals, errors, total):
257 Event.__init__(self)
258 self.cached = cached
259 self.parsed = parsed
260 self.skipped = skipped
261 self.virtuals = virtuals
262 self.masked = masked
263 self.errors = errors
264 self.sofar = cached + parsed
265 self.total = total
266
267class DepTreeGenerated(Event):
268 """
269 Event when a dependency tree has been generated
270 """
271
272 def __init__(self, depgraph):
273 Event.__init__(self)
274 self._depgraph = depgraph
275