Patchwork [bitbake-devel,1/1] Webhob: webservice client

login
register
mail settings
Submitter Xiaotong lv
Date June 16, 2012, 1:23 a.m.
Message ID <303a74c28fb34b1f0d40005a7bd197ea061c4e49.1339809365.git.xiaotongx.lv@intel.com>
Download mbox | patch
Permalink /patch/29909/
State New
Headers show

Comments

Xiaotong lv - June 16, 2012, 1:23 a.m.
A webservice client wrapper class.

Signed-off-by: Xiaotong Lv <xiaotongx.lv@intel.com>
---
 .../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

Patch

diff --git a/bitbake/lib/bb/ui/webservice_client/client_webservice.py b/bitbake/lib/bb/ui/webservice_client/client_webservice.py
new file mode 100644
index 0000000..e70ce36
--- /dev/null
+++ b/bitbake/lib/bb/ui/webservice_client/client_webservice.py
@@ -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'])