summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/event.py
diff options
context:
space:
mode:
authorRichard Purdie <richard@openedhand.com>2005-08-31 10:47:56 +0000
committerRichard Purdie <richard@openedhand.com>2005-08-31 10:47:56 +0000
commitf54da734eb7b69e8e34de505bd89a13479e230e0 (patch)
treef796bea6f5683dfe3d591ca5390d12fd78e59c96 /bitbake/lib/bb/event.py
parent4b46c1f6e891b1ddd5968536440b888661fade3e (diff)
downloadpoky-f54da734eb7b69e8e34de505bd89a13479e230e0.tar.gz
Initial population
git-svn-id: https://svn.o-hand.com/repos/poky@2 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'bitbake/lib/bb/event.py')
-rw-r--r--bitbake/lib/bb/event.py210
1 files changed, 210 insertions, 0 deletions
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py
new file mode 100644
index 0000000000..c4e88fa35d
--- /dev/null
+++ b/bitbake/lib/bb/event.py
@@ -0,0 +1,210 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4"""
5BitBake 'Event' implementation
6
7Classes and functions for manipulating 'events' in the
8BitBake build tools.
9
10Copyright (C) 2003, 2004 Chris Larson
11
12This program is free software; you can redistribute it and/or modify it under
13the terms of the GNU General Public License as published by the Free Software
14Foundation; either version 2 of the License, or (at your option) any later
15version.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23Place, Suite 330, Boston, MA 02111-1307 USA.
24"""
25
26import os, re
27import bb.data
28
29class Event:
30 """Base class for events"""
31 type = "Event"
32
33 def __init__(self, d = bb.data.init()):
34 self._data = d
35
36 def getData(self):
37 return self._data
38
39 def setData(self, data):
40 self._data = data
41
42 data = property(getData, setData, None, "data property")
43
44NotHandled = 0
45Handled = 1
46handlers = []
47
48def tmpHandler(event):
49 """Default handler for code events"""
50 return NotHandled
51
52def defaultTmpHandler():
53 tmp = "def tmpHandler(e):\n\t\"\"\"heh\"\"\"\n\treturn 0"
54 comp = compile(tmp, "tmpHandler(e)", "exec")
55 return comp
56
57def fire(event):
58 """Fire off an Event"""
59 for h in handlers:
60 if type(h).__name__ == "code":
61 exec(h)
62 if tmpHandler(event) == Handled:
63 return Handled
64 else:
65 if h(event) == Handled:
66 return Handled
67 return NotHandled
68
69def 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)
78
79def registerCode(handlerStr):
80 """Register a 'code' Event.
81 Deprecated interface; call register instead.
82
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:
91 handlers.append(comp)
92
93def remove(handler):
94 """Remove an Event handler"""
95 for h in handlers:
96 if type(handler).__name__ == "str":
97 return removeCode(handler)
98
99 if handler is h:
100 handlers.remove(handler)
101
102def 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)
108
109def getName(e):
110 """Returns the name of a class or class instance"""
111 if getattr(e, "__name__", None) == None:
112 return e.__class__.__name__
113 else:
114 return e.__name__
115
116
117class PkgBase(Event):
118 """Base class for package events"""
119
120 def __init__(self, t, d = {}):
121 self._pkg = t
122 Event.__init__(self, d)
123
124 def getPkg(self):
125 return self._pkg
126
127 def setPkg(self, pkg):
128 self._pkg = pkg
129
130 pkg = property(getPkg, setPkg, None, "pkg property")
131
132
133class BuildBase(Event):
134 """Base class for bbmake run events"""
135
136 def __init__(self, n, p, c):
137 self._name = n
138 self._pkgs = p
139 Event.__init__(self, c)
140
141 def getPkgs(self):
142 return self._pkgs
143
144 def setPkgs(self, pkgs):
145 self._pkgs = pkgs
146
147 def getName(self):
148 return self._name
149
150 def setName(self, name):
151 self._name = name
152
153 def getCfg(self):
154 return self.data
155
156 def setCfg(self, cfg):
157 self.data = cfg
158
159 pkgs = property(getPkgs, setPkgs, None, "pkgs property")
160 name = property(getName, setName, None, "name property")
161 cfg = property(getCfg, setCfg, None, "cfg property")
162
163
164class DepBase(PkgBase):
165 """Base class for dependency events"""
166
167 def __init__(self, t, data, d):
168 self._dep = d
169 PkgBase.__init__(self, t, data)
170
171 def getDep(self):
172 return self._dep
173
174 def setDep(self, dep):
175 self._dep = dep
176
177 dep = property(getDep, setDep, None, "dep property")
178
179
180class PkgStarted(PkgBase):
181 """Package build started"""
182
183
184class PkgFailed(PkgBase):
185 """Package build failed"""
186
187
188class PkgSucceeded(PkgBase):
189 """Package build completed"""
190
191
192class BuildStarted(BuildBase):
193 """bbmake build run started"""
194
195
196class BuildCompleted(BuildBase):
197 """bbmake build run completed"""
198
199
200class UnsatisfiedDep(DepBase):
201 """Unsatisfied Dependency"""
202
203
204class RecursiveDep(DepBase):
205 """Recursive Dependency"""
206
207
208class MultipleProviders(PkgBase):
209 """Multiple Providers"""
210