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

# 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 time
    galaxyhome=os.environ.get('GALAXY_HOME')
    sys.path.append(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator/')    
    from creatorEngineComplex import *
    from wsdl2path import *
    from paramConverter import *
    from ZSI.writer import SoapWriter
    from collections import deque

__author__="Shefali Shastri"

def main():
    """

    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

    """
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")

        #galaxyhome=os.environ.get('GALAXY_HOME')
        #sys.path.append(galaxyhome+'/tools/SOAPclient/clients/clientGenerator/')
        os.chdir(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator/')
        webservice = str(sys.argv[5])
        #print 'WS ', webservice
        operation = str(sys.argv[6])
        #print 'OP ',operation
        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)
            while(val.find('__ob__')>-1):
                vlist = val.split('__ob__')
                val = '['.join(vlist)
            while(val.find('__cb__')>-1):
                vlist = val.split('__cb__')
                val = ']'.join(vlist)
            
            print 'value is : ',val
            
                #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
        print inputdict
        if len(inputdict) == 0:
            print 'empty inputs'
            inputdic = {}
        else:
            inputdic = flat2nestedDict(inputdict)    
        print 'the inputs are',inputdic
        result = None
        try:
            result = test.invokeOp(operation,webservice,inputdic)
        except:
            pass
        print 'The result before is ',result
        #print ps
        while result == None:
            time.sleep(2)
            print 'in loop'
            result = test.invokeOp(operation,webservice,inputdic)
        
        print 'The result after is',result

        # 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();
    



if __name__ == "__main__":
    main();