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")
50 def tmpHandler(event):
51 """Default handler for code events"""
54 def defaultTmpHandler():
55 tmp = "def tmpHandler(e):\n\t\"\"\"heh\"\"\"\n\treturn NotHandled"
56 comp = bb.utils.better_compile(tmp, "tmpHandler(e)", "bb.event.defaultTmpHandler")
60 """Fire off an Event"""
62 if type(h).__name__ == "code":
64 if tmpHandler(event) == Handled:
67 if h(event) == Handled:
71 def register(name, handler):
72 """Register an Event handler"""
75 if name in _handlers_dict:
78 if handler is not None:
79 # handle string containing python code
80 if type(handler).__name__ == "str":
81 _registerCode(handler)
83 _handlers.append(handler)
85 _handlers_dict[name] = 1
87 def _registerCode(handlerStr):
88 """Register a 'code' Event.
89 Deprecated interface; call register instead.
91 Expects to be passed python code as a string, which will
92 be passed in turn to compile() and then exec(). Note that
93 the code will be within a function, so should have had
94 appropriate tabbing put in place."""
95 tmp = "def tmpHandler(e):\n%s" % handlerStr
96 comp = bb.utils.better_compile(tmp, "tmpHandler(e)", "bb.event._registerCode")
97 # prevent duplicate registration
98 _handlers.append(comp)
100 def remove(name, handler):
101 """Remove an Event handler"""
103 _handlers_dict.pop(name)
104 if type(handler).__name__ == "str":
105 return _removeCode(handler)
107 _handlers.remove(handler)
109 def _removeCode(handlerStr):
110 """Remove a 'code' Event handler
111 Deprecated interface; call remove instead."""
112 tmp = "def tmpHandler(e):\n%s" % handlerStr
113 comp = bb.utils.better_compile(tmp, "tmpHandler(e)", "bb.event._removeCode")
114 _handlers.remove(comp)
117 """Returns the name of a class or class instance"""
118 if getattr(e, "__name__", None) == None:
119 return e.__class__.__name__
124 class PkgBase(Event):
125 """Base class for package events"""
127 def __init__(self, t, d = bb.data.init()):
129 Event.__init__(self, d)
134 def setPkg(self, pkg):
137 pkg = property(getPkg, setPkg, None, "pkg property")
140 class BuildBase(Event):
141 """Base class for bbmake run events"""
143 def __init__(self, n, p, c, failures = 0):
146 Event.__init__(self, c)
147 self._failures = failures
152 def setPkgs(self, pkgs):
158 def setName(self, name):
164 def setCfg(self, cfg):
167 def getFailures(self):
169 Return the number of failed packages
171 return self._failures
173 pkgs = property(getPkgs, setPkgs, None, "pkgs property")
174 name = property(getName, setName, None, "name property")
175 cfg = property(getCfg, setCfg, None, "cfg property")
178 class DepBase(PkgBase):
179 """Base class for dependency events"""
181 def __init__(self, t, data, d):
183 PkgBase.__init__(self, t, data)
188 def setDep(self, dep):
191 dep = property(getDep, setDep, None, "dep property")
194 class PkgStarted(PkgBase):
195 """Package build started"""
198 class PkgFailed(PkgBase):
199 """Package build failed"""
202 class PkgSucceeded(PkgBase):
203 """Package build completed"""
206 class BuildStarted(BuildBase):
207 """bbmake build run started"""
210 class BuildCompleted(BuildBase):
211 """bbmake build run completed"""
214 class UnsatisfiedDep(DepBase):
215 """Unsatisfied Dependency"""
218 class RecursiveDep(DepBase):
219 """Recursive Dependency"""
221 class NoProvider(Event):
222 """No Provider for an Event"""
224 def __init__(self, item, data,runtime=False):
225 Event.__init__(self, data)
227 self._runtime = runtime
235 class MultipleProviders(Event):
236 """Multiple Providers"""
238 def __init__(self, item, candidates, data, runtime = False):
239 Event.__init__(self, data)
241 self._candidates = candidates
242 self._is_runtime = runtime
246 Is this a runtime issue?
248 return self._is_runtime
252 The name for the to be build item
256 def getCandidates(self):
258 Get the possible Candidates for a PROVIDER.
260 return self._candidates