diff rgToolFactory.py @ 11:704ccaade924 draft

Uploaded
author fubar
date Thu, 20 Mar 2014 05:50:38 -0400
parents 1fcf3fda325f
children a898ba82496e
line wrap: on
line diff
--- a/rgToolFactory.py	Thu Mar 20 05:03:17 2014 -0400
+++ b/rgToolFactory.py	Thu Mar 20 05:50:38 2014 -0400
@@ -8,6 +8,8 @@
 # suggestions for improvement and bug fixes welcome at https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
 #
 # march 2014
+# added dependencies to a tool_dependencies.xml if html page generated so generated tool is properly portable
+#
 # added ghostscript and graphicsmagick as dependencies 
 # fixed a wierd problem where gs was trying to use the new_files_path from universe (database/tmp) as ./database/tmp
 # errors ensued
@@ -88,6 +90,21 @@
 debug = False
 toolFactoryURL = 'https://bitbucket.org/fubar/galaxytoolfactory'
 
+# if we do html we need these dependencies
+toolhtmldep = """<?xml version="1.0"?>
+<tool_dependency>
+    <package name="ghostscript" version="9.10">
+        <repository name="package_ghostscript_9_10" owner="devteam" prior_installation_required="True" toolshed="http://toolshed.g2.bx.psu.edu/" />
+    </package>
+    <package name="graphicsmagick" version="1.3.18">
+        <repository name="package_graphicsmagick_1_3" owner="iuc" prior_installation_required="True" toolshed="http://toolshed.g2.bx.psu.edu/" />
+    </package>
+        <readme>
+           %s
+       </readme>
+</tool_dependency>
+"""
+
 def timenow():
     """return current time as a string
     """
@@ -130,7 +147,7 @@
         self.toolname = re.sub('[^a-zA-Z0-9_]+', '', opts.tool_name) # a sanitizer now does this but..
         self.toolid = self.toolname
         self.myname = sys.argv[0] # get our name because we write ourselves out as a tool later
-        self.pyfile = self.myname # crude but efficient - the cruft won't hurt much
+        self.pyfile = self.myname # crude but efficient - the cruft won't hurt muchself.tooldepfile)
         self.xmlfile = '%s.xml' % self.toolname
         s = open(self.opts.script_path,'r').readlines()
         s = [x.rstrip() for x in s] # remove pesky dos line endings if needed
@@ -233,7 +250,7 @@
             %(help)s
             </help>
             </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto
-               
+
         newCommand="""<command interpreter="python">
             %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s" 
             --tool_name "%(toolname)s" %(command_inputs)s %(command_outputs)s 
@@ -323,9 +340,19 @@
         if retval:
             print >> sys.stderr,'## Run failed. Cannot build yet. Please fix and retry'
             sys.exit(1)
-        self.makeXML()
         tdir = self.toolname
         os.mkdir(tdir)
+        self.makeXML()
+        if self.opts.make_HTML:
+            if self.opts.help_text:
+                hlp = open(self.opts.help_text,'r').read()
+            else:
+                hlp = 'Please ask the tool author for help as none was supplied at tool generation\n'
+            tooldeps = toolhtmldep % hlp
+            depf = open('tool_dependencies.xml','w')
+            depf.write(hlp)
+            depf.write('\n')
+            depf.close()
         if self.opts.input_tab <> 'None': # no reproducible test otherwise? TODO: maybe..
             testdir = os.path.join(tdir,'test-data')
             os.mkdir(testdir) # make tests directory