view WebServiceExtensionsV1.1/WebServiceToolWorkflow_REST_SOAP/workflowclients/client_1.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

'''
@author  Chaitanya Guttula, Sumedha Ganjoo
@see     LICENSE (MIT style license file).
'''
# To change this template, choose Tools | Templates
# and open the template in the editor.
import warnings
with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    import sys
    import os
    import urllib
    import time
    
    """
    
    This script takes the values of the input parameters of the
    web service from the user and invokes the web service.
    The URL to the WSDL is the command line argument

    """
    servicetype = sys.argv[2]
    if servicetype=='SOAP':
        galaxyhome=os.environ.get('GALAXY_HOME')
        sys.path.append(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator/')
        os.chdir(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator/')
        from creatorEngineComplex import *
        from wsdl2path import *
        from paramConverter import *
        from ZSI.writer import SoapWriter
        from msHandler import *

        webservice = str(sys.argv[5])
        operation = str(sys.argv[6])
        resultfile=open(sys.argv[1],'w')
        length=len(sys.argv)
        inputdict={}
        i=7
        test=ClientCreator()
        while(i>=7 and i<(length-1)):
            key=sys.argv[i]
            print 'key is : ',key
            #if(sys.argv[i+1]=='ZSI.TC.String'):
            val=sys.argv[i+1]
            while(val.find('__at__')>-1):
                vlist = val.split('__at__')
                val = '@'.join(vlist)
            while(val.find('__sq__')>-1):
                vlist = val.split('__sq__')
                val = ''.join(vlist)
            while(val.find('__gt__')>-1):
                vlist = val.split('__gt__')
                val = '>'.join(vlist)
            while(val.find('***')>-1):
                vlist = val.split('***')
                val = '\n'.join(vlist)
            while(val.find('**')>-1):
                vlist = val.split('**')
                val = ' '.join(vlist)
            #if(val.find(',')>-1):
            #    print 'found ,'
            #    vlist = val.split(',')
            #    val = '\',\''.join(vlist)
                
                
            #if(val.find('__sq__')>-1):
             #   j=i+4
              #  val=val.lstrip('__sq__')
               # while(str(sys.argv[j]).find('__sq__')==-1):
                #    val=val+' '+sys.argv[j]
                 #   j=j+1
                #val=val+' '+(str(sys.argv[j]).rstrip('__sq__'))
                #i=j-3

        #elif((sys.argv[i+1]=='ZSI.TC.Integer')or (sys.argv[i+1]=='ZSI.TCnumbers.Iint')):
        #   val=int(sys.argv[i+1])
       #elif(sys.argv[i+1]=='ZSI.TC.Decimal'):
         #   val=float(sys.argv[i+1])
        #elif(sys.argv[i+2]=='Yes'):
         #   valFile=open(sys.argv[i+3],'r')
          #  val=valFile.read()
        #else:
        #   val=sys.argv[i+1]
            if val == 'fileInput':
                f = open(sys.argv[i+2])
                #line = f.readline()
                val = ''
                #for j in line:
                #   val = val+j
                #linestripped = line.strip('\n')
                for line in f:
                    #line = f.readline().strip('\n')
                    #line = line.strip(' ')
                        
                    val = val+line
                val = val.strip("\n")
                print val
                i = i+1
            
            if(val != "0"): 
                inputdict[key]= val
            #resultfile.write('value is :'+ val+'\n')
            
            i=i+2
        if len(inputdict) == 0:
            inputdic = {}
        else:
            inputdic = flat2nestedDict(inputdict)    
        print 'The webservice is : ',operation,' ',webservice #added
        result = None
        try:
            result = test.invokeOp(operation,webservice,inputdic)
        except:
            pass
        print 'The result before is ',result
        while result == None:
            time.sleep(2)
            print 'in loop'
            try:
                result = test.invokeOp(operation,webservice,inputdic)
            except:
                pass
            print 'result in loop ',result
        
        print 'The result after is',result

        mshandler = MessageHandler()
        resultDict={}
        resultDict=mshandler.flatten(result)   #mshandler.msParser(responseInstance)
        flat =  nested2flatDict(resultDict)
	result=flat

        # Writing the output to he o/p file when the result is parsed
        for r in result:
           if type(result[r])==list:
                   for i in result[r]:
                           resultfile.write(str(i)+'\n')
                           print str(i)
           else:
                   resultfile.write(str(result[r])+'\n')

        #Writes the result without parsinf in the XML format it gets.
        #sw = SoapWriter(header=False, envelope=False);
        #res = test.opname2outputClassOb(operation,webservice)
        #res_tc = getattr(res,'typecode')
        #ofwhat = res_tc.ofwhat;
        #for tc in ofwhat :
        #    sw.serialize(getattr(result, tc.aname), tc);
        #    doc = sw.dom.getDocument();
        #    fp = open(sys.argv[1], 'w');
        #    try :
        #        doc.writexml(fp, '\t', '', '\n');
        #    finally :
        #        fp.close();
   

    elif servicetype == 'REST':

        outputFile = open(sys.argv[1],'w')
        resUrl = sys.argv[3]

        if(resUrl.find('__tilda__')>-1):
            ulist = resUrl.split('__tilda__')
            resUrl = '~'.join(ulist)
    
        paramdict={}
        length=(len(sys.argv))

        i=6
        while( i>=6 and i<(length-1)):
            key=sys.argv[i]
            val=sys.argv[i+1]
            if val=='fileInput':
                print '##########fileInput found#############'
                f=open(sys.argv[i+2])
                line = f.readline().strip('\n')
                line = line.strip(' ')
                val = line        
                i=i+1
    
            while(val.find('**')>-1):
                vlist = val.split('**')
        	val = ' '.join(vlist)
            print key + '\t' + val
            paramdict[key]=val
            i=i+2

        params = urllib.urlencode(paramdict)
        data = urllib.urlopen(resUrl, params).read()
        outputFile.write(data)
        outputFile.close()