From b6b30095de0f5549a6cd3526170c70f39e803de6 Mon Sep 17 00:00:00 2001 From: Alexandru DAMIAN Date: Tue, 28 May 2013 13:32:48 +0000 Subject: [PATCH] bitbake: bitbake: move start server code in a separate function This is a code sanitization targeted at making further server-related changes easier (launch a server separately or creating a mockup-server) to do. (Bitbake rev: eac00258d213137ef73aed255c92b7981e2f1c75) Signed-off-by: Alexandru DAMIAN Signed-off-by: Richard Purdie --- bitbake/bin/bitbake | 76 ++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/bitbake/bin/bitbake b/bitbake/bin/bitbake index f44543de2c..6d4efe6bbf 100755 --- a/bitbake/bin/bitbake +++ b/bitbake/bin/bitbake @@ -195,6 +195,40 @@ class BitBakeConfigParameters(cookerdata.ConfigParameters): options, targets = parser.parse_args(sys.argv) return options, targets[1:] + +def start_server(servermodule, configParams, configuration): + server = servermodule.BitBakeServer() + if configParams.bind: + server.initServer((configParams.bind, 0)) + else: + server.initServer() + + try: + configuration.setServerRegIdleCallback(server.getServerIdleCB()) + + cooker = bb.cooker.BBCooker(configuration) + + server.addcooker(cooker) + server.saveConnectionDetails() + except Exception as e: + exc_info = sys.exc_info() + while True: + try: + import queue + except ImportError: + import Queue as queue + try: + event = server.event_queue.get(block=False) + except (queue.Empty, IOError): + break + if isinstance(event, logging.LogRecord): + logger.handle(event) + raise exc_info[1], None, exc_info[2] + server.detach() + return server + + + def main(): configParams = BitBakeConfigParameters() @@ -212,7 +246,7 @@ def main(): try: module = __import__("bb.server", fromlist = [server_type]) - server = getattr(module, server_type) + servermodule = getattr(module, server_type) except AttributeError: sys.exit("FATAL: Invalid server type '%s' specified.\n" "Valid interfaces: xmlrpc, process [default]." % servertype) @@ -241,42 +275,14 @@ def main(): # Clear away any spurious environment variables while we stoke up the cooker cleanedvars = bb.utils.clean_environment() - server = server.BitBakeServer() - if configParams.bind: - server.initServer((configParams.bind, 0)) + # Collect all the caches we need + if configParams.server_only: + configuration.extra_caches = gather_extra_cache_data() else: - server.initServer() + configuration.extra_caches = getattr(ui_module, "extraCaches", []) - try: - configuration.setServerRegIdleCallback(server.getServerIdleCB()) - - if configParams.server_only: - configuration.extra_caches = gather_extra_cache_data() - else: - configuration.extra_caches = getattr(ui_module, "extraCaches", []) - - cooker = bb.cooker.BBCooker(configuration) - - server.addcooker(cooker) - server.saveConnectionDetails() - except Exception as e: - exc_info = sys.exc_info() - while True: - try: - import queue - except ImportError: - import Queue as queue - try: - event = server.event_queue.get(block=False) - except (queue.Empty, IOError): - break - if isinstance(event, logging.LogRecord): - logger.handle(event) - raise exc_info[1], None, exc_info[2] - server.detach() - - # Should no longer need to ever reference cooker - del cooker + # we start a server with a given configuration + server = start_server(servermodule, configParams, configuration) logger.removeHandler(handler)