bitbake/server/process: Update to new server API

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie 2011-06-08 11:20:08 +01:00
parent 8aabfed148
commit 658ba779ac
2 changed files with 79 additions and 34 deletions

View File

@ -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()

View 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)