[bitbake-devel] [PATCH 08/15] remotedata: enable transporting datastore from the client to the server

Paul Eggleton paul.eggleton at linux.intel.com
Tue Dec 13 07:07:07 UTC 2016


For the purposes of server-side parsing and expansion allowing for
client-side use of the datastore, we need a means of sending a datastore
from the client back to the server, where the datastore probably
consists of a remote (server-side) original plus some client-side
modifications. To do this we need to take care of a couple of things:

1) xmlrpc can't handle nested dicts, so if you enable memres and simply
   try passing a serialised datastore then things break. Instead of
   serialising the entire datastore, just take the naive option of
   transferring the internal dict alone (as a list of tuples) for now.

2) Change the TinfoilDataStoreConnector object into simply the handle
   (number) when transmitting; it gets substituted with the real
   datastore when the server receives it.

Signed-off-by: Paul Eggleton <paul.eggleton at linux.intel.com>
---
 lib/bb/remotedata.py | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/lib/bb/remotedata.py b/lib/bb/remotedata.py
index 932ee43..68ecffc 100644
--- a/lib/bb/remotedata.py
+++ b/lib/bb/remotedata.py
@@ -72,3 +72,45 @@ class RemoteDatastores:
         if idx in self.locked:
             raise Exception('Tried to release locked datastore %d' % idx)
         del self.datastores[idx]
+
+    def receive_datastore(self, remote_data):
+        """Receive a datastore object sent from the client (as prepared by transmit_datastore())"""
+        dct = dict(remote_data)
+        d = bb.data_smart.DataSmart()
+        d.dict = dct
+        while True:
+            if '_remote_data' in dct:
+                dsindex = dct['_remote_data']['_content']
+                del dct['_remote_data']
+                if dsindex is None:
+                    dct['_data'] = self.cooker.data.dict
+                else:
+                    dct['_data'] = self.datastores[dsindex].dict
+                break
+            elif '_data' in dct:
+                idct = dict(dct['_data'])
+                dct['_data'] = idct
+                dct = idct
+            else:
+                break
+        return d
+
+    @staticmethod
+    def transmit_datastore(d):
+        """Prepare a datastore object for sending over IPC from the client end"""
+        # FIXME content might be a dict, need to turn that into a list as well
+        def copy_dicts(dct):
+            if '_remote_data' in dct:
+                dsindex = dct['_remote_data']['_content'].dsindex
+                newdct = dct.copy()
+                newdct['_remote_data'] = {'_content': dsindex}
+                return list(newdct.items())
+            elif '_data' in dct:
+                newdct = dct.copy()
+                newdata = copy_dicts(dct['_data'])
+                if newdata:
+                    newdct['_data'] = newdata
+                return list(newdct.items())
+            return None
+        main_dict = copy_dicts(d.dict)
+        return main_dict
-- 
2.5.5




More information about the bitbake-devel mailing list