Mercurial > repos > uga-galaxy-group > webservice_toolsuite_v1_1
view WebServiceExtensionsV1.1/WebServiceToolWorkflow_REST_SOAP/generateClient1_mc.py~ @ 0:049760c677de default tip
Galaxy WSExtensions added successfully
author | uga-galaxy-group |
---|---|
date | Tue, 05 Jul 2011 19:34:18 -0400 |
parents | |
children |
line wrap: on
line source
#generates client for a web service to be used as standalone import warnings with warnings.catch_warnings(): warnings.simplefilter("ignore") import platform from jpype._jpackage import JPackage from jpype import * import os.path import sys import string from edit_tool_conf1 import * from msHandler import * from creatorEngineComplex import * class ClientGenerator1(object): def __init__(self,webservice,operation,inputs): self.webservice = webservice self.operation = operation #self.resourceName=resourceName self.inputs = inputs cc = ClientCreator() self.msinstance = cc.opname2inputClassOb(self.operation,self.webservice) def formatString(self,string): l = string.split(' ') return '**'.join(l) def isRequired(self,param): required = False if param.find('|')>-1 : plist = param.split('|') root = test.getParameter(self.msinstance(),plist[0]) # Added if (param.find('|$|')>-1): print 'plist-------->',plist k = 0 iparam = '' for p in plist: if(k<len(plist)-3): if(k==0): iparam = iparam+(p) else: iparam = iparam+'|'+p k=k+1 paramelement = test.getParameter(self.msinstance(),iparam) #if not getattr(root,'nillable') or (getattr(root,'nillable') and not getattr(paramelement,'nillable')): # required = True else: paramelement = test.getParameter(self.msinstance(),param) if not getattr(root,'nillable') or (getattr(root,'nillable') and not getattr(paramelement,'nillable')): required = True else: paramelement = test.getParameter(self.msinstance(),param) if getattr(paramelement,'nillable')==False: required = True return required def wsdlClient(self): ##parse wsdl '''javahome = os.environ.get('JAVA_HOME') galaxyhome=os.environ.get('GALAXY_HOME') classpath= galaxyhome + '/tools/SOAPclient/SimpleWSDLParser/build/classes' jarpath = galaxyhome + '/tools/SOAPclient/SimpleWSDLParser/dist/lib/' machine = platform.machine() if machine == 'x86_64' : print 'a' startJVM("%s/jre/lib/amd64/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath) elif machine == 'i386' : print 'b' startJVM("/System/Library/Frameworks/JavaVM.framework/JavaVM","-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath) elif machine == 'sun4u' : startJVM("%s/jre/lib/sparc/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath) else : print 'c' System.exit("Could not identify machine, please specify path to libjvm.so") pkg=JPackage('edu.uga.cs.lsdis.wsdl') urlToPass=java.net.URL(self.url) wadlUrl = self.url webserviceId = self.methodName resUrl = self.resourceName urls = [] methods = [] params = [] WADLParserDriver=pkg.WADLParserDriver wPD=WADLParserDriver() wPD.parse(urlToPass) urls = wPD.getUrl() methods = wPD.getCompleteMethodList() ''' ##generate client's xml galaxyhome=os.environ.get('GALAXY_HOME') clientCountFile=open(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clients/ClientCount.xml','r') clientCountFile.readline() clientCountStr = clientCountFile.read(1) clientCount=string.atoi(clientCountStr) clientCount=clientCount+1 clientCountFile.close() clientCountFile=open(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clients/ClientCount.xml','w') clientCountFile.write('<count> \n') clientCountFile.write(str(clientCount)+'\n') clientCountFile.write('</count> \n') clientCountFile.close() clientName = 'client_'+ str(clientCount) clientXml=open(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clients/'+clientName+'.xml','w') clientXml.seek(0,0) clientXml.write('<tool id="' + clientName+'" name="' + self.operation +'">\n') clientXml.write(' <description> Client for operation : '+self.operation+' , Web service: '+self.webservice+' </description>\n') clientXml.write(' <command interpreter="python">\n #if $cond_source.optional_param_source=="no" #client_1.py'+' $output ' +self.webservice+' '+self.operation) #clientXml.write(' <command interpreter="python">\n client_1.py \n' +' $output \n ' +self.webservice+' \n '+self.operation+'\n') ##write such that the parameters passed to client1.py(change name to clientName.py) are dependent on a for loop test = MessageHandler() j=0 for param in self.inputs: required = False if param.find('|')>-1 : plist = param.split('|') root = test.getParameter(self.msinstance(),plist[0]) # Added if (param.find('|$|')>-1): print 'plist-------->',plist k = 0 iparam = '' for p in plist: if(k<len(plist)-3): if(k==0): iparam = iparam+(p) else: iparam = iparam+'|'+p k=k+1 paramelement = test.getParameter(self.msinstance(),iparam) #if (getattr(root,'nillable') and not getattr(paramelement,'nillable')): # required = True else: paramelement = test.getParameter(self.msinstance(),param) if getattr(root,'nillable'): required = False else: #if (not getattr(root,'nillable')) or (getattr(root,'nillable') and not getattr(paramelement,'nillable')): if (not getattr(paramelement,'nillable')): required = True else: required = False else: paramelement = test.getParameter(self.msinstance(),param) if getattr(paramelement,'nillable')==False: required = True if required: clientXml.write(' "'+param+'"') clientXml.write(' $param' + str(j)) j=j+1 clientXml.write(' #else #client_1.py'+' $output ' +self.webservice+' '+self.operation+'\n') j=0 for param in self.inputs: required = False if param.find('|')>-1 : plist = param.split('|') root = test.getParameter(self.msinstance(),plist[0]) if (param.find('|$|')>-1): plist = param.split('|') print 'plist-------->',plist k = 0 iparam = '' for p in plist: if(k<len(plist)-3): if(k==0): iparam = iparam+(p) else: iparam = iparam+'|'+p k=k+1 paramelement = test.getParameter(self.msinstance(),iparam) else: paramelement = test.getParameter(self.msinstance(),param) if getattr(root,'nillable'): required = False else: #if (getattr(root,'nillable') and not getattr(paramelement,'nillable')): if (not getattr(paramelement,'nillable')): required = True else: required = False else: paramelement = test.getParameter(self.msinstance(),param) if getattr(paramelement,'nillable')==False: required = True if required: clientXml.write(' "'+param+'"') clientXml.write(' $param' + str(j)) j=j+1 for param in self.inputs: required = False if param.find('|')>-1 : plist = param.split('|') root = test.getParameter(self.msinstance(),plist[0]) if (param.find('|$|')>-1): plist = param.split('|') print 'plist-------->',plist k = 0 iparam = '' for p in plist: if(k<len(plist)-3): if(k==0): iparam = iparam+(p) else: iparam = iparam+'|'+p k=k+1 paramelement = test.getParameter(self.msinstance(),iparam) else: paramelement = test.getParameter(self.msinstance(),param) if getattr(root,'nillable'): required = False else: #if (getattr(root,'nillable') and not getattr(paramelement,'nillable')): if (not getattr(paramelement,'nillable')): required = True else: required = False else: paramelement = test.getParameter(self.msinstance(),param) if(not getattr(paramelement,'nillable')): required = True if not required:#getattr(paramelement,'nillable')==True: clientXml.write(' "'+param+'"') clientXml.write(' $cond_source.param' + str(j)) j=j+1 #params for array type # for param in self.inputs: # paramelement = test.getParameter(self.msinstance(),param) # if getattr(paramelement,'nillable')==True: # if string.find(param,"|0|")>-1: # ele = string(param,"|0|") # for param in self.inputs: # clientXml.write(' "'+param+'"') # clientXml.write(' $cond_source.param' + str(j)) # j=j+1 clientXml.write(' #end if \n</command>\n') # for param in self.inputs: # paramelement = test.getParameter(self.msinstance(),param) # if getattr(paramelement,'nillable')==False or getattr(paramelement,'minOccurs')==1: # clientXml.write(' "'+param+'"\n') # clientXml.write(' $param'+str(j)+'\n') # j=j+1 #clientXml.write('</command>\n') ##write inputs depending on required or not. if not required den dont display ##if required- den check default value, and if options exist.Depending on that ##decide the type of parameter and options clientXml.write(' <inputs>\n') j=0 for param in self.inputs: required = False if param.find('|')>-1 : plist = param.split('|') root = test.getParameter(self.msinstance(),plist[0]) if (param.find('|$|')>-1): plist = param.split('|') print 'plist-------->',plist k = 0 iparam = '' for p in plist: if(k<len(plist)-3): if(k==0): iparam = iparam+(p) else: iparam = iparam+'|'+p k=k+1 paramelement = test.getParameter(self.msinstance(),iparam) else: paramelement = test.getParameter(self.msinstance(),param) if getattr(root,'nillable'): required = False else: #if (getattr(root,'nillable') and not getattr(paramelement,'nillable')): if (not getattr(paramelement,'nillable')): required = True else: required = False else: paramelement = test.getParameter(self.msinstance(),param) if getattr(paramelement,'nillable')==False: required = True #if (param.find('|$|')>-1): # plist = param.split('|') # print 'plist-------->',plist # k = 0 # param = '' # for p in plist: # if(k<len(plist)-3): # if(k==0): # param = param+(p) # else: # param = param+'|'+p # k=k+1 #paramelement = test.getParameter(self.msinstance(),param) if required:#getattr(paramelement,'nillable')==False: pName = getattr(paramelement,'pname') clientXml.write('<param format="text" size = "150" name = "param'+str(j)+'" ') clientXml.write('type="text" label="Enter '+pName+'" help="see tip below" />\n') j=j+1 clientXml.write('\n <conditional name="cond_source"> \n <param name="optional_param_source" type="select" label="Show Additional Parameters">\n <option value="no" selected="true">no</option> \n <option value="yes">yes</option> \n </param>\n') clientXml.write('<when value="no"> \n </when>') clientXml.write('<when value="yes"> \n') for param in self.inputs: required = False if param.find('|')>-1 : plist = param.split('|') root = test.getParameter(self.msinstance(),plist[0]) if (param.find('|$|')>-1): plist = param.split('|') print 'plist-------->',plist k = 0 iparam = '' for p in plist: if(k<len(plist)-3): if(k==0): iparam = iparam+(p) else: iparam = iparam+'|'+p k=k+1 paramelement = test.getParameter(self.msinstance(),iparam) else: paramelement = test.getParameter(self.msinstance(),param) if getattr(root,'nillable'): required = False else: #if (getattr(root,'nillable') and not getattr(paramelement,'nillable')): if (not getattr(paramelement,'nillable')): required = True else: required = False else: paramelement = test.getParameter(self.msinstance(),param) if getattr(paramelement,'nillable')==False: required = True # if (param.find('|$|')>-1): # plist = param.split('|') # print 'plist-------->',plist # k = 0 # param = '' # for p in plist: # if(k<len(plist)-3): # if(k==0): # param = param+(p) # else: # param = param+'|'+p # k=k+1 # paramelement = test.getParameter(self.msinstance(),param) if not required:#getattr(paramelement,'nillable'): pName = getattr(paramelement,'pname') clientXml.write('<param format="text" size = "150" name = "param'+str(j)+'" ') clientXml.write('type="text" label="Enter '+pName+'" help="see tip below" />\n') j=j+1 clientXml.write('</when>\n</conditional>') # j=0 # for param in self.inputs: # paramelement = test.getParameter(self.msinstance(),param) # if not getattr(paramelement,'nillable'): # pName = getattr(paramelement,'pname')#param.getName() # clientXml.write('<param format="text" size = "150" name = "param'+str(j)+'" ') # clientXml.write('type="text" label="'+pName+'" help="see tip below" />\n') # j=j+1 clientXml.write('</inputs>\n <outputs>\n <data format="tabular" name="output" />\n </outputs>\n') clientXml.write(' <help>\n') paramtype = None for param in self.inputs: required = False if param.find('|')>-1 : plist = param.split('|') root = test.getParameter(self.msinstance(),plist[0]) if (param.find('|$|')>-1): plist = param.split('|') print 'plist-------->',plist k = 0 iparam = '' for p in plist: if(k<len(plist)-3): if(k==0): iparam = iparam+(p) else: iparam = iparam+'|'+p k=k+1 paramelement = test.getParameter(self.msinstance(),iparam) else: paramelement = test.getParameter(self.msinstance(),param) if getattr(root,'nillable'): required = False else: #if (getattr(root,'nillable') and not getattr(paramelement,'nillable')): if (not getattr(paramelement,'nillable')): required = True else: required = False else: paramelement = test.getParameter(self.msinstance(),param) if getattr(paramelement,'nillable')==False: required = True # if (param.find('|$|')>-1): # plist = param.split('|') # print 'plist-------->',plist # k = 0 # param = '' # for p in plist: # if(k<len(plist)-3): # if(k==0): # param = param+(p) # else: # param = param+'|'+p # k=k+1 # paramelement = test.getParameter(self.msinstance(),param) if required:#getattr(paramelement,'nillable')==False: if isinstance(paramelement,ZSI.TC.String): paramtype = 'String' elif isinstance(paramelement,ZSI.TCnumbers.FPfloat): paramtype = 'Floating point' elif isinstance(paramelement,ZSI.TC.Boolean): paramtype = 'Boolean' elif isinstance(paramelement,ZSI.TCnumbers.Iint): paramtype = 'Integer' clientXml.write('\n.. class:: infomark\n\n**TIP:** About '+ getattr(paramelement,'pname') +': type is ' + paramtype + '\n') clientXml.write(' </help>\n</tool>') # clientXml.write(' <help>\n') # j=0 # for param in params: # clientXml.write('\n.. class:: infomark\n\n**TIP:** '+ param +' type is ' + paramTypes[j] +'\n') # clientXml.write(' </help>\n</tool>') # clientXml.write('</tool>') clientXml.close() editor = editToolConfig1() editor.addTool(clientName) ##later add help feature def sawsdlClient(self): ##parse wadl javahome = os.environ.get('JAVA_HOME') galaxyhome=os.environ.get('GALAXY_HOME') classpath= galaxyhome + '/tools/WebServiceTool/WodenWSDLParser/bin' jarpath = galaxyhome + '/tools/WebServiceTool/WodenWSDLParser/lib/' machine = platform.machine() if machine == 'x86_64' : print 'a' startJVM("%s/jre/lib/amd64/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath) elif machine == 'i686' : print 'b' startJVM("%s/jre/lib/i386/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath) elif machine == 'sun4u' : startJVM("%s/jre/lib/sparc/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath) else : print 'c' System.exit("Could not identify machine, please specify path to libjvm.so") pkg=JPackage('lsdis') wsdlUrl = self.url webserviceId = self.methodName resUrl = self.resourceName urls = [] methods = [] params = [] paramTypes = [] WSDLParserDriver =pkg.WSDLParserDriver wPD=WSDLParserDriver() wPD.parse(wsdlUrl) methods = wPD.getCompleteMethodList() urls = wPD.getUrl() f=open(self.Ofile,'w') f.write(wsdlUrl) f.write('\n'+ resUrl) f.write('\n'+webserviceId) i=0 for method in methods: x = str(method.getName().getLocalPart()) if x == webserviceId : wPD.getParameters(x) f.write('method matched') paramTypes = wPD.getParamTypeList() params = wPD.getParamList() break i=i+1 ##generate client's xml galaxyhome=os.environ.get('GALAXY_HOME') clientCountFile=open(galaxyhome+'/tools/WebServiceTool/clients/ClientCount.xml','r') clientCountFile.readline() clientCountStr = clientCountFile.read(1) clientCount=string.atoi(clientCountStr) clientCount=clientCount+1 clientCountFile.close() clientCountFile=open(galaxyhome+'/tools/WebServiceTool/clients/ClientCount.xml','w') clientCountFile.write('<count> \n') clientCountFile.write(str(clientCount)) clientCountFile.write('</count> \n') clientName = 'client_'+ str(clientCount) clientXml=open(galaxyhome+'/tools/WebServiceTool/clients/'+clientName+'.xml','w') clientXml.seek(0,0) clientXml.write('<tool id="' + clientName+'" name="' + self.methodName +'">\n') clientXml.write(' <description> Client for method: '+self.methodName+' , Web service: '+self.url+' </description>\n') clientXml.write(' <command interpreter="python">\n client_1.py \n'+' $output \n ' +resUrl+'\n') ##write such that the parameters passed to client1.py(change name to clientName.py) are dependent on a for loop j=0 for param in params: clientXml.write(' '+self.formatString(param)+'\n') clientXml.write(' $param' + str(j)+'\n') j=j+1 clientXml.write('</command>\n') ##write inputs depending on required or not. if not required den dont display ##if required- den check default value, and if options exist.Depending on that ##decide the type of parameter and options clientXml.write(' <inputs>\n') j=0 for param in params: clientXml.write('<param format="text" size = "150" name = "param'+str(j)+'" ') clientXml.write('type="text" label="'+param+'" help="see tip below" />\n') j=j+1 clientXml.write('</inputs>\n <outputs>\n <data format="tabular" name="output" />\n </outputs>\n') clientXml.write(' <help>\n') clientXml.write('** Replace white with ** in all parameter values **\n') j=0 for param in params: clientXml.write('\n.. class:: infomark\n\n**TIP:** '+ param +' type is ' + paramTypes[j] +'\n') clientXml.write(' </help>\n</tool>') editor = editToolConfig1() editor.addTool(clientName) ##later add help feature