comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:049760c677de
1 '''
2 @author Chaitanya Guttula, Sumedha Ganjoo
3 @see LICENSE (MIT style license file).
4 '''
5 # To change this template, choose Tools | Templates
6 # and open the template in the editor.
7 import warnings
8 with warnings.catch_warnings():
9 warnings.simplefilter("ignore")
10 import sys
11 import os
12 import urllib
13 import time
14
15 """
16
17 This script takes the values of the input parameters of the
18 web service from the user and invokes the web service.
19 The URL to the WSDL is the command line argument
20
21 """
22 servicetype = sys.argv[2]
23 if servicetype=='SOAP':
24 galaxyhome=os.environ.get('GALAXY_HOME')
25 sys.path.append(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator/')
26 os.chdir(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator/')
27 from creatorEngineComplex import *
28 from wsdl2path import *
29 from paramConverter import *
30 from ZSI.writer import SoapWriter
31 from msHandler import *
32
33 webservice = str(sys.argv[5])
34 operation = str(sys.argv[6])
35 resultfile=open(sys.argv[1],'w')
36 length=len(sys.argv)
37 inputdict={}
38 i=7
39 test=ClientCreator()
40 while(i>=7 and i<(length-1)):
41 key=sys.argv[i]
42 print 'key is : ',key
43 #if(sys.argv[i+1]=='ZSI.TC.String'):
44 val=sys.argv[i+1]
45 while(val.find('__at__')>-1):
46 vlist = val.split('__at__')
47 val = '@'.join(vlist)
48 while(val.find('__sq__')>-1):
49 vlist = val.split('__sq__')
50 val = ''.join(vlist)
51 while(val.find('__gt__')>-1):
52 vlist = val.split('__gt__')
53 val = '>'.join(vlist)
54 while(val.find('***')>-1):
55 vlist = val.split('***')
56 val = '\n'.join(vlist)
57 while(val.find('**')>-1):
58 vlist = val.split('**')
59 val = ' '.join(vlist)
60 #if(val.find(',')>-1):
61 # print 'found ,'
62 # vlist = val.split(',')
63 # val = '\',\''.join(vlist)
64
65
66 #if(val.find('__sq__')>-1):
67 # j=i+4
68 # val=val.lstrip('__sq__')
69 # while(str(sys.argv[j]).find('__sq__')==-1):
70 # val=val+' '+sys.argv[j]
71 # j=j+1
72 #val=val+' '+(str(sys.argv[j]).rstrip('__sq__'))
73 #i=j-3
74
75 #elif((sys.argv[i+1]=='ZSI.TC.Integer')or (sys.argv[i+1]=='ZSI.TCnumbers.Iint')):
76 # val=int(sys.argv[i+1])
77 #elif(sys.argv[i+1]=='ZSI.TC.Decimal'):
78 # val=float(sys.argv[i+1])
79 #elif(sys.argv[i+2]=='Yes'):
80 # valFile=open(sys.argv[i+3],'r')
81 # val=valFile.read()
82 #else:
83 # val=sys.argv[i+1]
84 if val == 'fileInput':
85 f = open(sys.argv[i+2])
86 #line = f.readline()
87 val = ''
88 #for j in line:
89 # val = val+j
90 #linestripped = line.strip('\n')
91 for line in f:
92 #line = f.readline().strip('\n')
93 #line = line.strip(' ')
94
95 val = val+line
96 val = val.strip("\n")
97 print val
98 i = i+1
99
100 if(val != "0"):
101 inputdict[key]= val
102 #resultfile.write('value is :'+ val+'\n')
103
104 i=i+2
105 if len(inputdict) == 0:
106 inputdic = {}
107 else:
108 inputdic = flat2nestedDict(inputdict)
109 print 'The webservice is : ',operation,' ',webservice #added
110 result = None
111 try:
112 result = test.invokeOp(operation,webservice,inputdic)
113 except:
114 pass
115 print 'The result before is ',result
116 while result == None:
117 time.sleep(2)
118 print 'in loop'
119 try:
120 result = test.invokeOp(operation,webservice,inputdic)
121 except:
122 pass
123 print 'result in loop ',result
124
125 print 'The result after is',result
126
127 mshandler = MessageHandler()
128 resultDict={}
129 resultDict=mshandler.flatten(result) #mshandler.msParser(responseInstance)
130 flat = nested2flatDict(resultDict)
131 result=flat
132
133 # Writing the output to he o/p file when the result is parsed
134 for r in result:
135 if type(result[r])==list:
136 for i in result[r]:
137 resultfile.write(str(i)+'\n')
138 print str(i)
139 else:
140 resultfile.write(str(result[r])+'\n')
141
142 #Writes the result without parsinf in the XML format it gets.
143 #sw = SoapWriter(header=False, envelope=False);
144 #res = test.opname2outputClassOb(operation,webservice)
145 #res_tc = getattr(res,'typecode')
146 #ofwhat = res_tc.ofwhat;
147 #for tc in ofwhat :
148 # sw.serialize(getattr(result, tc.aname), tc);
149 # doc = sw.dom.getDocument();
150 # fp = open(sys.argv[1], 'w');
151 # try :
152 # doc.writexml(fp, '\t', '', '\n');
153 # finally :
154 # fp.close();
155
156
157 elif servicetype == 'REST':
158
159 outputFile = open(sys.argv[1],'w')
160 resUrl = sys.argv[3]
161
162 if(resUrl.find('__tilda__')>-1):
163 ulist = resUrl.split('__tilda__')
164 resUrl = '~'.join(ulist)
165
166 paramdict={}
167 length=(len(sys.argv))
168
169 i=6
170 while( i>=6 and i<(length-1)):
171 key=sys.argv[i]
172 val=sys.argv[i+1]
173 if val=='fileInput':
174 print '##########fileInput found#############'
175 f=open(sys.argv[i+2])
176 line = f.readline().strip('\n')
177 line = line.strip(' ')
178 val = line
179 i=i+1
180
181 while(val.find('**')>-1):
182 vlist = val.split('**')
183 val = ' '.join(vlist)
184 print key + '\t' + val
185 paramdict[key]=val
186 i=i+2
187
188 params = urllib.urlencode(paramdict)
189 data = urllib.urlopen(resUrl, params).read()
190 outputFile.write(data)
191 outputFile.close()
192