diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-06-08 09:34:12 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-06-08 11:37:26 +0100 |
commit | cd3c4292e7ccc8934f229fcf010f8615398b87b5 (patch) | |
tree | 0c9cbf81048e4b44bc613f78cd6d59f0d9400b2e /bitbake/lib/bb/server | |
parent | e386fe4542865119ae7e1574e260c037e926239e (diff) | |
download | poky-cd3c4292e7ccc8934f229fcf010f8615398b87b5.tar.gz |
bitbake: Cleanup bitbake server init process to be clearer to follow
Create a standard format server class instance with method calls
for each step in the server setup. There should be enough hooks
for each of the different server types.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/server')
-rw-r--r-- | bitbake/lib/bb/server/none.py | 59 | ||||
-rw-r--r-- | bitbake/lib/bb/server/xmlrpc.py | 50 |
2 files changed, 72 insertions, 37 deletions
diff --git a/bitbake/lib/bb/server/none.py b/bitbake/lib/bb/server/none.py index 45cda2f5f4..6083631fe7 100644 --- a/bitbake/lib/bb/server/none.py +++ b/bitbake/lib/bb/server/none.py | |||
@@ -36,8 +36,7 @@ DEBUG = False | |||
36 | import inspect, select | 36 | import inspect, select |
37 | 37 | ||
38 | class BitBakeServerCommands(): | 38 | class BitBakeServerCommands(): |
39 | def __init__(self, server, cooker): | 39 | def __init__(self, server): |
40 | self.cooker = cooker | ||
41 | self.server = server | 40 | self.server = server |
42 | 41 | ||
43 | def runCommand(self, command): | 42 | def runCommand(self, command): |
@@ -106,13 +105,17 @@ class BBUIEventQueue: | |||
106 | def chldhandler(signum, stackframe): | 105 | def chldhandler(signum, stackframe): |
107 | pass | 106 | pass |
108 | 107 | ||
109 | class BitBakeServer(): | 108 | class BitBakeNoneServer(): |
110 | # remove this when you're done with debugging | 109 | # remove this when you're done with debugging |
111 | # allow_reuse_address = True | 110 | # allow_reuse_address = True |
112 | 111 | ||
113 | def __init__(self, cooker): | 112 | def __init__(self): |
114 | self._idlefuns = {} | 113 | self._idlefuns = {} |
115 | self.commands = BitBakeServerCommands(self, cooker) | 114 | self.commands = BitBakeServerCommands(self) |
115 | |||
116 | def addcooker(self, cooker): | ||
117 | self.cooker = cooker | ||
118 | self.commands.cooker = cooker | ||
116 | 119 | ||
117 | def register_idle_function(self, function, data): | 120 | def register_idle_function(self, function, data): |
118 | """Register a function to be called while the server is idle""" | 121 | """Register a function to be called while the server is idle""" |
@@ -157,25 +160,10 @@ class BitBakeServer(): | |||
157 | except: | 160 | except: |
158 | pass | 161 | pass |
159 | 162 | ||
160 | class BitbakeServerInfo(): | ||
161 | def __init__(self, server): | ||
162 | self.server = server | ||
163 | self.commands = server.commands | ||
164 | |||
165 | class BitBakeServerFork(): | ||
166 | def __init__(self, cooker, server, serverinfo, logfile): | ||
167 | serverinfo.logfile = logfile | ||
168 | serverinfo.cooker = cooker | ||
169 | serverinfo.server = server | ||
170 | |||
171 | class BitbakeUILauch(): | ||
172 | def launch(self, serverinfo, uifunc, *args): | ||
173 | return bb.cooker.server_main(serverinfo.cooker, uifunc, *args) | ||
174 | |||
175 | class BitBakeServerConnection(): | 163 | class BitBakeServerConnection(): |
176 | def __init__(self, serverinfo): | 164 | def __init__(self, server): |
177 | self.server = serverinfo.server | 165 | self.server = server.server |
178 | self.connection = serverinfo.commands | 166 | self.connection = self.server.commands |
179 | self.events = bb.server.none.BBUIEventQueue(self.server) | 167 | self.events = bb.server.none.BBUIEventQueue(self.server) |
180 | for event in bb.event.ui_queue: | 168 | for event in bb.event.ui_queue: |
181 | self.events.queue_event(event) | 169 | self.events.queue_event(event) |
@@ -189,3 +177,28 @@ class BitBakeServerConnection(): | |||
189 | self.connection.terminateServer() | 177 | self.connection.terminateServer() |
190 | except: | 178 | except: |
191 | pass | 179 | pass |
180 | |||
181 | class BitBakeServer(object): | ||
182 | def initServer(self): | ||
183 | self.server = BitBakeNoneServer() | ||
184 | |||
185 | def addcooker(self, cooker): | ||
186 | self.cooker = cooker | ||
187 | self.server.addcooker(cooker) | ||
188 | |||
189 | def getServerIdleCB(self): | ||
190 | return self.server.register_idle_function | ||
191 | |||
192 | def saveConnectionDetails(self): | ||
193 | return | ||
194 | |||
195 | def detach(self, cooker_logfile): | ||
196 | self.logfile = cooker_logfile | ||
197 | |||
198 | def establishConnection(self): | ||
199 | self.connection = BitBakeServerConnection(self) | ||
200 | return self.connection | ||
201 | |||
202 | def launchUI(self, uifunc, *args): | ||
203 | return bb.cooker.server_main(self.cooker, uifunc, *args) | ||
204 | |||
diff --git a/bitbake/lib/bb/server/xmlrpc.py b/bitbake/lib/bb/server/xmlrpc.py index e7b6010874..4a16f9d525 100644 --- a/bitbake/lib/bb/server/xmlrpc.py +++ b/bitbake/lib/bb/server/xmlrpc.py | |||
@@ -122,8 +122,7 @@ def _create_server(host, port): | |||
122 | return s | 122 | return s |
123 | 123 | ||
124 | class BitBakeServerCommands(): | 124 | class BitBakeServerCommands(): |
125 | def __init__(self, server, cooker): | 125 | def __init__(self, server): |
126 | self.cooker = cooker | ||
127 | self.server = server | 126 | self.server = server |
128 | 127 | ||
129 | def registerEventHandler(self, host, port): | 128 | def registerEventHandler(self, host, port): |
@@ -160,11 +159,11 @@ class BitBakeServerCommands(): | |||
160 | """ | 159 | """ |
161 | return True | 160 | return True |
162 | 161 | ||
163 | class BitBakeServer(SimpleXMLRPCServer): | 162 | class BitBakeXMLRPCServer(SimpleXMLRPCServer): |
164 | # remove this when you're done with debugging | 163 | # remove this when you're done with debugging |
165 | # allow_reuse_address = True | 164 | # allow_reuse_address = True |
166 | 165 | ||
167 | def __init__(self, cooker, interface = ("localhost", 0)): | 166 | def __init__(self, interface = ("localhost", 0)): |
168 | """ | 167 | """ |
169 | Constructor | 168 | Constructor |
170 | """ | 169 | """ |
@@ -174,9 +173,12 @@ class BitBakeServer(SimpleXMLRPCServer): | |||
174 | self._idlefuns = {} | 173 | self._idlefuns = {} |
175 | self.host, self.port = self.socket.getsockname() | 174 | self.host, self.port = self.socket.getsockname() |
176 | #self.register_introspection_functions() | 175 | #self.register_introspection_functions() |
177 | commands = BitBakeServerCommands(self, cooker) | 176 | self.commands = BitBakeServerCommands(self) |
178 | self.autoregister_all_functions(commands, "") | 177 | self.autoregister_all_functions(self.commands, "") |
178 | |||
179 | def addcooker(self, cooker): | ||
179 | self.cooker = cooker | 180 | self.cooker = cooker |
181 | self.commands.cooker = cooker | ||
180 | 182 | ||
181 | def autoregister_all_functions(self, context, prefix): | 183 | def autoregister_all_functions(self, context, prefix): |
182 | """ | 184 | """ |
@@ -244,14 +246,6 @@ class BitbakeServerInfo(): | |||
244 | self.host = server.host | 246 | self.host = server.host |
245 | self.port = server.port | 247 | self.port = server.port |
246 | 248 | ||
247 | class BitBakeServerFork(): | ||
248 | def __init__(self, cooker, server, serverinfo, logfile): | ||
249 | daemonize.createDaemon(server.serve_forever, logfile) | ||
250 | |||
251 | class BitbakeUILauch(): | ||
252 | def launch(self, serverinfo, uifunc, *args): | ||
253 | return uifunc(*args) | ||
254 | |||
255 | class BitBakeServerConnection(): | 249 | class BitBakeServerConnection(): |
256 | def __init__(self, serverinfo): | 250 | def __init__(self, serverinfo): |
257 | self.connection = _create_server(serverinfo.host, serverinfo.port) | 251 | self.connection = _create_server(serverinfo.host, serverinfo.port) |
@@ -271,3 +265,31 @@ class BitBakeServerConnection(): | |||
271 | self.connection.terminateServer() | 265 | self.connection.terminateServer() |
272 | except: | 266 | except: |
273 | pass | 267 | pass |
268 | |||
269 | class BitBakeServer(object): | ||
270 | def initServer(self): | ||
271 | self.server = BitBakeXMLRPCServer() | ||
272 | |||
273 | def addcooker(self, cooker): | ||
274 | self.cooker = cooker | ||
275 | self.server.addcooker(cooker) | ||
276 | |||
277 | def getServerIdleCB(self): | ||
278 | return self.server.register_idle_function | ||
279 | |||
280 | def saveConnectionDetails(self): | ||
281 | self.serverinfo = BitbakeServerInfo(self.server) | ||
282 | |||
283 | def detach(self, cooker_logfile): | ||
284 | daemonize.createDaemon(self.server.serve_forever, cooker_logfile) | ||
285 | del self.cooker | ||
286 | del self.server | ||
287 | |||
288 | def establishConnection(self): | ||
289 | self.connection = BitBakeServerConnection(self.serverinfo) | ||
290 | return self.connection | ||
291 | |||
292 | def launchUI(self, uifunc, *args): | ||
293 | return uifunc(*args) | ||
294 | |||
295 | |||