diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WebServiceExtensionsV1.1/install.py	Tue Jul 05 19:34:18 2011 -0400
@@ -0,0 +1,406 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+__author__ = "Chaitanya Guttula"
+
+
+import os
+import sys
+from shutil import copytree, ignore_patterns
+
+galaxyhome=os.environ.get('GALAXY_HOME')
+#print galaxyhome
+
+#os.mkdir(galaxyhome+'/GAL')
+dirfilelist=os.listdir(galaxyhome+'/tools')
+exist = False
+for dirfile in dirfilelist:
+    if dirfile == 'WebServiceToolWorkflow_REST_SOAP':
+        exist = True
+        break
+
+if exist:
+    print 'WebServiceToolWorkflow_REST_SOAP is already present in '+galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP'
+else:
+    copytree('WebServiceToolWorkflow_REST_SOAP',galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP', ignore=ignore_patterns('*.pyc', 'tmp*'))
+    print 'Copied the folder \'WebServiceToolWorkflow_REST_SOAP\' to '+galaxyhome+'/tools'
+
+f1=open(galaxyhome+'/tool_conf.xml','r')
+f1.seek(0,0)
+f2=open(galaxyhome+'/tool_conf_backup.xml','w')
+f2.seek(0,0)
+
+#copy the first line <toolbox> into another file f2
+line = f1.readline()
+#f2.write(line)
+
+lineStripped=line.lstrip()
+lineStripped=lineStripped.rstrip()
+
+#Flags for verifying that the tool is not already installed
+tool_present = False
+webservice_present = False
+workflow_present = False
+
+# Check of the tools are already installed or not
+# and sets the flags to true if they are already installed 
+while not lineStripped == '</toolbox>':
+    line = f1.readline()
+    lineStripped = line.lstrip()
+    lineStripped=lineStripped.rstrip()          
+    if(lineStripped.find('<!--')>-1):
+        line = f1.readline()
+        while(not line.find('-->')>-1):
+            line = f1.readline()
+    
+    if lineStripped == '<section name="Add Web service tool(s)" id="RegisterWebService">':
+        tool_present = True
+    elif lineStripped == '<section name="Select Web Service Tool" id="WebServices">':
+        webservice_present = True
+    elif lineStripped == '<section name="Select Web Service Workflow Tool" id="WebServiceWorkflow">':
+        workflow_present = True
+
+
+f1.seek(0,0)
+line = f1.readline()
+f2.write(line)
+
+lineStripped=line.lstrip()
+lineStripped=lineStripped.rstrip()
+
+# copy to the file f2 till <toolbox>
+while not lineStripped == '<toolbox>':
+    line = f1.readline()
+    f2.write(line)
+    lineStripped = line.lstrip()
+    lineStripped = lineStripped.rstrip()
+
+# Check if the tool is not installed and then add it to the file f2
+if not tool_present:
+    f2.write('  <section name="Add Web service tool(s)" id="RegisterWebService">\n')
+    f2.write('    <tool file="WebServiceToolWorkflow_REST_SOAP/WebServiceTool_input_url_REST_SOAP.xml"/>\n')
+    f2.write('    <tool file="WebServiceToolWorkflow_REST_SOAP/WebServiceTool_input_method_REST_SOAP.xml"/>\n')
+    f2.write('    <tool file="WebServiceToolWorkflow_REST_SOAP/refreshTool.xml"/>\n')
+    f2.write('  </section>\n')
+    print 'The "Add Web Service Tool" added successfully'
+else:
+    print 'The "Add Web service tool" tool is already present'
+
+
+# Check if the section "Web Service Tools" is not installed and then add it to the file f2
+if not webservice_present:
+    f2.write('  <section name="Select Web Service Tool" id="WebServices">\n')
+    f2.write('\n')
+    f2.write('  </section>\n')
+    print 'The "Web Service Tools" added successfully'
+else:
+    print 'The section "Web Service Tools" is already present'
+
+
+# Check if the Section "Web Service Workflow Tools" is not installed and then add it to the file f2
+if not workflow_present:
+    f2.write('  <section name="Select Web Service Workflow Tool" id="WebServiceWorkflow">\n')
+    f2.write('\n')
+    f2.write('  </section>\n')
+    print 'The section "Web Service Workflow Tools" is added successfully'
+else:
+    print 'The section "Web Service Workflow Tools" is already present'
+
+
+#copy rest of tool_conf.xml file to f2
+while not lineStripped == '</toolbox>':
+    line = f1.readline()
+    f2.write(line)
+    lineStripped = line.lstrip()
+    lineStripped=lineStripped.rstrip()          
+#else:
+#    print line
+
+##close f1 and f2
+f1.close()
+f2.close()
+
+##interchange modes of f1 and f2
+f1=open(galaxyhome+'/tool_conf.xml','w')
+f1.seek(0,0)
+f2=open(galaxyhome+'/tool_conf_backup.xml','r')
+f2.seek(0,0)
+
+line = f2.readline()
+f1.write(line)
+
+lineStripped=line.lstrip()
+lineStripped = lineStripped.rstrip()
+
+##write entire f2 into f1 (reverse roles)
+while not lineStripped == '</toolbox>':
+    line = f2.readline()
+    f1.write(line)
+    lineStripped = line.lstrip()
+    lineStripped = lineStripped.rstrip()        
+#else:
+#    print line
+
+f1.close()
+f2.close()
+
+
+# Adding Code to __init__.py in lib/galaxy/tools folder in Galaxy for disabling Web service stand alone tools in Workflows
+f1 = open(galaxyhome+'/lib/galaxy/tools/__init__.py','r')
+f1.seek(0,0)
+
+exist = False
+line = f1.readline()
+linestripped = line.lstrip()
+linestripped = linestripped.rstrip()
+while line != '':
+#    if(linsetripped.find('\'\'\'')>-1):
+#        line = f1.readline()
+#        while(not line.find('\'\'\'')>-1):
+#            line = f1.readline()
+    if(linestripped == 'if self.id.find("WebService")>-1:'):
+        exist = True
+        break
+    line = f1.readline()
+    linestripped = line.lstrip()
+    linestripped = linestripped.rstrip()
+
+if exist :
+    print 'Workflow code is already present in __init__.py'
+else:
+    f2 = open(galaxyhome+'/lib/galaxy/tools/__init__backup.py','w')
+    f2.seek(0,0)
+    f1.seek(0,0)
+    line = f1.readline()
+    f2.write(line)
+    linestripped = line.lstrip()
+    linestripped = linestripped.rstrip()
+    while not (linestripped.find('def check_workflow_compatible(')>-1): 
+        line = f1.readline()
+        linestripped = line.lstrip()
+        linestripped = linestripped.rstrip()
+        f2.write(line)
+    if line.find('(')>-1:
+        while not line.find(')')>-1:
+            line = f1.readline()
+            f2.write(line)
+        
+    line = f1.readline()
+    while line.find('#')>-1:
+        f2.write(line)
+        line = f1.readline()
+        
+    indent=0
+    while (line[indent] == ' '):
+        indent = indent+1
+    
+    space = ''
+    for i in range(0,indent):    
+        space +=' '
+        
+    f2.write(space+'#############\n')    
+    f2.write(space+'#added by Chaitany Guttula, chaitu86@uga.edu - to disable webservice standalone tools in Workflows\n')
+    f2.write(space+'if self.id.find("WebService")>-1:\n')
+    f2.write(space+'    return False\n')
+    f2.write(space+'#############\n')
+
+    f2.write(line)
+    line = f1.readline()
+    f2.write(line)
+
+    while line != '':
+        line = f1.readline()
+        f2.write(line)
+    
+    f1.close()
+    f2.close()
+
+    f1 = open(galaxyhome+'/lib/galaxy/tools/__init__backup.py','r')
+    f2 = open(galaxyhome+'/lib/galaxy/tools/__init__.py','w')
+
+    line = f1.readline()
+    f2.write(line)
+
+    while line != '':
+        line = f1.readline()
+        f2.write(line)
+    
+    f1.close()
+    f2.close()
+    print 'Workflow disabling Code added to __init__.py'
+    
+
+
+# Adding Code to __init__.py in lib/galaxy/tools folder in Galaxy for invoking the refresh functionality
+f1 = open(galaxyhome+'/lib/galaxy/tools/__init__.py','r')
+f1.seek(0,0)
+
+exist = False
+line = f1.readline()
+linestripped = line.lstrip()
+linestripped = linestripped.rstrip()
+while line != '':
+#    if(linsetripped.find('\'\'\'')>-1):
+#        line = f1.readline()
+#        while(not line.find('\'\'\'')>-1):
+#            line = f1.readline()
+    if(linestripped == 'if self.id == \'WebService_REFRESH_ID\':'):
+        exist = True
+        break
+    line = f1.readline()
+    linestripped = line.lstrip()
+    linestripped = linestripped.rstrip()
+
+if exist :
+    print 'Refresh code is already present in __init__.py'
+else:
+    f2 = open(galaxyhome+'/lib/galaxy/tools/__init__backup.py','w')
+    f2.seek(0,0)
+    f1.seek(0,0)
+    line = f1.readline()
+    f2.write(line)
+    linestripped = line.lstrip()
+    linestripped = linestripped.rstrip()
+    while not (linestripped.find('def execute(')>-1): 
+        line = f1.readline()
+        linestripped = line.lstrip()
+        linestripped = linestripped.rstrip()
+        f2.write(line)
+    if line.find('(')>-1:
+        while not line.find(')')>-1:
+            line = f1.readline()
+            f2.write(line)
+        
+    line = f1.readline()
+    while line.find('#')>-1:
+        f2.write(line)
+        line = f1.readline()
+        
+    indent=0
+    while (line[indent] == ' '):
+        indent = indent+1
+    
+    space = ''
+    for i in range(0,indent):    
+        space +=' '
+        
+    f2.write(space+'#############\n')    
+    f2.write(space+'#add code to verify if user has administrative privileges\n')
+    f2.write(space+'#added by sumedha ganjoo, sganjoo@uga.edu - to refresh toolbox\n')
+    f2.write(space+'if self.id == \'WebService_REFRESH_ID\':\n')
+    f2.write(space+'    self.app.refreshToolBox()\n')
+    f2.write(space+'#############\n')
+
+    f2.write(line)
+    line = f1.readline()
+    f2.write(line)
+
+    while line != '':
+        line = f1.readline()
+        f2.write(line)
+    
+    f1.close()
+    f2.close()
+
+    f1 = open(galaxyhome+'/lib/galaxy/tools/__init__backup.py','r')
+    f2 = open(galaxyhome+'/lib/galaxy/tools/__init__.py','w')
+
+    line = f1.readline()
+    f2.write(line)
+
+    while line != '':
+        line = f1.readline()
+        f2.write(line)
+    
+    f1.close()
+    f2.close()
+    print 'Refresh Code added to __init__.py'
+    
+    
+# Adding Code to app.py in lib/galaxy folder in Galaxy for invoking the refresh functionality
+f1 = open(galaxyhome+'/lib/galaxy/app.py','r')
+
+f1.seek(0,0)
+
+exist = False
+line = f1.readline()
+linestripped = line.lstrip()
+linestripped = linestripped.rstrip()
+while line != '':
+    if(linestripped == 'def refreshToolBox( self ):'):
+        exist = True
+        break
+    line = f1.readline()
+    linestripped = line.lstrip()
+    linestripped = linestripped.rstrip()
+
+if exist:
+    print 'Refresh code is already present in app.py'
+else:
+    f2 = open(galaxyhome+'/lib/galaxy/app_backup.py','w')
+    f2.seek(0,0)
+    f1.seek(0,0)
+    line = f1.readline()
+    f2.write(line)
+    linestripped = line.lstrip()
+    linestripped = linestripped.rstrip()
+    while not (line.find('class UniverseApplication')>-1): 
+        line = f1.readline()
+        linestripped = line.lstrip()
+        linestripped = linestripped.rstrip()
+        f2.write(line)
+    if line.find('(')>-1:
+        while not line.find(')')>-1:
+            line = f1.readline()
+            f2.write(line)
+        
+    line = f1.readline()
+    
+    while line.find('#')>-1:
+        f2.write(line)
+        line = f1.readline()
+    
+    
+    indent=0
+    while (line[indent] == ' '):
+        indent = indent+1
+
+    space = ''
+    for i in range(0,indent):    
+        space +=' '
+    
+    f2.write(space+'#############\n')    
+    f2.write(space+'#added by sumedha ganjoo, sganjoo@uga.edu\n')
+    f2.write(space+'def refreshToolBox( self ):\n')
+    f2.write(space+'    self.toolbox = tools.ToolBox( self.config.tool_config, self.config.tool_path, self )\n')
+    f2.write(space+'#############\n\n')
+
+    f2.write(line)
+    line = f1.readline()
+    f2.write(line)
+
+    while line != '':
+        line = f1.readline()
+        f2.write(line)
+
+    f1.close()
+    f2.close()
+
+    f1 = open(galaxyhome+'/lib/galaxy/app_backup.py','r')
+    f2 = open(galaxyhome+'/lib/galaxy/app.py','w')
+    
+    line = f1.readline()
+    f2.write(line)
+
+    while line != '':
+        line = f1.readline()
+        f2.write(line)
+
+    f1.close()
+    f2.close()
+    print 'Refresh code is added to app.py'
+    
+    
+    
+print '****Installation of tool is complete. Now reload galaxy to use the installed tool****'    
+