diff options
| author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-07-18 22:15:17 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-07-21 08:41:11 +0100 |
| commit | 577b75086eaf4ae2201933f7b9ac32f6239867c6 (patch) | |
| tree | 66486353161365955936a20338642c8f50dc15e8 | |
| parent | dd71707d5a5a420a4406ce88164ac2a32cc04956 (diff) | |
| download | poky-577b75086eaf4ae2201933f7b9ac32f6239867c6.tar.gz | |
bitbake: server: Remove base classes and inline code
In preparation for rewriting this code, expand the relatively useless
base classes into the code itself.
(Bitbake rev: a1c6151420d86bac658c08ae714647062edd6ef2)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | bitbake/lib/bb/server/__init__.py | 72 | ||||
| -rw-r--r-- | bitbake/lib/bb/server/process.py | 34 | ||||
| -rw-r--r-- | bitbake/lib/bb/server/xmlrpc.py | 60 |
3 files changed, 80 insertions, 86 deletions
diff --git a/bitbake/lib/bb/server/__init__.py b/bitbake/lib/bb/server/__init__.py index 538a633fe5..345691e40f 100644 --- a/bitbake/lib/bb/server/__init__.py +++ b/bitbake/lib/bb/server/__init__.py | |||
| @@ -25,75 +25,3 @@ approach to the interface, and minimize risks associated with code duplication. | |||
| 25 | 25 | ||
| 26 | """ | 26 | """ |
| 27 | 27 | ||
| 28 | """ BaseImplServer() the base class for all XXServer() implementations. | ||
| 29 | |||
| 30 | These classes contain the actual code that runs the server side, i.e. | ||
| 31 | listens for the commands and executes them. Although these implementations | ||
| 32 | contain all the data of the original bitbake command, i.e the cooker instance, | ||
| 33 | they may well run on a different process or even machine. | ||
| 34 | |||
| 35 | """ | ||
| 36 | |||
| 37 | class BaseImplServer(): | ||
| 38 | def __init__(self): | ||
| 39 | self._idlefuns = {} | ||
| 40 | |||
| 41 | def addcooker(self, cooker): | ||
| 42 | self.cooker = cooker | ||
| 43 | |||
| 44 | def register_idle_function(self, function, data): | ||
| 45 | """Register a function to be called while the server is idle""" | ||
| 46 | assert hasattr(function, '__call__') | ||
| 47 | self._idlefuns[function] = data | ||
| 48 | |||
| 49 | |||
| 50 | |||
| 51 | """ BitBakeBaseServerConnection class is the common ancestor to all | ||
| 52 | BitBakeServerConnection classes. | ||
| 53 | |||
| 54 | These classes control the remote server. The only command currently | ||
| 55 | implemented is the terminate() command. | ||
| 56 | |||
| 57 | """ | ||
| 58 | |||
| 59 | class BitBakeBaseServerConnection(): | ||
| 60 | def __init__(self, serverImpl): | ||
| 61 | pass | ||
| 62 | |||
| 63 | def terminate(self): | ||
| 64 | pass | ||
| 65 | |||
| 66 | def setupEventQueue(self): | ||
| 67 | pass | ||
| 68 | |||
| 69 | |||
| 70 | """ BitBakeBaseServer class is the common ancestor to all Bitbake servers | ||
| 71 | |||
| 72 | Derive this class in order to implement a BitBakeServer which is the | ||
| 73 | controlling stub for the actual server implementation | ||
| 74 | |||
| 75 | """ | ||
| 76 | class BitBakeBaseServer(object): | ||
| 77 | def initServer(self): | ||
| 78 | self.serverImpl = None # we ensure a runtime crash if not overloaded | ||
| 79 | self.connection = None | ||
| 80 | return | ||
| 81 | |||
| 82 | def addcooker(self, cooker): | ||
| 83 | self.cooker = cooker | ||
| 84 | self.serverImpl.addcooker(cooker) | ||
| 85 | |||
| 86 | def getServerIdleCB(self): | ||
| 87 | return self.serverImpl.register_idle_function | ||
| 88 | |||
| 89 | def saveConnectionDetails(self): | ||
| 90 | return | ||
| 91 | |||
| 92 | def detach(self): | ||
| 93 | return | ||
| 94 | |||
| 95 | def establishConnection(self, featureset): | ||
| 96 | raise "Must redefine the %s.establishConnection()" % self.__class__.__name__ | ||
| 97 | |||
| 98 | def endSession(self): | ||
| 99 | self.connection.terminate() | ||
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py index cfcd76495c..48da7fe46c 100644 --- a/bitbake/lib/bb/server/process.py +++ b/bitbake/lib/bb/server/process.py | |||
| @@ -33,8 +33,6 @@ import select | |||
| 33 | from queue import Empty | 33 | from queue import Empty |
| 34 | from multiprocessing import Event, Process, util, Queue, Pipe, queues, Manager | 34 | from multiprocessing import Event, Process, util, Queue, Pipe, queues, Manager |
| 35 | 35 | ||
| 36 | from . import BitBakeBaseServer, BitBakeBaseServerConnection, BaseImplServer | ||
| 37 | |||
| 38 | logger = logging.getLogger('BitBake') | 36 | logger = logging.getLogger('BitBake') |
| 39 | 37 | ||
| 40 | class ServerCommunicator(): | 38 | class ServerCommunicator(): |
| @@ -85,12 +83,12 @@ class EventAdapter(): | |||
| 85 | print("EventAdapter puked: %s" % str(err)) | 83 | print("EventAdapter puked: %s" % str(err)) |
| 86 | 84 | ||
| 87 | 85 | ||
| 88 | class ProcessServer(Process, BaseImplServer): | 86 | class ProcessServer(Process): |
| 89 | profile_filename = "profile.log" | 87 | profile_filename = "profile.log" |
| 90 | profile_processed_filename = "profile.log.processed" | 88 | profile_processed_filename = "profile.log.processed" |
| 91 | 89 | ||
| 92 | def __init__(self, command_channel, event_queue, featurelist): | 90 | def __init__(self, command_channel, event_queue, featurelist): |
| 93 | BaseImplServer.__init__(self) | 91 | self._idlefuns = {} |
| 94 | Process.__init__(self) | 92 | Process.__init__(self) |
| 95 | self.command_channel = command_channel | 93 | self.command_channel = command_channel |
| 96 | self.event_queue = event_queue | 94 | self.event_queue = event_queue |
| @@ -208,7 +206,15 @@ class ProcessServer(Process, BaseImplServer): | |||
| 208 | self.quitin.send("quit") | 206 | self.quitin.send("quit") |
| 209 | self.quitin.close() | 207 | self.quitin.close() |
| 210 | 208 | ||
| 211 | class BitBakeProcessServerConnection(BitBakeBaseServerConnection): | 209 | def addcooker(self, cooker): |
| 210 | self.cooker = cooker | ||
| 211 | |||
| 212 | def register_idle_function(self, function, data): | ||
| 213 | """Register a function to be called while the server is idle""" | ||
| 214 | assert hasattr(function, '__call__') | ||
| 215 | self._idlefuns[function] = data | ||
| 216 | |||
| 217 | class BitBakeProcessServerConnection(object): | ||
| 212 | def __init__(self, serverImpl, ui_channel, event_queue): | 218 | def __init__(self, serverImpl, ui_channel, event_queue): |
| 213 | self.procserver = serverImpl | 219 | self.procserver = serverImpl |
| 214 | self.ui_channel = ui_channel | 220 | self.ui_channel = ui_channel |
| @@ -247,6 +253,9 @@ class BitBakeProcessServerConnection(BitBakeBaseServerConnection): | |||
| 247 | # fd leakage because isn't called on Queue.close() | 253 | # fd leakage because isn't called on Queue.close() |
| 248 | self.event_queue._writer.close() | 254 | self.event_queue._writer.close() |
| 249 | 255 | ||
| 256 | def setupEventQueue(self): | ||
| 257 | pass | ||
| 258 | |||
| 250 | # Wrap Queue to provide API which isn't server implementation specific | 259 | # Wrap Queue to provide API which isn't server implementation specific |
| 251 | class ProcessEventQueue(multiprocessing.queues.Queue): | 260 | class ProcessEventQueue(multiprocessing.queues.Queue): |
| 252 | def __init__(self, maxsize): | 261 | def __init__(self, maxsize): |
| @@ -279,7 +288,7 @@ class ProcessEventQueue(multiprocessing.queues.Queue): | |||
| 279 | sys.exit(1) | 288 | sys.exit(1) |
| 280 | return None | 289 | return None |
| 281 | 290 | ||
| 282 | class BitBakeServer(BitBakeBaseServer): | 291 | class BitBakeServer(object): |
| 283 | def initServer(self, single_use=True): | 292 | def initServer(self, single_use=True): |
| 284 | # establish communication channels. We use bidirectional pipes for | 293 | # establish communication channels. We use bidirectional pipes for |
| 285 | # ui <--> server command/response pairs | 294 | # ui <--> server command/response pairs |
| @@ -304,3 +313,16 @@ class BitBakeServer(BitBakeBaseServer): | |||
| 304 | raise BaseException(error) | 313 | raise BaseException(error) |
| 305 | signal.signal(signal.SIGTERM, lambda i, s: self.connection.sigterm_terminate()) | 314 | signal.signal(signal.SIGTERM, lambda i, s: self.connection.sigterm_terminate()) |
| 306 | return self.connection | 315 | return self.connection |
| 316 | |||
| 317 | def addcooker(self, cooker): | ||
| 318 | self.cooker = cooker | ||
| 319 | self.serverImpl.addcooker(cooker) | ||
| 320 | |||
| 321 | def getServerIdleCB(self): | ||
| 322 | return self.serverImpl.register_idle_function | ||
| 323 | |||
| 324 | def saveConnectionDetails(self): | ||
| 325 | return | ||
| 326 | |||
| 327 | def endSession(self): | ||
| 328 | self.connection.terminate() | ||
diff --git a/bitbake/lib/bb/server/xmlrpc.py b/bitbake/lib/bb/server/xmlrpc.py index 1a475e04ba..6874765136 100644 --- a/bitbake/lib/bb/server/xmlrpc.py +++ b/bitbake/lib/bb/server/xmlrpc.py | |||
| @@ -49,7 +49,6 @@ from xmlrpc.server import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler | |||
| 49 | import bb | 49 | import bb |
| 50 | from bb import daemonize | 50 | from bb import daemonize |
| 51 | from bb.ui import uievent | 51 | from bb.ui import uievent |
| 52 | from . import BitBakeBaseServer, BitBakeBaseServerConnection, BaseImplServer | ||
| 53 | 52 | ||
| 54 | DEBUG = False | 53 | DEBUG = False |
| 55 | 54 | ||
| @@ -193,15 +192,25 @@ class BitBakeXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): | |||
| 193 | self.wfile.write(bytes(response, 'utf-8')) | 192 | self.wfile.write(bytes(response, 'utf-8')) |
| 194 | 193 | ||
| 195 | 194 | ||
| 196 | class XMLRPCProxyServer(BaseImplServer): | 195 | class XMLRPCProxyServer(object): |
| 197 | """ not a real working server, but a stub for a proxy server connection | 196 | """ not a real working server, but a stub for a proxy server connection |
| 198 | 197 | ||
| 199 | """ | 198 | """ |
| 200 | def __init__(self, host, port, use_builtin_types=True): | 199 | def __init__(self, host, port, use_builtin_types=True): |
| 201 | self.host = host | 200 | self.host = host |
| 202 | self.port = port | 201 | self.port = port |
| 202 | self._idlefuns = {} | ||
| 203 | 203 | ||
| 204 | class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer): | 204 | def addcooker(self, cooker): |
| 205 | self.cooker = cooker | ||
| 206 | |||
| 207 | def register_idle_function(self, function, data): | ||
| 208 | """Register a function to be called while the server is idle""" | ||
| 209 | assert hasattr(function, '__call__') | ||
| 210 | self._idlefuns[function] = data | ||
| 211 | |||
| 212 | |||
| 213 | class XMLRPCServer(SimpleXMLRPCServer): | ||
| 205 | # remove this when you're done with debugging | 214 | # remove this when you're done with debugging |
| 206 | # allow_reuse_address = True | 215 | # allow_reuse_address = True |
| 207 | 216 | ||
| @@ -209,7 +218,7 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer): | |||
| 209 | """ | 218 | """ |
| 210 | Constructor | 219 | Constructor |
| 211 | """ | 220 | """ |
| 212 | BaseImplServer.__init__(self) | 221 | self._idlefuns = {} |
| 213 | self.single_use = single_use | 222 | self.single_use = single_use |
| 214 | # Use auto port configuration | 223 | # Use auto port configuration |
| 215 | if (interface[1] == -1): | 224 | if (interface[1] == -1): |
| @@ -231,7 +240,7 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer): | |||
| 231 | self.next_heartbeat = time.time() | 240 | self.next_heartbeat = time.time() |
| 232 | 241 | ||
| 233 | def addcooker(self, cooker): | 242 | def addcooker(self, cooker): |
| 234 | BaseImplServer.addcooker(self, cooker) | 243 | self.cooker = cooker |
| 235 | self.commands.cooker = cooker | 244 | self.commands.cooker = cooker |
| 236 | 245 | ||
| 237 | def autoregister_all_functions(self, context, prefix): | 246 | def autoregister_all_functions(self, context, prefix): |
| @@ -335,7 +344,13 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer): | |||
| 335 | def set_connection_token(self, token): | 344 | def set_connection_token(self, token): |
| 336 | self.connection_token = token | 345 | self.connection_token = token |
| 337 | 346 | ||
| 338 | class BitBakeXMLRPCServerConnection(BitBakeBaseServerConnection): | 347 | def register_idle_function(self, function, data): |
| 348 | """Register a function to be called while the server is idle""" | ||
| 349 | assert hasattr(function, '__call__') | ||
| 350 | self._idlefuns[function] = data | ||
| 351 | |||
| 352 | |||
| 353 | class BitBakeXMLRPCServerConnection(object): | ||
| 339 | def __init__(self, serverImpl, clientinfo=("localhost", 0), observer_only = False, featureset = None): | 354 | def __init__(self, serverImpl, clientinfo=("localhost", 0), observer_only = False, featureset = None): |
| 340 | self.connection, self.transport = _create_server(serverImpl.host, serverImpl.port) | 355 | self.connection, self.transport = _create_server(serverImpl.host, serverImpl.port) |
| 341 | self.clientinfo = clientinfo | 356 | self.clientinfo = clientinfo |
| @@ -388,7 +403,7 @@ class BitBakeXMLRPCServerConnection(BitBakeBaseServerConnection): | |||
| 388 | except: | 403 | except: |
| 389 | pass | 404 | pass |
| 390 | 405 | ||
| 391 | class BitBakeServer(BitBakeBaseServer): | 406 | class BitBakeServer(object): |
| 392 | def initServer(self, interface = ("localhost", 0), | 407 | def initServer(self, interface = ("localhost", 0), |
| 393 | single_use = False, idle_timeout=0): | 408 | single_use = False, idle_timeout=0): |
| 394 | self.interface = interface | 409 | self.interface = interface |
| @@ -405,7 +420,20 @@ class BitBakeServer(BitBakeBaseServer): | |||
| 405 | def set_connection_token(self, token): | 420 | def set_connection_token(self, token): |
| 406 | self.connection.transport.set_connection_token(token) | 421 | self.connection.transport.set_connection_token(token) |
| 407 | 422 | ||
| 408 | class BitBakeXMLRPCClient(BitBakeBaseServer): | 423 | def addcooker(self, cooker): |
| 424 | self.cooker = cooker | ||
| 425 | self.serverImpl.addcooker(cooker) | ||
| 426 | |||
| 427 | def getServerIdleCB(self): | ||
| 428 | return self.serverImpl.register_idle_function | ||
| 429 | |||
| 430 | def saveConnectionDetails(self): | ||
| 431 | return | ||
| 432 | |||
| 433 | def endSession(self): | ||
| 434 | self.connection.terminate() | ||
| 435 | |||
| 436 | class BitBakeXMLRPCClient(object): | ||
| 409 | 437 | ||
| 410 | def __init__(self, observer_only = False, token = None): | 438 | def __init__(self, observer_only = False, token = None): |
| 411 | self.token = token | 439 | self.token = token |
| @@ -446,3 +474,19 @@ class BitBakeXMLRPCClient(BitBakeBaseServer): | |||
| 446 | 474 | ||
| 447 | def endSession(self): | 475 | def endSession(self): |
| 448 | self.connection.removeClient() | 476 | self.connection.removeClient() |
| 477 | |||
| 478 | def initServer(self): | ||
| 479 | self.serverImpl = None | ||
| 480 | self.connection = None | ||
| 481 | return | ||
| 482 | |||
| 483 | def addcooker(self, cooker): | ||
| 484 | self.cooker = cooker | ||
| 485 | self.serverImpl.addcooker(cooker) | ||
| 486 | |||
| 487 | def getServerIdleCB(self): | ||
| 488 | return self.serverImpl.register_idle_function | ||
| 489 | |||
| 490 | def detach(self): | ||
| 491 | return | ||
| 492 | |||
