diff rgToolFactory.py @ 19:a87a262220a4

Adding proof of concept for optional output formats. Updated readme again
author ross lazarus ross.lazarus@gmail.com
date Tue, 05 Jun 2012 21:54:58 +1000
parents 8594478e8d2c
children 3f58115c6c5b
line wrap: on
line diff
--- a/rgToolFactory.py	Mon Jun 04 21:32:24 2012 +1000
+++ b/rgToolFactory.py	Tue Jun 05 21:54:58 2012 +1000
@@ -1,27 +1,54 @@
 # rgToolFactory.py
-# derived from 
-# rgBaseScriptWrapper.py
-# but designed to run arbitrary user supplied code 
-# extremely dangerous!!
-# trusted users only - private site only
-# a list in the xml is searched for users permitted to run this tool.
-# DO NOT install on a public or important site - local instance only
-# generated tools are fine as they just run normally and their user cannot do anything unusually insecure
+# https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
+
+# this is a tool factory for simple scripts in python, R or whatever ails ye.
+# you paste and run your script
+# Only works for simple scripts that read one input from the history.
+# Optionally can write one new history dataset,
+# and optionally collect any number of outputs into links on an autogenerated HTML page.
+
+# DO NOT install on a public or important site - please.
+
+# installed generated tools are fine if the script is safe.
+# They just run normally and their user cannot do anything unusually insecure
+# but please, practice safe toolshed.
+# Read the fucking code before you install any tool 
+# especially this one
+
+# After you get the script working on some test data, you can
+# optionally generate a toolshed compatible gzip file
+# containing your script safely wrapped as an ordinary Galaxy script in your local toolshed for
+# safe and largely automated installation in a production Galaxy.
+
+# If you opt for an HTML output, you get all the script outputs arranged
+# as a single Html history item - all output files are linked, thumbnails for all the pdfs.
+# Ugly but really inexpensive.
+# 
+# Patches appreciated please. 
 #
-# copyright ross lazarus (ross.lazarus@gmail.com) May 2012
+#
+# long route to June 2012 product
+# Behold the awesome power of Galaxy and the toolshed with the tool factory binds to bind them
+# derived from an integrated script model  
+# called rgBaseScriptWrapper.py
+# Note to the unwary:
+#   This tool allows arbitrary scripting on your Galaxy as the Galaxy user
+#   There is nothing stopping a malicious user doing whatever they choose
+#   Extremely dangerous!!
+#   Totally insecure. So, trusted users only
+#
+# preferred model is a developer using their throw away workstation instance - ie a private site.
+# no real risk.
+# a list in the xml source file is searched for users permitted to run this tool.
+# PUT some IDs in the list in the XML before you restart Galaxy to load this new tool please
+# otherwise, the tool won't run for anybody.
+#
+
+# 
+# copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
 # 
 # all rights reserved
-# Licensed under the LGPL for your pleasure
-# Derived from rgDGE.py in May 2012
-# generalized to run required interpreter
-# to make your own tools based on a given script and interpreter such as perl or python
-# clone this and the corresponding xml wrapper
-# replace the parameters/inputs/outputs and the configfile contents with your script
-# Use the $foo syntax to place your parameter values inside the script to assign them - at run time, the script will be used as a template
-# and returned as part of the output to the user - with the right values for all the parameters.
-# Note that this assumes you want all the outputs arranged as a single Html file output 
-# after this generic script runner runs your script with the specified interpreter,
-# it will collect all output files into the specified output_html, making thumbnails for all the pdfs it finds and making links for all the other files.
+# Licensed under the LGPL if you want to improve it, feel free https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
 
 import sys 
 import shutil 
@@ -52,7 +79,7 @@
 
     def __init__(self,opts=None):
         """
-        run the script
+        cleanup inputs, setup some outputs
         
         """
         if opts.output_dir: # simplify for the tool tarball
@@ -93,8 +120,7 @@
     def makeXML(self):
         """
         Create a Galaxy xml tool wrapper for the new script as a string to write out
-        fixme - use templating or something less fugly than this.
-        Here's an example of what we produce
+        fixme - use templating or something less fugly than this example of what we produce
 
         <tool id="reverse" name="reverse" version="0.01">
             <description>a tabular file</description>
@@ -293,7 +319,7 @@
         <body> 
         <div class="document"> 
         """ 
-        galhtmlattr = """<hr/><b><a href="http://rgenetics.org">Galaxy Tool Factory Script Wrapper</a> tool output %s run at %s</b><br/>""" 
+        galhtmlattr = """<hr/><b><a href="https://bitbucket.org/fubar/galaxytoolfactory/overview">Galaxy Tool Factory Script Wrapper</a> tool output %s run at %s</b><br/>""" 
         galhtmlpostfix = """</div></body></html>\n"""
 
         flist = os.listdir(self.opts.output_dir)
@@ -379,7 +405,7 @@
     a('--tool_desc',default=None)
     a('--new_tool',default=None)
     opts, args = op.parse_args()
-    assert not opts.bad_user,'%s is NOT authorized to use this tool. Please ask your friendly admin' % opts.bad_user
+    assert not opts.bad_user,'%s is NOT authorized to use this tool. Please ask your friendly admin to add their ID to %s.xml' % (opts.bad_user,os.path.splitext(self.myname)[0])
     assert opts.tool_name,'## Tool Factory expects a tool name - eg --tool_name=DESeq'
     assert opts.interpreter,'## Tool Factory wrapper expects an interpreter - eg --interpreter=Rscript'
     assert os.path.isfile(opts.script_path),'## Tool Factory wrapper expects a script path - eg --script_path=foo.R'