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 0"
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 = {}):
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):
139 Event.__init__(self, c)
144 def setPkgs(self, pkgs):
150 def setName(self, name):
156 def setCfg(self, cfg):
159 pkgs = property(getPkgs, setPkgs, None, "pkgs property")
160 name = property(getName, setName, None, "name property")
161 cfg = property(getCfg, setCfg, None, "cfg property")
164 class DepBase(PkgBase):
165 """Base class for dependency events"""
167 def __init__(self, t, data, d):
169 PkgBase.__init__(self, t, data)
174 def setDep(self, dep):
177 dep = property(getDep, setDep, None, "dep property")
180 class PkgStarted(PkgBase):
181 """Package build started"""
184 class PkgFailed(PkgBase):
185 """Package build failed"""
188 class PkgSucceeded(PkgBase):
189 """Package build completed"""
192 class BuildStarted(BuildBase):
193 """bbmake build run started"""
196 class BuildCompleted(BuildBase):
197 """bbmake build run completed"""
200 class UnsatisfiedDep(DepBase):
201 """Unsatisfied Dependency"""
204 class RecursiveDep(DepBase):
205 """Recursive Dependency"""
208 class MultipleProviders(PkgBase):
209 """Multiple Providers"""