comparison WebServiceExtensionsV1.1/install.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 # To change this template, choose Tools | Templates
2 # and open the template in the editor.
3
4 __author__ = "Chaitanya Guttula"
5
6
7 import os
8 import sys
9 from shutil import copytree, ignore_patterns
10
11 galaxyhome=os.environ.get('GALAXY_HOME')
12 #print galaxyhome
13
14 #os.mkdir(galaxyhome+'/GAL')
15 dirfilelist=os.listdir(galaxyhome+'/tools')
16 exist = False
17 for dirfile in dirfilelist:
18 if dirfile == 'WebServiceToolWorkflow_REST_SOAP':
19 exist = True
20 break
21
22 if exist:
23 print 'WebServiceToolWorkflow_REST_SOAP is already present in '+galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP'
24 else:
25 copytree('WebServiceToolWorkflow_REST_SOAP',galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP', ignore=ignore_patterns('*.pyc', 'tmp*'))
26 print 'Copied the folder \'WebServiceToolWorkflow_REST_SOAP\' to '+galaxyhome+'/tools'
27
28 f1=open(galaxyhome+'/tool_conf.xml','r')
29 f1.seek(0,0)
30 f2=open(galaxyhome+'/tool_conf_backup.xml','w')
31 f2.seek(0,0)
32
33 #copy the first line <toolbox> into another file f2
34 line = f1.readline()
35 #f2.write(line)
36
37 lineStripped=line.lstrip()
38 lineStripped=lineStripped.rstrip()
39
40 #Flags for verifying that the tool is not already installed
41 tool_present = False
42 webservice_present = False
43 workflow_present = False
44
45 # Check of the tools are already installed or not
46 # and sets the flags to true if they are already installed
47 while not lineStripped == '</toolbox>':
48 line = f1.readline()
49 lineStripped = line.lstrip()
50 lineStripped=lineStripped.rstrip()
51 if(lineStripped.find('<!--')>-1):
52 line = f1.readline()
53 while(not line.find('-->')>-1):
54 line = f1.readline()
55
56 if lineStripped == '<section name="Add Web service tool(s)" id="RegisterWebService">':
57 tool_present = True
58 elif lineStripped == '<section name="Select Web Service Tool" id="WebServices">':
59 webservice_present = True
60 elif lineStripped == '<section name="Select Web Service Workflow Tool" id="WebServiceWorkflow">':
61 workflow_present = True
62
63
64 f1.seek(0,0)
65 line = f1.readline()
66 f2.write(line)
67
68 lineStripped=line.lstrip()
69 lineStripped=lineStripped.rstrip()
70
71 # copy to the file f2 till <toolbox>
72 while not lineStripped == '<toolbox>':
73 line = f1.readline()
74 f2.write(line)
75 lineStripped = line.lstrip()
76 lineStripped = lineStripped.rstrip()
77
78 # Check if the tool is not installed and then add it to the file f2
79 if not tool_present:
80 f2.write(' <section name="Add Web service tool(s)" id="RegisterWebService">\n')
81 f2.write(' <tool file="WebServiceToolWorkflow_REST_SOAP/WebServiceTool_input_url_REST_SOAP.xml"/>\n')
82 f2.write(' <tool file="WebServiceToolWorkflow_REST_SOAP/WebServiceTool_input_method_REST_SOAP.xml"/>\n')
83 f2.write(' <tool file="WebServiceToolWorkflow_REST_SOAP/refreshTool.xml"/>\n')
84 f2.write(' </section>\n')
85 print 'The "Add Web Service Tool" added successfully'
86 else:
87 print 'The "Add Web service tool" tool is already present'
88
89
90 # Check if the section "Web Service Tools" is not installed and then add it to the file f2
91 if not webservice_present:
92 f2.write(' <section name="Select Web Service Tool" id="WebServices">\n')
93 f2.write('\n')
94 f2.write(' </section>\n')
95 print 'The "Web Service Tools" added successfully'
96 else:
97 print 'The section "Web Service Tools" is already present'
98
99
100 # Check if the Section "Web Service Workflow Tools" is not installed and then add it to the file f2
101 if not workflow_present:
102 f2.write(' <section name="Select Web Service Workflow Tool" id="WebServiceWorkflow">\n')
103 f2.write('\n')
104 f2.write(' </section>\n')
105 print 'The section "Web Service Workflow Tools" is added successfully'
106 else:
107 print 'The section "Web Service Workflow Tools" is already present'
108
109
110 #copy rest of tool_conf.xml file to f2
111 while not lineStripped == '</toolbox>':
112 line = f1.readline()
113 f2.write(line)
114 lineStripped = line.lstrip()
115 lineStripped=lineStripped.rstrip()
116 #else:
117 # print line
118
119 ##close f1 and f2
120 f1.close()
121 f2.close()
122
123 ##interchange modes of f1 and f2
124 f1=open(galaxyhome+'/tool_conf.xml','w')
125 f1.seek(0,0)
126 f2=open(galaxyhome+'/tool_conf_backup.xml','r')
127 f2.seek(0,0)
128
129 line = f2.readline()
130 f1.write(line)
131
132 lineStripped=line.lstrip()
133 lineStripped = lineStripped.rstrip()
134
135 ##write entire f2 into f1 (reverse roles)
136 while not lineStripped == '</toolbox>':
137 line = f2.readline()
138 f1.write(line)
139 lineStripped = line.lstrip()
140 lineStripped = lineStripped.rstrip()
141 #else:
142 # print line
143
144 f1.close()
145 f2.close()
146
147
148 # Adding Code to __init__.py in lib/galaxy/tools folder in Galaxy for disabling Web service stand alone tools in Workflows
149 f1 = open(galaxyhome+'/lib/galaxy/tools/__init__.py','r')
150 f1.seek(0,0)
151
152 exist = False
153 line = f1.readline()
154 linestripped = line.lstrip()
155 linestripped = linestripped.rstrip()
156 while line != '':
157 # if(linsetripped.find('\'\'\'')>-1):
158 # line = f1.readline()
159 # while(not line.find('\'\'\'')>-1):
160 # line = f1.readline()
161 if(linestripped == 'if self.id.find("WebService")>-1:'):
162 exist = True
163 break
164 line = f1.readline()
165 linestripped = line.lstrip()
166 linestripped = linestripped.rstrip()
167
168 if exist :
169 print 'Workflow code is already present in __init__.py'
170 else:
171 f2 = open(galaxyhome+'/lib/galaxy/tools/__init__backup.py','w')
172 f2.seek(0,0)
173 f1.seek(0,0)
174 line = f1.readline()
175 f2.write(line)
176 linestripped = line.lstrip()
177 linestripped = linestripped.rstrip()
178 while not (linestripped.find('def check_workflow_compatible(')>-1):
179 line = f1.readline()
180 linestripped = line.lstrip()
181 linestripped = linestripped.rstrip()
182 f2.write(line)
183 if line.find('(')>-1:
184 while not line.find(')')>-1:
185 line = f1.readline()
186 f2.write(line)
187
188 line = f1.readline()
189 while line.find('#')>-1:
190 f2.write(line)
191 line = f1.readline()
192
193 indent=0
194 while (line[indent] == ' '):
195 indent = indent+1
196
197 space = ''
198 for i in range(0,indent):
199 space +=' '
200
201 f2.write(space+'#############\n')
202 f2.write(space+'#added by Chaitany Guttula, chaitu86@uga.edu - to disable webservice standalone tools in Workflows\n')
203 f2.write(space+'if self.id.find("WebService")>-1:\n')
204 f2.write(space+' return False\n')
205 f2.write(space+'#############\n')
206
207 f2.write(line)
208 line = f1.readline()
209 f2.write(line)
210
211 while line != '':
212 line = f1.readline()
213 f2.write(line)
214
215 f1.close()
216 f2.close()
217
218 f1 = open(galaxyhome+'/lib/galaxy/tools/__init__backup.py','r')
219 f2 = open(galaxyhome+'/lib/galaxy/tools/__init__.py','w')
220
221 line = f1.readline()
222 f2.write(line)
223
224 while line != '':
225 line = f1.readline()
226 f2.write(line)
227
228 f1.close()
229 f2.close()
230 print 'Workflow disabling Code added to __init__.py'
231
232
233
234 # Adding Code to __init__.py in lib/galaxy/tools folder in Galaxy for invoking the refresh functionality
235 f1 = open(galaxyhome+'/lib/galaxy/tools/__init__.py','r')
236 f1.seek(0,0)
237
238 exist = False
239 line = f1.readline()
240 linestripped = line.lstrip()
241 linestripped = linestripped.rstrip()
242 while line != '':
243 # if(linsetripped.find('\'\'\'')>-1):
244 # line = f1.readline()
245 # while(not line.find('\'\'\'')>-1):
246 # line = f1.readline()
247 if(linestripped == 'if self.id == \'WebService_REFRESH_ID\':'):
248 exist = True
249 break
250 line = f1.readline()
251 linestripped = line.lstrip()
252 linestripped = linestripped.rstrip()
253
254 if exist :
255 print 'Refresh code is already present in __init__.py'
256 else:
257 f2 = open(galaxyhome+'/lib/galaxy/tools/__init__backup.py','w')
258 f2.seek(0,0)
259 f1.seek(0,0)
260 line = f1.readline()
261 f2.write(line)
262 linestripped = line.lstrip()
263 linestripped = linestripped.rstrip()
264 while not (linestripped.find('def execute(')>-1):
265 line = f1.readline()
266 linestripped = line.lstrip()
267 linestripped = linestripped.rstrip()
268 f2.write(line)
269 if line.find('(')>-1:
270 while not line.find(')')>-1:
271 line = f1.readline()
272 f2.write(line)
273
274 line = f1.readline()
275 while line.find('#')>-1:
276 f2.write(line)
277 line = f1.readline()
278
279 indent=0
280 while (line[indent] == ' '):
281 indent = indent+1
282
283 space = ''
284 for i in range(0,indent):
285 space +=' '
286
287 f2.write(space+'#############\n')
288 f2.write(space+'#add code to verify if user has administrative privileges\n')
289 f2.write(space+'#added by sumedha ganjoo, sganjoo@uga.edu - to refresh toolbox\n')
290 f2.write(space+'if self.id == \'WebService_REFRESH_ID\':\n')
291 f2.write(space+' self.app.refreshToolBox()\n')
292 f2.write(space+'#############\n')
293
294 f2.write(line)
295 line = f1.readline()
296 f2.write(line)
297
298 while line != '':
299 line = f1.readline()
300 f2.write(line)
301
302 f1.close()
303 f2.close()
304
305 f1 = open(galaxyhome+'/lib/galaxy/tools/__init__backup.py','r')
306 f2 = open(galaxyhome+'/lib/galaxy/tools/__init__.py','w')
307
308 line = f1.readline()
309 f2.write(line)
310
311 while line != '':
312 line = f1.readline()
313 f2.write(line)
314
315 f1.close()
316 f2.close()
317 print 'Refresh Code added to __init__.py'
318
319
320 # Adding Code to app.py in lib/galaxy folder in Galaxy for invoking the refresh functionality
321 f1 = open(galaxyhome+'/lib/galaxy/app.py','r')
322
323 f1.seek(0,0)
324
325 exist = False
326 line = f1.readline()
327 linestripped = line.lstrip()
328 linestripped = linestripped.rstrip()
329 while line != '':
330 if(linestripped == 'def refreshToolBox( self ):'):
331 exist = True
332 break
333 line = f1.readline()
334 linestripped = line.lstrip()
335 linestripped = linestripped.rstrip()
336
337 if exist:
338 print 'Refresh code is already present in app.py'
339 else:
340 f2 = open(galaxyhome+'/lib/galaxy/app_backup.py','w')
341 f2.seek(0,0)
342 f1.seek(0,0)
343 line = f1.readline()
344 f2.write(line)
345 linestripped = line.lstrip()
346 linestripped = linestripped.rstrip()
347 while not (line.find('class UniverseApplication')>-1):
348 line = f1.readline()
349 linestripped = line.lstrip()
350 linestripped = linestripped.rstrip()
351 f2.write(line)
352 if line.find('(')>-1:
353 while not line.find(')')>-1:
354 line = f1.readline()
355 f2.write(line)
356
357 line = f1.readline()
358
359 while line.find('#')>-1:
360 f2.write(line)
361 line = f1.readline()
362
363
364 indent=0
365 while (line[indent] == ' '):
366 indent = indent+1
367
368 space = ''
369 for i in range(0,indent):
370 space +=' '
371
372 f2.write(space+'#############\n')
373 f2.write(space+'#added by sumedha ganjoo, sganjoo@uga.edu\n')
374 f2.write(space+'def refreshToolBox( self ):\n')
375 f2.write(space+' self.toolbox = tools.ToolBox( self.config.tool_config, self.config.tool_path, self )\n')
376 f2.write(space+'#############\n\n')
377
378 f2.write(line)
379 line = f1.readline()
380 f2.write(line)
381
382 while line != '':
383 line = f1.readline()
384 f2.write(line)
385
386 f1.close()
387 f2.close()
388
389 f1 = open(galaxyhome+'/lib/galaxy/app_backup.py','r')
390 f2 = open(galaxyhome+'/lib/galaxy/app.py','w')
391
392 line = f1.readline()
393 f2.write(line)
394
395 while line != '':
396 line = f1.readline()
397 f2.write(line)
398
399 f1.close()
400 f2.close()
401 print 'Refresh code is added to app.py'
402
403
404
405 print '****Installation of tool is complete. Now reload galaxy to use the installed tool****'
406