[gnome-continuous-yocto/gnomeostree-3.28-rocko: 6809/8267] bitbake: server: Remove base classes and inline code



commit 577b75086eaf4ae2201933f7b9ac32f6239867c6
Author: Richard Purdie <richard purdie linuxfoundation org>
Date:   Tue Jul 18 22:15:17 2017 +0100

    bitbake: server: Remove base classes and inline code
    
    In preparation for rewriting this code, expand the relatively useless
    base classes into the code itself.
    
    (Bitbake rev: a1c6151420d86bac658c08ae714647062edd6ef2)
    
    Signed-off-by: Richard Purdie <richard purdie linuxfoundation org>

 bitbake/lib/bb/server/__init__.py |   72 -------------------------------------
 bitbake/lib/bb/server/process.py  |   34 ++++++++++++++---
 bitbake/lib/bb/server/xmlrpc.py   |   60 ++++++++++++++++++++++++++----
 3 files changed, 80 insertions(+), 86 deletions(-)
---
diff --git a/bitbake/lib/bb/server/__init__.py b/bitbake/lib/bb/server/__init__.py
index 538a633..345691e 100644
--- a/bitbake/lib/bb/server/__init__.py
+++ b/bitbake/lib/bb/server/__init__.py
@@ -25,75 +25,3 @@ approach to the interface, and minimize risks associated with code duplication.
 
 """
 
-"""  BaseImplServer() the base class for all XXServer() implementations.
-
-    These classes contain the actual code that runs the server side, i.e.
-    listens for the commands and executes them. Although these implementations
-    contain all the data of the original bitbake command, i.e the cooker instance,
-    they may well run on a different process or even machine.
-
-"""
-
-class BaseImplServer():
-    def __init__(self):
-        self._idlefuns = {}
-
-    def addcooker(self, cooker):
-        self.cooker = cooker
-
-    def register_idle_function(self, function, data):
-        """Register a function to be called while the server is idle"""
-        assert hasattr(function, '__call__')
-        self._idlefuns[function] = data
-
-
-
-""" BitBakeBaseServerConnection class is the common ancestor to all
-    BitBakeServerConnection classes.
-
-    These classes control the remote server. The only command currently
-    implemented is the terminate() command.
-
-"""
-
-class BitBakeBaseServerConnection():
-    def __init__(self, serverImpl):
-        pass
-
-    def terminate(self):
-        pass
-
-    def setupEventQueue(self):
-        pass
-
-
-""" BitBakeBaseServer class is the common ancestor to all Bitbake servers
-
-    Derive this class in order to implement a BitBakeServer which is the
-    controlling stub for the actual server implementation
-
-"""
-class BitBakeBaseServer(object):
-    def initServer(self):
-        self.serverImpl = None  # we ensure a runtime crash if not overloaded
-        self.connection = None
-        return
-
-    def addcooker(self, cooker):
-        self.cooker = cooker
-        self.serverImpl.addcooker(cooker)
-
-    def getServerIdleCB(self):
-        return self.serverImpl.register_idle_function
-
-    def saveConnectionDetails(self):
-        return
-
-    def detach(self):
-        return
-
-    def establishConnection(self, featureset):
-        raise   "Must redefine the %s.establishConnection()" % self.__class__.__name__
-
-    def endSession(self):
-        self.connection.terminate()
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py
index cfcd764..48da7fe 100644
--- a/bitbake/lib/bb/server/process.py
+++ b/bitbake/lib/bb/server/process.py
@@ -33,8 +33,6 @@ import select
 from queue import Empty
 from multiprocessing import Event, Process, util, Queue, Pipe, queues, Manager
 
-from . import BitBakeBaseServer, BitBakeBaseServerConnection, BaseImplServer
-
 logger = logging.getLogger('BitBake')
 
 class ServerCommunicator():
@@ -85,12 +83,12 @@ class EventAdapter():
             print("EventAdapter puked: %s" % str(err))
 
 
-class ProcessServer(Process, BaseImplServer):
+class ProcessServer(Process):
     profile_filename = "profile.log"
     profile_processed_filename = "profile.log.processed"
 
     def __init__(self, command_channel, event_queue, featurelist):
-        BaseImplServer.__init__(self)
+        self._idlefuns = {}
         Process.__init__(self)
         self.command_channel = command_channel
         self.event_queue = event_queue
@@ -208,7 +206,15 @@ class ProcessServer(Process, BaseImplServer):
         self.quitin.send("quit")
         self.quitin.close()
 
-class BitBakeProcessServerConnection(BitBakeBaseServerConnection):
+    def addcooker(self, cooker):
+        self.cooker = cooker
+
+    def register_idle_function(self, function, data):
+        """Register a function to be called while the server is idle"""
+        assert hasattr(function, '__call__')
+        self._idlefuns[function] = data
+
+class BitBakeProcessServerConnection(object):
     def __init__(self, serverImpl, ui_channel, event_queue):
         self.procserver = serverImpl
         self.ui_channel = ui_channel
@@ -247,6 +253,9 @@ class BitBakeProcessServerConnection(BitBakeBaseServerConnection):
         # fd leakage because isn't called on Queue.close()
         self.event_queue._writer.close()
 
+    def setupEventQueue(self):
+        pass
+
 # Wrap Queue to provide API which isn't server implementation specific
 class ProcessEventQueue(multiprocessing.queues.Queue):
     def __init__(self, maxsize):
@@ -279,7 +288,7 @@ class ProcessEventQueue(multiprocessing.queues.Queue):
                 sys.exit(1)
             return None
 
-class BitBakeServer(BitBakeBaseServer):
+class BitBakeServer(object):
     def initServer(self, single_use=True):
         # establish communication channels.  We use bidirectional pipes for
         # ui <--> server command/response pairs
@@ -304,3 +313,16 @@ class BitBakeServer(BitBakeBaseServer):
             raise BaseException(error)
         signal.signal(signal.SIGTERM, lambda i, s: self.connection.sigterm_terminate())
         return self.connection
+
+    def addcooker(self, cooker):
+        self.cooker = cooker
+        self.serverImpl.addcooker(cooker)
+
+    def getServerIdleCB(self):
+        return self.serverImpl.register_idle_function
+
+    def saveConnectionDetails(self):
+        return
+
+    def endSession(self):
+        self.connection.terminate()
diff --git a/bitbake/lib/bb/server/xmlrpc.py b/bitbake/lib/bb/server/xmlrpc.py
index 1a475e0..6874765 100644
--- a/bitbake/lib/bb/server/xmlrpc.py
+++ b/bitbake/lib/bb/server/xmlrpc.py
@@ -49,7 +49,6 @@ from xmlrpc.server import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
 import bb
 from bb import daemonize
 from bb.ui import uievent
-from . import BitBakeBaseServer, BitBakeBaseServerConnection, BaseImplServer
 
 DEBUG = False
 
@@ -193,15 +192,25 @@ class BitBakeXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
         self.wfile.write(bytes(response, 'utf-8'))
 
 
-class XMLRPCProxyServer(BaseImplServer):
+class XMLRPCProxyServer(object):
     """ not a real working server, but a stub for a proxy server connection
 
     """
     def __init__(self, host, port, use_builtin_types=True):
         self.host = host
         self.port = port
+        self._idlefuns = {}
 
-class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer):
+    def addcooker(self, cooker):
+        self.cooker = cooker
+
+    def register_idle_function(self, function, data):
+        """Register a function to be called while the server is idle"""
+        assert hasattr(function, '__call__')
+        self._idlefuns[function] = data
+
+
+class XMLRPCServer(SimpleXMLRPCServer):
     # remove this when you're done with debugging
     # allow_reuse_address = True
 
@@ -209,7 +218,7 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer):
         """
         Constructor
         """
-        BaseImplServer.__init__(self)
+        self._idlefuns = {}
         self.single_use = single_use
         # Use auto port configuration
         if (interface[1] == -1):
@@ -231,7 +240,7 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer):
         self.next_heartbeat = time.time()
 
     def addcooker(self, cooker):
-        BaseImplServer.addcooker(self, cooker)
+        self.cooker = cooker
         self.commands.cooker = cooker
 
     def autoregister_all_functions(self, context, prefix):
@@ -335,7 +344,13 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer):
     def set_connection_token(self, token):
         self.connection_token = token
 
-class BitBakeXMLRPCServerConnection(BitBakeBaseServerConnection):
+    def register_idle_function(self, function, data):
+        """Register a function to be called while the server is idle"""
+        assert hasattr(function, '__call__')
+        self._idlefuns[function] = data
+
+
+class BitBakeXMLRPCServerConnection(object):
     def __init__(self, serverImpl, clientinfo=("localhost", 0), observer_only = False, featureset = None):
         self.connection, self.transport = _create_server(serverImpl.host, serverImpl.port)
         self.clientinfo = clientinfo
@@ -388,7 +403,7 @@ class BitBakeXMLRPCServerConnection(BitBakeBaseServerConnection):
         except:
             pass
 
-class BitBakeServer(BitBakeBaseServer):
+class BitBakeServer(object):
     def initServer(self, interface = ("localhost", 0),
                    single_use = False, idle_timeout=0):
         self.interface = interface
@@ -405,7 +420,20 @@ class BitBakeServer(BitBakeBaseServer):
     def set_connection_token(self, token):
         self.connection.transport.set_connection_token(token)
 
-class BitBakeXMLRPCClient(BitBakeBaseServer):
+    def addcooker(self, cooker):
+        self.cooker = cooker
+        self.serverImpl.addcooker(cooker)
+
+    def getServerIdleCB(self):
+        return self.serverImpl.register_idle_function
+
+    def saveConnectionDetails(self):
+        return
+
+    def endSession(self):
+        self.connection.terminate()
+
+class BitBakeXMLRPCClient(object):
 
     def __init__(self, observer_only = False, token = None):
         self.token = token
@@ -446,3 +474,19 @@ class BitBakeXMLRPCClient(BitBakeBaseServer):
 
     def endSession(self):
         self.connection.removeClient()
+
+    def initServer(self):
+        self.serverImpl = None
+        self.connection = None
+        return
+
+    def addcooker(self, cooker):
+        self.cooker = cooker
+        self.serverImpl.addcooker(cooker)
+
+    def getServerIdleCB(self):
+        return self.serverImpl.register_idle_function
+
+    def detach(self):
+        return
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]