2 # ex:ts=4:sw=4:sts=4:et
3 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
5 BitBake 'Event' implementation
7 Classes and functions for manipulating 'events' in the
10 Copyright (C) 2003, 2004 Chris Larson
12 This program is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free Software
14 Foundation; either version 2 of the License, or (at your option) any later
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place, Suite 330, Boston, MA 02111-1307 USA.
30 """Base class for events"""
33 def __init__(self, d = bb.data.init()):
39 def setData(self, data):
42 data = property(getData, setData, None, "data property")
48 def tmpHandler(event):
49 """Default handler for code events"""
52 def defaultTmpHandler():
53 tmp = "def tmpHandler(e):\n\t\"\"\"heh\"\"\"\n\treturn NotHandled"
54 comp = compile(tmp, "tmpHandler(e)", "exec")
58 """Fire off an Event"""
60 if type(h).__name__ == "code":
62 if tmpHandler(event) == Handled:
65 if h(event) == Handled:
69 def register(handler):
70 """Register an Event handler"""
71 if handler is not None:
72 # handle string containing python code
73 if type(handler).__name__ == "str":
74 return _registerCode(handler)
75 # prevent duplicate registration
76 if not handler in handlers:
77 handlers.append(handler)
79 def _registerCode(handlerStr):
80 """Register a 'code' Event.
81 Deprecated interface; call register instead.
83 Expects to be passed python code as a string, which will
84 be passed in turn to compile() and then exec(). Note that
85 the code will be within a function, so should have had
86 appropriate tabbing put in place."""
87 tmp = "def tmpHandler(e):\n%s" % handlerStr
88 comp = compile(tmp, "tmpHandler(e)", "exec")
89 # prevent duplicate registration
90 if not comp in handlers:
94 """Remove an Event handler"""
96 if type(handler).__name__ == "str":
97 return _removeCode(handler)
100 handlers.remove(handler)
102 def _removeCode(handlerStr):
103 """Remove a 'code' Event handler
104 Deprecated interface; call remove instead."""
105 tmp = "def tmpHandler(e):\n%s" % handlerStr
106 comp = compile(tmp, "tmpHandler(e)", "exec")
107 handlers.remove(comp)
110 """Returns the name of a class or class instance"""
111 if getattr(e, "__name__", None) == None:
112 return e.__class__.__name__
117 class PkgBase(Event):
118 """Base class for package events"""
120 def __init__(self, t, d = bb.data.init()):
122 Event.__init__(self, d)
127 def setPkg(self, pkg):
130 pkg = property(getPkg, setPkg, None, "pkg property")
133 class BuildBase(Event):
134 """Base class for bbmake run events"""
136 def __init__(self, n, p, c, failures = 0):
139 Event.__init__(self, c)
140 self._failures = failures
145 def setPkgs(self, pkgs):
151 def setName(self, name):
157 def setCfg(self, cfg):
160 def getFailures(self):
162 Return the number of failed packages
164 return self._failures
166 pkgs = property(getPkgs, setPkgs, None, "pkgs property")
167 name = property(getName, setName, None, "name property")
168 cfg = property(getCfg, setCfg, None, "cfg property")
171 class DepBase(PkgBase):
172 """Base class for dependency events"""
174 def __init__(self, t, data, d):
176 PkgBase.__init__(self, t, data)
181 def setDep(self, dep):
184 dep = property(getDep, setDep, None, "dep property")
187 class PkgStarted(PkgBase):
188 """Package build started"""
191 class PkgFailed(PkgBase):
192 """Package build failed"""
195 class PkgSucceeded(PkgBase):
196 """Package build completed"""
199 class BuildStarted(BuildBase):
200 """bbmake build run started"""
203 class BuildCompleted(BuildBase):
204 """bbmake build run completed"""
207 class UnsatisfiedDep(DepBase):
208 """Unsatisfied Dependency"""
211 class RecursiveDep(DepBase):
212 """Recursive Dependency"""
215 class MultipleProviders(Event):
216 """Multiple Providers"""
218 def __init__(self, item, candidates, data, runtime = False):
219 Event.__init__(self, data)
221 self._candidates = candidates
222 self._is_runtime = runtime
226 Is this a runtime issue?
228 return self._is_runtime
232 The name for the to be build item
236 def getCandidates(self):
238 Get the possible Candidates for a PROVIDER.
240 return self._candidates