Mercurial > repos > uga-galaxy-group > webservice_toolsuite_v1_1
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 | |
32 webservice = str(sys.argv[5]) | |
33 operation = str(sys.argv[6]) | |
34 resultfile=open(sys.argv[1],'w') | |
35 length=len(sys.argv) | |
36 inputdict={} | |
37 i=7 | |
38 test=ClientCreator() | |
39 while(i>=7 and i<(length-1)): | |
40 key=sys.argv[i] | |
41 print 'key is : ',key | |
42 #if(sys.argv[i+1]=='ZSI.TC.String'): | |
43 val=sys.argv[i+1] | |
44 while(val.find('__at__')>-1): | |
45 vlist = val.split('__at__') | |
46 val = '@'.join(vlist) | |
47 while(val.find('__sq__')>-1): | |
48 vlist = val.split('__sq__') | |
49 val = ''.join(vlist) | |
50 while(val.find('__gt__')>-1): | |
51 vlist = val.split('__gt__') | |
52 val = '>'.join(vlist) | |
53 while(val.find('***')>-1): | |
54 vlist = val.split('***') | |
55 val = '\n'.join(vlist) | |
56 while(val.find('**')>-1): | |
57 vlist = val.split('**') | |
58 val = ' '.join(vlist) | |
59 #if(val.find(',')>-1): | |
60 # print 'found ,' | |
61 # vlist = val.split(',') | |
62 # val = '\',\''.join(vlist) | |
63 | |
64 | |
65 #if(val.find('__sq__')>-1): | |
66 # j=i+4 | |
67 # val=val.lstrip('__sq__') | |
68 # while(str(sys.argv[j]).find('__sq__')==-1): | |
69 # val=val+' '+sys.argv[j] | |
70 # j=j+1 | |
71 #val=val+' '+(str(sys.argv[j]).rstrip('__sq__')) | |
72 #i=j-3 | |
73 | |
74 #elif((sys.argv[i+1]=='ZSI.TC.Integer')or (sys.argv[i+1]=='ZSI.TCnumbers.Iint')): | |
75 # val=int(sys.argv[i+1]) | |
76 #elif(sys.argv[i+1]=='ZSI.TC.Decimal'): | |
77 # val=float(sys.argv[i+1]) | |
78 #elif(sys.argv[i+2]=='Yes'): | |
79 # valFile=open(sys.argv[i+3],'r') | |
80 # val=valFile.read() | |
81 #else: | |
82 # val=sys.argv[i+1] | |
83 if val == 'fileInput': | |
84 f = open(sys.argv[i+2]) | |
85 #line = f.readline() | |
86 val = '' | |
87 #for j in line: | |
88 # val = val+j | |
89 #linestripped = line.strip('\n') | |
90 for line in f: | |
91 #line = f.readline().strip('\n') | |
92 #line = line.strip(' ') | |
93 | |
94 val = val+line | |
95 val = val.strip("\n") | |
96 print val | |
97 i = i+1 | |
98 | |
99 if(val != "0"): | |
100 inputdict[key]= val | |
101 #resultfile.write('value is :'+ val+'\n') | |
102 | |
103 i=i+2 | |
104 if len(inputdict) == 0: | |
105 inputdic = {} | |
106 else: | |
107 inputdic = flat2nestedDict(inputdict) | |
108 print 'The webservice is : ',operation,' ',webservice #added | |
109 result = None | |
110 try: | |
111 result = test.invokeOp(operation,webservice,inputdic) | |
112 except: | |
113 pass | |
114 print 'The result before is ',result | |
115 while result == None: | |
116 time.sleep(2) | |
117 print 'in loop' | |
118 try: | |
119 result = test.invokeOp(operation,webservice,inputdic) | |
120 except: | |
121 pass | |
122 print 'result in loop ',result | |
123 | |
124 print 'The result after is',result | |
125 | |
126 # Writing the output to he o/p file when the result is parsed | |
127 for r in result: | |
128 if type(result[r])==list: | |
129 for i in result[r]: | |
130 resultfile.write(str(i)+'\n') | |
131 print str(i) | |
132 else: | |
133 resultfile.write(str(result[r])+'\n') | |
134 | |
135 #Writes the result without parsinf in the XML format it gets. | |
136 #sw = SoapWriter(header=False, envelope=False); | |
137 #res = test.opname2outputClassOb(operation,webservice) | |
138 #res_tc = getattr(res,'typecode') | |
139 #ofwhat = res_tc.ofwhat; | |
140 #for tc in ofwhat : | |
141 # sw.serialize(getattr(result, tc.aname), tc); | |
142 # doc = sw.dom.getDocument(); | |
143 # fp = open(sys.argv[1], 'w'); | |
144 # try : | |
145 # doc.writexml(fp, '\t', '', '\n'); | |
146 # finally : | |
147 # fp.close(); | |
148 | |
149 | |
150 elif servicetype == 'REST': | |
151 | |
152 outputFile = open(sys.argv[1],'w') | |
153 resUrl = sys.argv[3] | |
154 | |
155 if(resUrl.find('__tilda__')>-1): | |
156 ulist = resUrl.split('__tilda__') | |
157 resUrl = '~'.join(ulist) | |
158 | |
159 paramdict={} | |
160 length=(len(sys.argv)) | |
161 | |
162 i=6 | |
163 while( i>=6 and i<(length-1)): | |
164 key=sys.argv[i] | |
165 val=sys.argv[i+1] | |
166 if val=='fileInput': | |
167 print '##########fileInput found#############' | |
168 f=open(sys.argv[i+2]) | |
169 line = f.readline().strip('\n') | |
170 line = line.strip(' ') | |
171 val = line | |
172 i=i+1 | |
173 | |
174 while(val.find('**')>-1): | |
175 vlist = val.split('**') | |
176 val = ' '.join(vlist) | |
177 print key + '\t' + val | |
178 paramdict[key]=val | |
179 i=i+2 | |
180 | |
181 params = urllib.urlencode(paramdict) | |
182 data = urllib.urlopen(resUrl, params).read() | |
183 outputFile.write(data) | |
184 outputFile.close() | |
185 |