[bitbake-devel] [PATCH 1/1] Webhob: webservice client
Xiaotong lv
xiaotongx.lv at intel.com
Sat Jun 16 01:23:30 UTC 2012
A webservice client wrapper class.
Signed-off-by: Xiaotong Lv <xiaotongx.lv at 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
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'])
--
1.7.4.4
More information about the bitbake-devel
mailing list