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.
31 """Base class for events"""
34 def __init__(self, d = bb.data.init()):
40 def setData(self, data):
43 data = property(getData, setData, None, "data property")
49 def tmpHandler(event):
50 """Default handler for code events"""
53 def defaultTmpHandler():
54 tmp = "def tmpHandler(e):\n\t\"\"\"heh\"\"\"\n\treturn NotHandled"
55 comp = bb.utils.better_compile(tmp, "tmpHandler(e)", "bb.event.defaultTmpHandler")
59 """Fire off an Event"""
61 if type(h).__name__ == "code":
63 if tmpHandler(event) == Handled:
66 if h(event) == Handled:
70 def register(handler):
71 """Register an Event handler"""
72 if handler is not None:
73 # handle string containing python code
74 if type(handler).__name__ == "str":
75 return _registerCode(handler)
76 # prevent duplicate registration
77 if not handler in handlers:
78 handlers.append(handler)
80 def _registerCode(handlerStr):
81 """Register a 'code' Event.
82 Deprecated interface; call register instead.
84 Expects to be passed python code as a string, which will
85 be passed in turn to compile() and then exec(). Note that
86 the code will be within a function, so should have had
87 appropriate tabbing put in place."""
88 tmp = "def tmpHandler(e):\n%s" % handlerStr
89 comp = bb.utils.better_compile(tmp, "tmpHandler(e)", "bb.event._registerCode")
90 # prevent duplicate registration
91 if not comp in handlers:
95 """Remove an Event handler"""
97 if type(handler).__name__ == "str":
98 return _removeCode(handler)
101 handlers.remove(handler)
103 def _removeCode(handlerStr):
104 """Remove a 'code' Event handler
105 Deprecated interface; call remove instead."""
106 tmp = "def tmpHandler(e):\n%s" % handlerStr
107 comp = bb.utils.better_compile(tmp, "tmpHandler(e)", "bb.event._removeCode")
108 handlers.remove(comp)
111 """Returns the name of a class or class instance"""
112 if getattr(e, "__name__", None) == None:
113 return e.__class__.__name__
118 class PkgBase(Event):
119 """Base class for package events"""
121 def __init__(self, t, d = bb.data.init()):
123 Event.__init__(self, d)
128 def setPkg(self, pkg):
131 pkg = property(getPkg, setPkg, None, "pkg property")
134 class BuildBase(Event):
135 """Base class for bbmake run events"""
137 def __init__(self, n, p, c, failures = 0):
140 Event.__init__(self, c)
141 self._failures = failures
146 def setPkgs(self, pkgs):
152 def setName(self, name):
158 def setCfg(self, cfg):
161 def getFailures(self):
163 Return the number of failed packages
165 return self._failures
167 pkgs = property(getPkgs, setPkgs, None, "pkgs property")
168 name = property(getName, setName, None, "name property")
169 cfg = property(getCfg, setCfg, None, "cfg property")
172 class DepBase(PkgBase):
173 """Base class for dependency events"""
175 def __init__(self, t, data, d):
177 PkgBase.__init__(self, t, data)
182 def setDep(self, dep):
185 dep = property(getDep, setDep, None, "dep property")
188 class PkgStarted(PkgBase):
189 """Package build started"""
192 class PkgFailed(PkgBase):
193 """Package build failed"""
196 class PkgSucceeded(PkgBase):
197 """Package build completed"""
200 class BuildStarted(BuildBase):
201 """bbmake build run started"""
204 class BuildCompleted(BuildBase):
205 """bbmake build run completed"""
208 class UnsatisfiedDep(DepBase):
209 """Unsatisfied Dependency"""
212 class RecursiveDep(DepBase):
213 """Recursive Dependency"""
216 class MultipleProviders(Event):
217 """Multiple Providers"""
219 def __init__(self, item, candidates, data, runtime = False):
220 Event.__init__(self, data)
222 self._candidates = candidates
223 self._is_runtime = runtime
227 Is this a runtime issue?
229 return self._is_runtime
233 The name for the to be build item
237 def getCandidates(self):
239 Get the possible Candidates for a PROVIDER.
241 return self._candidates