summaryrefslogtreecommitdiffstats
path: root/lib/bb
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@linux.intel.com>2010-01-18 17:40:10 +0000
committerRichard Purdie <rpurdie@linux.intel.com>2010-01-18 17:40:10 +0000
commit4d67b81dd837c2132e34fe3354e258fa51ebeaad (patch)
tree5ae62a221932cfc7df5f71c09f6334204dc86cbe /lib/bb
parentc295c4646729883f9724ce3ae55d8454aab86ab1 (diff)
downloadbitbake-4d67b81dd837c2132e34fe3354e258fa51ebeaad.tar.gz
Add none server type to avoid xmlrpc in the default case
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'lib/bb')
-rw-r--r--lib/bb/cooker.py2
-rw-r--r--lib/bb/server/__init__.py1
-rw-r--r--lib/bb/server/none.py168
-rw-r--r--lib/bb/server/xmlrpc.py30
4 files changed, 199 insertions, 2 deletions
diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index 1bf7d4bd1..55a97cc6c 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -932,8 +932,6 @@ class CookerParser:
self.pointer = 0
def parse_next(self):
- print "Pointer %d" % self.pointer
-
if self.pointer < len(self.filelist):
f = self.filelist[self.pointer]
cooker = self.cooker
diff --git a/lib/bb/server/__init__.py b/lib/bb/server/__init__.py
index 0dd04cf72..1a732236e 100644
--- a/lib/bb/server/__init__.py
+++ b/lib/bb/server/__init__.py
@@ -1 +1,2 @@
import xmlrpc
+import none
diff --git a/lib/bb/server/none.py b/lib/bb/server/none.py
new file mode 100644
index 000000000..671460f84
--- /dev/null
+++ b/lib/bb/server/none.py
@@ -0,0 +1,168 @@
+#
+# BitBake 'dummy' Passthrough Server
+#
+# Copyright (C) 2006 - 2007 Michael 'Mickey' Lauer
+# Copyright (C) 2006 - 2008 Richard Purdie
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+"""
+ This module implements an xmlrpc server for BitBake.
+
+ Use this by deriving a class from BitBakeXMLRPCServer and then adding
+ methods which you want to "export" via XMLRPC. If the methods have the
+ prefix xmlrpc_, then registering those function will happen automatically,
+ if not, you need to call register_function.
+
+ Use register_idle_function() to add a function which the xmlrpc server
+ calls from within server_forever when no requests are pending. Make sure
+ that those functions are non-blocking or else you will introduce latency
+ in the server's main loop.
+"""
+
+import bb
+from bb.ui import uievent
+import xmlrpclib
+
+DEBUG = False
+
+from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
+import inspect, select
+
+class BitBakeServerCommands():
+ def __init__(self, server, cooker):
+ self.cooker = cooker
+ self.server = server
+
+ def runCommand(self, command):
+ """
+ Run a cooker command on the server
+ """
+ print "Running Command %s" % command
+ return self.cooker.command.runCommand(command)
+
+ def terminateServer(self):
+ """
+ Trigger the server to quit
+ """
+ self.server.server_exit()
+ print "Server (cooker) exitting"
+ return
+
+ def ping(self):
+ """
+ Dummy method which can be used to check the server is still alive
+ """
+ return True
+
+eventQueue = []
+
+class BBUIEventQueue:
+ class event:
+ def __init__(self, parent):
+ self.parent = parent
+ @staticmethod
+ def send(event):
+ event = xmlrpclib.loads(xmlrpclib.dumps(event, allow_none=True))
+ bb.server.none.eventQueue.append(event[0])
+ @staticmethod
+ def quit():
+ return
+
+ def __init__(self, BBServer):
+ self.eventQueue = bb.server.none.eventQueue
+ self.BBServer = BBServer
+ self.EventHandle = bb.event.register_UIHhandler(self)
+
+ def getEvent(self):
+ if len(self.eventQueue) == 0:
+ return None
+
+ return self.eventQueue.pop(0)
+
+ def waitEvent(self, delay):
+ self.BBServer.idle_commands()
+ return self.getEvent()
+
+ def queue_event(self, event):
+ self.eventQueue.append(event)
+
+ def system_quit( self ):
+ bb.event.unregister_UIHhandler(self.EventHandle)
+
+class BitBakeServer():
+ # remove this when you're done with debugging
+ # allow_reuse_address = True
+
+ def __init__(self, cooker):
+ self._idlefuns = {}
+ self.commands = BitBakeServerCommands(self, cooker)
+
+ def register_idle_function(self, function, data):
+ """Register a function to be called while the server is idle"""
+ assert callable(function)
+ self._idlefuns[function] = data
+
+ def idle_commands(self):
+ #print "Idle queue length %s" % len(self._idlefuns)
+ #print "Idle timeout, running idle functions"
+ #if len(self._idlefuns) == 0:
+
+
+ for function, data in self._idlefuns.items():
+ try:
+ retval = function(self, data, False)
+ if not retval:
+ del self._idlefuns[function]
+ except SystemExit:
+ raise
+ except:
+ import traceback
+ traceback.print_exc()
+ pass
+
+ def server_exit(self):
+ # Tell idle functions we're exiting
+ for function, data in self._idlefuns.items():
+ try:
+ retval = function(self, data, True)
+ except:
+ pass
+
+class BitbakeServerInfo():
+ def __init__(self, server):
+ self.server = server
+ self.commands = server.commands
+
+class BitBakeServerFork():
+ def __init__(self, serverinfo, command, logfile):
+ serverinfo.forkCommand = command
+ serverinfo.logfile = logfile
+
+class BitBakeServerConnection():
+ def __init__(self, serverinfo):
+ self.server = serverinfo.server
+ self.connection = serverinfo.commands
+ self.events = bb.server.none.BBUIEventQueue(self.server)
+
+ def terminate(self):
+ try:
+ self.events.system_quit()
+ except:
+ pass
+ try:
+ self.connection.terminateServer()
+ except:
+ pass
+
diff --git a/lib/bb/server/xmlrpc.py b/lib/bb/server/xmlrpc.py
index c5937abd6..e7b7183fb 100644
--- a/lib/bb/server/xmlrpc.py
+++ b/lib/bb/server/xmlrpc.py
@@ -33,6 +33,8 @@
import bb
import xmlrpclib
+from bb import daemonize
+from bb.ui import uievent
DEBUG = False
@@ -143,3 +145,31 @@ class BitBakeServer(SimpleXMLRPCServer):
self.server_close()
return
+
+class BitbakeServerInfo():
+ def __init__(self, server):
+ self.host = server.host
+ self.port = server.port
+
+class BitBakeServerFork():
+ def __init__(self, command, logfile):
+ daemonize.createDaemon(command, logfile)
+
+class BitBakeServerConnection():
+ def __init__(self, serverinfo):
+ self.connection = xmlrpclib.Server("http://%s:%s" % (serverinfo.host, serverinfo.port), allow_none=True)
+ self.events = uievent.BBUIEventQueue(self.connection)
+
+ def terminate(self):
+ # Don't wait for server indefinitely
+ import socket
+ socket.setdefaulttimeout(2)
+ try:
+ self.events.system_quit()
+ except:
+ pass
+ try:
+ self.connection.terminateServer()
+ except:
+ pass
+