Skip to contentSkip to conversation

Webhob: webservice client

PATCH New Xiaotong lv 1 participant 2 messages Jun 15, 2012

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 Webhob: webservice client

In reply to Xiaotong lv

A webservice client wrapper class.

---
 .../bb/ui/webservice_client/client_webservice.py   |   63 ++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)
 create mode 100644 bitbake/lib/bb/ui/webservice_client/client_webservice.py
bitbake/lib/bb/ui/webservice_client/client_webservice.py new file +63 -0
new file mode 100644
index 0000000..e70ce36
@@ -0,0 +1,63 @@
+import sys
+import traceback
+try:
+    from suds.client import Client, WebFault
+except ImportError as e:
+    sys.exit('Error:Install suds python lib firstly\n%s' % str(e))
+try:
+    import simplejson as json
+except ImportError:
+    import json
+
+class Connection:
+    def __init__(self, wsUrl, cache=None):
+        self.wsUrl = wsUrl
+        self.cache = cache
+        try:
+            self.client = Client(wsUrl, cache=self.cache)
+        except Exception, e:
+            sys.exit(str(e))
+
+    def runCommand(self, command):
+        if not isinstance(command, list) or not command:
+            raise ValueError('command must be list type, and be not empty')
+        params = {}
+        param_type = []
+        params['function'] = command.pop(0)
+        for i in command:
+            if isinstance(i, list):
+                param_type.append(('list'," ".join(i)))
+            elif isinstance(i, bool):
+                param_type.append(('bool',bool(i)))
+            elif isinstance(i, str):
+                param_type.append(('string',str(i)))
+
+        if param_type:
+            params['param_type'] = {'string':[type for type, param in param_type]}
+            params['params'] = {'string':[param for type, param in param_type]}
+
+        try:
+            return self.client.service.runCommand(params)
+        except WebFault, f:
+            print f.fault
+        except Exception, e:
+            print e
+            traceback.print_exc()
+
+    def getEvent(self):
+        try:
+            event = self.client.service.getEvent()
+            if isinstance(event, unicode):
+                event = event.encode('utf-8')
+            o_event = json.loads(event)
+            return o_event['events']
+        except WebFault, f:
+            print f.fault
+        except Exception, e:
+            print e
+            traceback.print_exc()
+
+#only testing
+if __name__ == '__main__':
+    server = Connection('http://localhost:8888/?wsdl')
+    print server.runCommand(['getVariable', 'BBLAYERS'])
Signature · 1 line
1.7.4.4
#0 lore raw

cover Webhob: webservice client

this is a webservice python client based on suds.
if client is other different language. such as java, php, etc. we can use their corresponding webservice client program to call bitbake.

The following changes since commit cbe94009a060bc680bf196732642e295151b8ef9:

Webhob: a general helper interface based on webservice (2012-06-06 21:03:11 -0400)

are available in the git repository at:
git://git.yoctoproject.org/poky-contrib xtlv/webhob-webservice
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=xtlv/webhob-webservice

Xiaotong lv (1):
Webhob: webservice client

 .../bb/ui/webservice_client/client_webservice.py   |   63 ++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)
 create mode 100644 bitbake/lib/bb/ui/webservice_client/client_webservice.py
Signature · 1 line
1.7.4.4