]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
bitbake/server/process: Update to new server API
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 8 Jun 2011 10:20:08 +0000 (11:20 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 8 Jun 2011 10:38:47 +0000 (11:38 +0100)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
bitbake/bin/bitbake
bitbake/lib/bb/server/process.py

index 8f2fece2caf7a2cd740ad336e9b1d153dd1f7e71..acd2f790dc5bdc8eded444ffef915d51236678c2 100755 (executable)
@@ -40,7 +40,8 @@ from bb import cooker
 from bb import ui
 from bb import server
 from bb.server import none
-from bb.server import xmlrpc
+#from bb.server import process
+#from bb.server import xmlrpc
 
 __version__ = "1.13.0"
 logger = logging.getLogger("BitBake")
@@ -189,8 +190,9 @@ Default BBFILES are the .bb files in the current directory.""")
     # of the UIs (e.g. for DISPLAY, etc.)
     bb.utils.clean_environment()
 
+    server = bb.server.none.BitBakeServer()    
+    #server = bb.server.process.BitBakeServer()
     #server = bb.server.xmlrpc.BitBakeServer()
-    server = bb.server.none.BitBakeServer()
 
     server.initServer()
     idle = server.getServerIdleCB()
index 5d7f8aa9deb9718ba8c9a19c80af5e47c0fa586b..12f368f80f20d32c2119857f78410f6d01461f58 100644 (file)
@@ -29,8 +29,8 @@ import os
 import signal
 import sys
 import time
-from bb.cooker import BBCooker
-from multiprocessing import Event, Process, util
+from Queue import Empty
+from multiprocessing import Event, Process, util, Queue, Pipe, queues
 
 logger = logging.getLogger('BitBake')
 
@@ -72,13 +72,11 @@ class ProcessServer(Process):
     profile_filename = "profile.log"
     profile_processed_filename = "profile.log.processed"
 
-    def __init__(self, command_channel, event_queue, configuration):
+    def __init__(self, command_channel, event_queue):
         Process.__init__(self)
         self.command_channel = command_channel
         self.event_queue = event_queue
         self.event = EventAdapter(event_queue)
-        self.configuration = configuration
-        self.cooker = BBCooker(configuration, self.register_idle_function)
         self._idlefunctions = {}
         self.event_handle = bb.event.register_UIHhandler(self)
         self.quit = False
@@ -95,33 +93,7 @@ class ProcessServer(Process):
         self._idlefunctions[function] = data
 
     def run(self):
-        if self.configuration.profile:
-            return self.profile_main()
-        else:
-            return self.main()
-
-    def profile_main(self):
-        import cProfile
-        profiler = cProfile.Profile()
-        try:
-            return profiler.runcall(self.main)
-        finally:
-            profiler.dump_stats(self.profile_filename)
-            self.write_profile_stats()
-            sys.__stderr__.write("Raw profiling information saved to %s and "
-                                 "processed statistics to %s\n" %
-                                 (self.profile_filename,
-                                  self.profile_processed_filename))
-
-    def write_profile_stats(self):
-        import pstats
-        with open(self.profile_processed_filename, 'w') as outfile:
-            stats = pstats.Stats(self.profile_filename, stream=outfile)
-            stats.sort_stats('time')
-            stats.print_stats()
-            stats.print_callers()
-            stats.sort_stats('cumulative')
-            stats.print_stats()
+        bb.cooker.server_main(self.cooker, self.main)
 
     def main(self):
         # Ignore SIGINT within the server, as all SIGINT handling is done by
@@ -219,3 +191,74 @@ class ProcessServer(Process):
     # which can result in a bitbake server hang during the parsing process
     if (2, 6, 0) <= sys.version_info < (2, 6, 3):
         _bootstrap = bootstrap_2_6_6
+
+class BitBakeServerConnection():
+    def __init__(self, server):
+        self.server = server
+        self.procserver = server.server
+        self.connection = ServerCommunicator(server.ui_channel)
+        self.events = server.event_queue
+
+    def terminate(self, force = False):
+        signal.signal(signal.SIGINT, signal.SIG_IGN)
+        self.procserver.stop()
+        if force:
+            self.procserver.join(0.5)
+            if self.procserver.is_alive():
+                self.procserver.terminate()
+                self.procserver.join()
+        else:
+            self.procserver.join()
+        while True:
+            try:
+                event = self.server.event_queue.get(block=False)
+            except (Empty, IOError):
+                break
+            if isinstance(event, logging.LogRecord):
+                logger.handle(event)
+        self.server.ui_channel.close()
+        self.server.event_queue.close()
+        if force:
+            sys.exit(1)
+
+# Wrap Queue to provide API which isn't server implementation specific
+class ProcessEventQueue(multiprocessing.queues.Queue):
+    def waitEvent(self, timeout):
+        try:
+            return self.get(True, timeout)
+        except Empty:
+            return None
+
+class BitBakeServer(object):
+    def initServer(self):
+        # establish communication channels.  We use bidirectional pipes for
+        # ui <--> server command/response pairs
+        # and a queue for server -> ui event notifications
+        #
+        self.ui_channel, self.server_channel = Pipe()
+        self.event_queue = ProcessEventQueue(0)
+
+        self.server = ProcessServer(self.server_channel, self.event_queue)
+
+    def addcooker(self, cooker):
+        self.cooker = cooker
+        self.server.cooker = cooker
+
+    def getServerIdleCB(self):
+        return self.server.register_idle_function
+
+    def saveConnectionDetails(self):
+        return
+
+    def detach(self, cooker_logfile):
+        self.server.start() 
+        return
+
+    def establishConnection(self):
+        self.connection = BitBakeServerConnection(self)
+        signal.signal(signal.SIGTERM, lambda i, s: self.connection.terminate(force=True))
+        return self.connection
+
+    def launchUI(self, uifunc, *args):
+        return bb.cooker.server_main(self.cooker, uifunc, *args)
+