From patchwork Sat Jun 16 01:23:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [bitbake-devel,1/1] Webhob: webservice client Date: Sat, 16 Jun 2012 01:23:30 -0000 From: Xiaotong lv X-Patchwork-Id: 29909 Message-Id: <303a74c28fb34b1f0d40005a7bd197ea061c4e49.1339809365.git.xiaotongx.lv@intel.com> To: bitbake-devel@lists.openembedded.org A webservice client wrapper class. Signed-off-by: Xiaotong Lv --- .../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'])