def start_server(servermodule, configParams, configuration, features): server = servermodule.BitBakeServer() single_use = not configParams.server_only and os.getenv('BBSERVER') != 'autostart' if configParams.bind: (host, port) = configParams.bind.split(':') server.initServer((host, int(port)), single_use=single_use, idle_timeout=configParams.idle_timeout) configuration.interface = [server.serverImpl.host, server.serverImpl.port] else: server.initServer(single_use=single_use) configuration.interface = [] try: configuration.setServerRegIdleCallback(server.getServerIdleCB()) cooker = bb.cooker.BBCooker(configuration, features) server.addcooker(cooker) server.saveConnectionDetails() except Exception as e: while hasattr(server, "event_queue"): import queue try: event = server.event_queue.get(block=False) except (queue.Empty, IOError): break if isinstance(event, logging.LogRecord): logger.handle(event) raise if not configParams.foreground: server.detach() cooker.lock.close() return server
def start_server(servermodule, configParams, configuration, features): server = servermodule.BitBakeServer() if configParams.bind: (host, port) = configParams.bind.split(':') server.initServer((host, int(port))) configuration.interface = [ server.serverImpl.host, server.serverImpl.port ] else: server.initServer() configuration.interface = [] try: configuration.setServerRegIdleCallback(server.getServerIdleCB()) cooker = bb.cooker.BBCooker(configuration, features) server.addcooker(cooker) server.saveConnectionDetails() except Exception as e: exc_info = sys.exc_info() while hasattr(server, "event_queue"): 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 start_server(servermodule, configParams, configuration, features): server = servermodule.BitBakeServer() single_use = not configParams.server_only if configParams.bind: (host, port) = configParams.bind.split(':') server.initServer((host, int(port)), single_use) configuration.interface = [server.serverImpl.host, server.serverImpl.port] else: server.initServer(single_use=single_use) configuration.interface = [] try: configuration.setServerRegIdleCallback(server.getServerIdleCB()) cooker = bb.cooker.BBCooker(configuration, features) server.addcooker(cooker) server.saveConnectionDetails() except Exception as e: while hasattr(server, "event_queue"): import queue try: event = server.event_queue.get(block=False) except (queue.Empty, IOError): break if isinstance(event, logging.LogRecord): logger.handle(event) raise server.detach() cooker.lock.close() return server
def bitbake_main(configParams, configuration): # Python multiprocessing requires /dev/shm on Linux if sys.platform.startswith('linux') and not os.access( '/dev/shm', os.W_OK | os.X_OK): raise BBMainException( "FATAL: /dev/shm does not exist or is not writable") # Unbuffer stdout to avoid log truncation in the event # of an unorderly exit as well as to provide timely # updates to log files for use with tail try: if sys.stdout.name == '<stdout>': sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) except: pass configuration.setConfigParameters(configParams) ui_module = get_ui(configParams) # Server type can be xmlrpc or process currently, if nothing is specified, # the default server is process if configParams.servertype: server_type = configParams.servertype else: server_type = 'process' try: module = __import__("bb.server", fromlist=[server_type]) servermodule = getattr(module, server_type) except AttributeError: raise BBMainException("FATAL: Invalid server type '%s' specified.\n" "Valid interfaces: xmlrpc, process [default]." % server_type) if configParams.server_only: if configParams.servertype != "xmlrpc": raise BBMainException( "FATAL: If '--server-only' is defined, we must set the " "servertype as 'xmlrpc'.\n") if not configParams.bind: raise BBMainException( "FATAL: The '--server-only' option requires a name/address " "to bind to with the -B option.\n") if configParams.remote_server: raise BBMainException("FATAL: The '--server-only' option conflicts with %s.\n" % ("the BBSERVER environment variable" if "BBSERVER" in os.environ \ else "the '--remote-server' option" )) if configParams.bind and configParams.servertype != "xmlrpc": raise BBMainException("FATAL: If '-B' or '--bind' is defined, we must " "set the servertype as 'xmlrpc'.\n") if configParams.remote_server and configParams.servertype != "xmlrpc": raise BBMainException( "FATAL: If '--remote-server' is defined, we must " "set the servertype as 'xmlrpc'.\n") if configParams.observe_only and (not configParams.remote_server or configParams.bind): raise BBMainException( "FATAL: '--observe-only' can only be used by UI clients " "connecting to a server.\n") if configParams.kill_server and not configParams.remote_server: raise BBMainException( "FATAL: '--kill-server' can only be used to terminate a remote server" ) if "BBDEBUG" in os.environ: level = int(os.environ["BBDEBUG"]) if level > configuration.debug: configuration.debug = level bb.msg.init_msgconfig(configParams.verbose, configuration.debug, configuration.debug_domains) # Ensure logging messages get sent to the UI as events handler = bb.event.LogHandler() if not configParams.status_only: # In status only mode there are no logs and no UI logger.addHandler(handler) # Clear away any spurious environment variables while we stoke up the cooker cleanedvars = bb.utils.clean_environment() featureset = [] if not configParams.server_only: # Collect the feature set for the UI featureset = getattr(ui_module, "featureSet", []) if not configParams.remote_server: # we start a server with a given configuration server = start_server(servermodule, configParams, configuration, featureset) bb.event.ui_queue = [] else: # we start a stub server that is actually a XMLRPClient that connects to a real server server = servermodule.BitBakeXMLRPCClient(configParams.observe_only, configParams.xmlrpctoken) server.saveConnectionDetails(configParams.remote_server) if not configParams.server_only: try: server_connection = server.establishConnection(featureset) except Exception as e: if configParams.kill_server: return 0 bb.fatal("Could not connect to server %s: %s" % (configParams.remote_server, str(e))) # Restore the environment in case the UI needs it for k in cleanedvars: os.environ[k] = cleanedvars[k] logger.removeHandler(handler) if configParams.status_only: server_connection.terminate() return 0 if configParams.kill_server: server_connection.connection.terminateServer() bb.event.ui_queue = [] return 0 try: return ui_module.main(server_connection.connection, server_connection.events, configParams) finally: bb.event.ui_queue = [] server_connection.terminate() else: print("Bitbake server address: %s, server port: %s" % (server.serverImpl.host, server.serverImpl.port)) return 0 return 1
def bitbake_main(configParams, configuration): # Python multiprocessing requires /dev/shm on Linux if sys.platform.startswith('linux') and not os.access('/dev/shm', os.W_OK | os.X_OK): raise BBMainException("FATAL: /dev/shm does not exist or is not writable") # Unbuffer stdout to avoid log truncation in the event # of an unorderly exit as well as to provide timely # updates to log files for use with tail try: if sys.stdout.name == '<stdout>': # Reopen with O_SYNC (unbuffered) fl = fcntl.fcntl(sys.stdout.fileno(), fcntl.F_GETFL) fl |= os.O_SYNC fcntl.fcntl(sys.stdout.fileno(), fcntl.F_SETFL, fl) except: pass configuration.setConfigParameters(configParams) ui_module = import_extension_module(bb.ui, configParams.ui, 'main') servermodule = import_extension_module(bb.server, configParams.servertype, 'BitBakeServer') if configParams.server_only: if configParams.servertype != "xmlrpc": raise BBMainException("FATAL: If '--server-only' is defined, we must set the " "servertype as 'xmlrpc'.\n") if not configParams.bind: raise BBMainException("FATAL: The '--server-only' option requires a name/address " "to bind to with the -B option.\n") if configParams.remote_server: raise BBMainException("FATAL: The '--server-only' option conflicts with %s.\n" % ("the BBSERVER environment variable" if "BBSERVER" in os.environ \ else "the '--remote-server' option")) if configParams.bind and configParams.servertype != "xmlrpc": raise BBMainException("FATAL: If '-B' or '--bind' is defined, we must " "set the servertype as 'xmlrpc'.\n") if configParams.remote_server and configParams.servertype != "xmlrpc": raise BBMainException("FATAL: If '--remote-server' is defined, we must " "set the servertype as 'xmlrpc'.\n") if configParams.observe_only and (not configParams.remote_server or configParams.bind): raise BBMainException("FATAL: '--observe-only' can only be used by UI clients " "connecting to a server.\n") if configParams.kill_server and not configParams.remote_server: raise BBMainException("FATAL: '--kill-server' can only be used to " "terminate a remote server") if "BBDEBUG" in os.environ: level = int(os.environ["BBDEBUG"]) if level > configuration.debug: configuration.debug = level bb.msg.init_msgconfig(configParams.verbose, configuration.debug, configuration.debug_domains) # Ensure logging messages get sent to the UI as events handler = bb.event.LogHandler() if not configParams.status_only: # In status only mode there are no logs and no UI logger.addHandler(handler) # Clear away any spurious environment variables while we stoke up the cooker cleanedvars = bb.utils.clean_environment() featureset = [] if not configParams.server_only: # Collect the feature set for the UI featureset = getattr(ui_module, "featureSet", []) if configParams.server_only: for param in ('prefile', 'postfile'): value = getattr(configParams, param) if value: setattr(configuration, "%s_server" % param, value) param = "%s_server" % param if not configParams.remote_server: # we start a server with a given configuration server = start_server(servermodule, configParams, configuration, featureset) bb.event.ui_queue = [] else: # we start a stub server that is actually a XMLRPClient that connects to a real server server = servermodule.BitBakeXMLRPCClient(configParams.observe_only, configParams.xmlrpctoken) server.saveConnectionDetails(configParams.remote_server) if not configParams.server_only: try: server_connection = server.establishConnection(featureset) except Exception as e: bb.fatal("Could not connect to server %s: %s" % (configParams.remote_server, str(e))) if configParams.kill_server: server_connection.connection.terminateServer() bb.event.ui_queue = [] return 0 server_connection.setupEventQueue() # Restore the environment in case the UI needs it for k in cleanedvars: os.environ[k] = cleanedvars[k] logger.removeHandler(handler) if configParams.status_only: server_connection.terminate() return 0 try: return ui_module.main(server_connection.connection, server_connection.events, configParams) finally: bb.event.ui_queue = [] server_connection.terminate() else: print("Bitbake server address: %s, server port: %s" % (server.serverImpl.host, server.serverImpl.port)) return 0 return 1
def setup_bitbake(configParams, configuration, extrafeatures=None): # Ensure logging messages get sent to the UI as events handler = bb.event.LogHandler() if not configParams.status_only: # In status only mode there are no logs and no UI logger.addHandler(handler) # Clear away any spurious environment variables while we stoke up the cooker cleanedvars = bb.utils.clean_environment() if configParams.server_only: featureset = [] ui_module = None else: ui_module = import_extension_module(bb.ui, configParams.ui, 'main') # Collect the feature set for the UI featureset = getattr(ui_module, "featureSet", []) if configParams.server_only: for param in ('prefile', 'postfile'): value = getattr(configParams, param) if value: setattr(configuration, "%s_server" % param, value) param = "%s_server" % param if extrafeatures: for feature in extrafeatures: if not feature in featureset: featureset.append(feature) servermodule = import_extension_module(bb.server, configParams.servertype, 'BitBakeServer') if configParams.remote_server: if os.getenv('BBSERVER') == 'autostart': if configParams.remote_server == 'autostart' or \ not servermodule.check_connection(configParams.remote_server, timeout=2): configParams.bind = 'localhost:0' srv = start_server(servermodule, configParams, configuration, featureset) configParams.remote_server = '%s:%d' % tuple( configuration.interface) bb.event.ui_queue = [] # we start a stub server that is actually a XMLRPClient that connects to a real server from bb.server.xmlrpc import BitBakeXMLRPCClient server = servermodule.BitBakeXMLRPCClient(configParams.observe_only, configParams.xmlrpctoken) server.saveConnectionDetails(configParams.remote_server) else: # we start a server with a given configuration server = start_server(servermodule, configParams, configuration, featureset) bb.event.ui_queue = [] if configParams.server_only: server_connection = None else: try: server_connection = server.establishConnection(featureset) except Exception as e: bb.fatal("Could not connect to server %s: %s" % (configParams.remote_server, str(e))) if configParams.kill_server: server_connection.connection.terminateServer() bb.event.ui_queue = [] return None, None, None server_connection.setupEventQueue() # Restore the environment in case the UI needs it for k in cleanedvars: os.environ[k] = cleanedvars[k] logger.removeHandler(handler) return server, server_connection, ui_module
def bitbake_main(configParams, configuration): # Python multiprocessing requires /dev/shm on Linux if sys.platform.startswith('linux') and not os.access('/dev/shm', os.W_OK | os.X_OK): raise BBMainException("FATAL: /dev/shm does not exist or is not writable") # Unbuffer stdout to avoid log truncation in the event # of an unorderly exit as well as to provide timely # updates to log files for use with tail try: if sys.stdout.name == '<stdout>': sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) except: pass configuration.setConfigParameters(configParams) ui_module = get_ui(configParams) # Server type can be xmlrpc or process currently, if nothing is specified, # the default server is process if configParams.servertype: server_type = configParams.servertype else: server_type = 'process' try: module = __import__("bb.server", fromlist = [server_type]) servermodule = getattr(module, server_type) except AttributeError: raise BBMainException("FATAL: Invalid server type '%s' specified.\n" "Valid interfaces: xmlrpc, process [default]." % server_type) if configParams.server_only: if configParams.servertype != "xmlrpc": raise BBMainException("FATAL: If '--server-only' is defined, we must set the " "servertype as 'xmlrpc'.\n") if not configParams.bind: raise BBMainException("FATAL: The '--server-only' option requires a name/address " "to bind to with the -B option.\n") if configParams.remote_server: raise BBMainException("FATAL: The '--server-only' option conflicts with %s.\n" % ("the BBSERVER environment variable" if "BBSERVER" in os.environ \ else "the '--remote-server' option" )) if configParams.bind and configParams.servertype != "xmlrpc": raise BBMainException("FATAL: If '-B' or '--bind' is defined, we must " "set the servertype as 'xmlrpc'.\n") if configParams.remote_server and configParams.servertype != "xmlrpc": raise BBMainException("FATAL: If '--remote-server' is defined, we must " "set the servertype as 'xmlrpc'.\n") if configParams.observe_only and (not configParams.remote_server or configParams.bind): raise BBMainException("FATAL: '--observe-only' can only be used by UI clients " "connecting to a server.\n") if configParams.kill_server and not configParams.remote_server: raise BBMainException("FATAL: '--kill-server' can only be used to terminate a remote server") if "BBDEBUG" in os.environ: level = int(os.environ["BBDEBUG"]) if level > configuration.debug: configuration.debug = level bb.msg.init_msgconfig(configParams.verbose, configuration.debug, configuration.debug_domains) # Ensure logging messages get sent to the UI as events handler = bb.event.LogHandler() if not configParams.status_only: # In status only mode there are no logs and no UI logger.addHandler(handler) # Clear away any spurious environment variables while we stoke up the cooker cleanedvars = bb.utils.clean_environment() featureset = [] if not configParams.server_only: # Collect the feature set for the UI featureset = getattr(ui_module, "featureSet", []) if not configParams.remote_server: # we start a server with a given configuration server = start_server(servermodule, configParams, configuration, featureset) bb.event.ui_queue = [] else: # we start a stub server that is actually a XMLRPClient that connects to a real server server = servermodule.BitBakeXMLRPCClient(configParams.observe_only, configParams.xmlrpctoken) server.saveConnectionDetails(configParams.remote_server) if not configParams.server_only: try: server_connection = server.establishConnection(featureset) except Exception as e: if configParams.kill_server: return 0 bb.fatal("Could not connect to server %s: %s" % (configParams.remote_server, str(e))) # Restore the environment in case the UI needs it for k in cleanedvars: os.environ[k] = cleanedvars[k] logger.removeHandler(handler) if configParams.status_only: server_connection.terminate() return 0 if configParams.kill_server: server_connection.connection.terminateServer() bb.event.ui_queue = [] return 0 try: return ui_module.main(server_connection.connection, server_connection.events, configParams) finally: bb.event.ui_queue = [] server_connection.terminate() else: print("Bitbake server address: %s, server port: %s" % (server.serverImpl.host, server.serverImpl.port)) return 0 return 1
def setup_bitbake(configParams, configuration, extrafeatures=None): # Ensure logging messages get sent to the UI as events handler = bb.event.LogHandler() if not configParams.status_only: # In status only mode there are no logs and no UI logger.addHandler(handler) # Clear away any spurious environment variables while we stoke up the cooker cleanedvars = bb.utils.clean_environment() if configParams.server_only: featureset = [] ui_module = None else: ui_module = import_extension_module(bb.ui, configParams.ui, 'main') # Collect the feature set for the UI featureset = getattr(ui_module, "featureSet", []) if configParams.server_only: for param in ('prefile', 'postfile'): value = getattr(configParams, param) if value: setattr(configuration, "%s_server" % param, value) param = "%s_server" % param if extrafeatures: for feature in extrafeatures: if not feature in featureset: featureset.append(feature) servermodule = import_extension_module(bb.server, configParams.servertype, 'BitBakeServer') if configParams.remote_server: if os.getenv('BBSERVER') == 'autostart': if configParams.remote_server == 'autostart' or \ not servermodule.check_connection(configParams.remote_server, timeout=2): configParams.bind = 'localhost:0' srv = start_server(servermodule, configParams, configuration, featureset) configParams.remote_server = '%s:%d' % tuple(configuration.interface) bb.event.ui_queue = [] # we start a stub server that is actually a XMLRPClient that connects to a real server from bb.server.xmlrpc import BitBakeXMLRPCClient server = servermodule.BitBakeXMLRPCClient(configParams.observe_only, configParams.xmlrpctoken) server.saveConnectionDetails(configParams.remote_server) else: # we start a server with a given configuration server = start_server(servermodule, configParams, configuration, featureset) bb.event.ui_queue = [] if configParams.server_only: server_connection = None else: try: server_connection = server.establishConnection(featureset) except Exception as e: bb.fatal("Could not connect to server %s: %s" % (configParams.remote_server, str(e))) if configParams.kill_server: server_connection.connection.terminateServer() bb.event.ui_queue = [] return None, None, None server_connection.setupEventQueue() # Restore the environment in case the UI needs it for k in cleanedvars: os.environ[k] = cleanedvars[k] logger.removeHandler(handler) return server, server_connection, ui_module
def bitbake_main(configParams, configuration): # Python multiprocessing requires /dev/shm on Linux if sys.platform.startswith('linux') and not os.access('/dev/shm', os.W_OK | os.X_OK): raise BBMainException("FATAL: /dev/shm does not exist or is not writable") # Unbuffer stdout to avoid log truncation in the event # of an unorderly exit as well as to provide timely # updates to log files for use with tail try: if sys.stdout.name == '<stdout>': # Reopen with O_SYNC (unbuffered) fl = fcntl.fcntl(sys.stdout.fileno(), fcntl.F_GETFL) fl |= os.O_SYNC fcntl.fcntl(sys.stdout.fileno(), fcntl.F_SETFL, fl) except: pass configuration.setConfigParameters(configParams) ui_module = import_extension_module(bb.ui, configParams.ui, 'main') servermodule = import_extension_module(bb.server, configParams.servertype, 'BitBakeServer') if configParams.server_only: if configParams.servertype != "xmlrpc": raise BBMainException("FATAL: If '--server-only' is defined, we must set the " "servertype as 'xmlrpc'.\n") if not configParams.bind: raise BBMainException("FATAL: The '--server-only' option requires a name/address " "to bind to with the -B option.\n") else: try: #Checking that the port is a number int(configParams.bind.split(":")[1]) except (ValueError,IndexError): raise BBMainException( "FATAL: Malformed host:port bind parameter") if configParams.remote_server: raise BBMainException("FATAL: The '--server-only' option conflicts with %s.\n" % ("the BBSERVER environment variable" if "BBSERVER" in os.environ \ else "the '--remote-server' option")) elif configParams.foreground: raise BBMainException("FATAL: The '--foreground' option can only be used " "with --server-only.\n") if configParams.bind and configParams.servertype != "xmlrpc": raise BBMainException("FATAL: If '-B' or '--bind' is defined, we must " "set the servertype as 'xmlrpc'.\n") if configParams.remote_server and configParams.servertype != "xmlrpc": raise BBMainException("FATAL: If '--remote-server' is defined, we must " "set the servertype as 'xmlrpc'.\n") if configParams.observe_only and (not configParams.remote_server or configParams.bind): raise BBMainException("FATAL: '--observe-only' can only be used by UI clients " "connecting to a server.\n") if configParams.kill_server and not configParams.remote_server: raise BBMainException("FATAL: '--kill-server' can only be used to " "terminate a remote server") if "BBDEBUG" in os.environ: level = int(os.environ["BBDEBUG"]) if level > configuration.debug: configuration.debug = level bb.msg.init_msgconfig(configParams.verbose, configuration.debug, configuration.debug_domains) # Ensure logging messages get sent to the UI as events handler = bb.event.LogHandler() if not configParams.status_only: # In status only mode there are no logs and no UI logger.addHandler(handler) # Clear away any spurious environment variables while we stoke up the cooker cleanedvars = bb.utils.clean_environment() featureset = [] if not configParams.server_only: # Collect the feature set for the UI featureset = getattr(ui_module, "featureSet", []) if configParams.server_only: for param in ('prefile', 'postfile'): value = getattr(configParams, param) if value: setattr(configuration, "%s_server" % param, value) param = "%s_server" % param if not configParams.remote_server: # we start a server with a given configuration server = start_server(servermodule, configParams, configuration, featureset) bb.event.ui_queue = [] else: if os.getenv('BBSERVER') == 'autostart': if configParams.remote_server == 'autostart' or \ not servermodule.check_connection(configParams.remote_server, timeout=2): configParams.bind = 'localhost:0' srv = start_server(servermodule, configParams, configuration, featureset) configParams.remote_server = '%s:%d' % tuple(configuration.interface) bb.event.ui_queue = [] # we start a stub server that is actually a XMLRPClient that connects to a real server server = servermodule.BitBakeXMLRPCClient(configParams.observe_only, configParams.xmlrpctoken) server.saveConnectionDetails(configParams.remote_server) if not configParams.server_only: try: server_connection = server.establishConnection(featureset) except Exception as e: bb.fatal("Could not connect to server %s: %s" % (configParams.remote_server, str(e))) if configParams.kill_server: server_connection.connection.terminateServer() bb.event.ui_queue = [] return 0 server_connection.setupEventQueue() # Restore the environment in case the UI needs it for k in cleanedvars: os.environ[k] = cleanedvars[k] logger.removeHandler(handler) if configParams.status_only: server_connection.terminate() return 0 try: return ui_module.main(server_connection.connection, server_connection.events, configParams) finally: bb.event.ui_queue = [] server_connection.terminate() else: print("Bitbake server address: %s, server port: %s" % (server.serverImpl.host, server.serverImpl.port)) if configParams.foreground: server.serverImpl.serve_forever() return 0 return 1