annotate rgToolFactory.py @ 53:b608991544f5 draft

Uploaded
author fubar
date Sun, 09 Feb 2014 19:04:12 -0500
parents c0fa3dde02d9
children d4fc5eb21a2e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
1 # rgToolFactory.py
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
2 # see https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
3 #
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
4 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
5 #
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
6 # all rights reserved
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
7 # Licensed under the LGPL
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
8 # suggestions for improvement and bug fixes welcome at https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
9 #
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
10 # august 2013
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
11 # found a problem with GS if $TMP or $TEMP missing - now inject /tmp and warn
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
12 #
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
13 # july 2013
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
14 # added ability to combine images and individual log files into html output
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
15 # just make sure there's a log file foo.log and it will be output
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
16 # together with all images named like "foo_*.pdf
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
17 # otherwise old format for html
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
18 #
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
19 # January 2013
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
20 # problem pointed out by Carlos Borroto
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
21 # added escaping for <>$ - thought I did that ages ago...
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
22 #
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
23 # August 11 2012
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
24 # changed to use shell=False and cl as a sequence
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
25
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
26 # This is a Galaxy tool factory for simple scripts in python, R or whatever ails ye.
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
27 # It also serves as the wrapper for the new tool.
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
28 #
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
29 # you paste and run your script
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
30 # Only works for simple scripts that read one input from the history.
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
31 # Optionally can write one new history dataset,
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
32 # and optionally collect any number of outputs into links on an autogenerated HTML page.
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
33
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
34 # DO NOT install on a public or important site - please.
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
35
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
36 # installed generated tools are fine if the script is safe.
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
37 # They just run normally and their user cannot do anything unusually insecure
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
38 # but please, practice safe toolshed.
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
39 # Read the fucking code before you install any tool
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
40 # especially this one
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
41
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
42 # After you get the script working on some test data, you can
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
43 # optionally generate a toolshed compatible gzip file
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
44 # containing your script safely wrapped as an ordinary Galaxy script in your local toolshed for
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
45 # safe and largely automated installation in a production Galaxy.
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
46
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
47 # If you opt for an HTML output, you get all the script outputs arranged
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
48 # as a single Html history item - all output files are linked, thumbnails for all the pdfs.
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
49 # Ugly but really inexpensive.
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
50 #
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
51 # Patches appreciated please.
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
52 #
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
53 #
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
54 # long route to June 2012 product
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
55 # Behold the awesome power of Galaxy and the toolshed with the tool factory to bind them
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
56 # derived from an integrated script model
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
57 # called rgBaseScriptWrapper.py
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
58 # Note to the unwary:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
59 # This tool allows arbitrary scripting on your Galaxy as the Galaxy user
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
60 # There is nothing stopping a malicious user doing whatever they choose
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
61 # Extremely dangerous!!
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
62 # Totally insecure. So, trusted users only
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
63 #
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
64 # preferred model is a developer using their throw away workstation instance - ie a private site.
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
65 # no real risk. The universe_wsgi.ini admin_users string is checked - only admin users are permitted to run this tool.
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
66 #
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
67
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
68 import sys
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
69 import shutil
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
70 import subprocess
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
71 import os
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
72 import time
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
73 import tempfile
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
74 import optparse
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
75 import tarfile
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
76 import re
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
77 import shutil
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
78 import math
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
79
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
80 progname = os.path.split(sys.argv[0])[1]
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
81 myversion = 'V000.2 June 2012'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
82 verbose = False
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
83 debug = False
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
84 toolFactoryURL = 'https://bitbucket.org/fubar/galaxytoolfactory'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
85
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
86 def timenow():
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
87 """return current time as a string
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
88 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
89 return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time()))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
90
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
91 html_escape_table = {
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
92 "&": "&amp;",
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
93 ">": "&gt;",
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
94 "<": "&lt;",
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
95 "$": "\$"
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
96 }
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
97
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
98 def html_escape(text):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
99 """Produce entities within text."""
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
100 return "".join(html_escape_table.get(c,c) for c in text)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
101
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
102 def cmd_exists(cmd):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
103 return subprocess.call("type " + cmd, shell=True,
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
104 stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
105
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
106
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
107 class ScriptRunner:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
108 """class is a wrapper for an arbitrary script
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
109 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
110
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
111 def __init__(self,opts=None,treatbashSpecial=True):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
112 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
113 cleanup inputs, setup some outputs
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
114
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
115 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
116 self.useGM = cmd_exists('gm')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
117 self.useIM = cmd_exists('convert')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
118 self.useGS = cmd_exists('gs')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
119 self.temp_warned = False # we want only one warning if $TMP not set
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
120 self.treatbashSpecial = treatbashSpecial
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
121 if opts.output_dir: # simplify for the tool tarball
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
122 os.chdir(opts.output_dir)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
123 self.thumbformat = 'png'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
124 self.opts = opts
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
125 self.toolname = re.sub('[^a-zA-Z0-9_]+', '', opts.tool_name) # a sanitizer now does this but..
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
126 self.toolid = self.toolname
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
127 self.myname = sys.argv[0] # get our name because we write ourselves out as a tool later
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
128 self.pyfile = self.myname # crude but efficient - the cruft won't hurt much
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
129 self.xmlfile = '%s.xml' % self.toolname
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
130 s = open(self.opts.script_path,'r').readlines()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
131 s = [x.rstrip() for x in s] # remove pesky dos line endings if needed
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
132 self.script = '\n'.join(s)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
133 fhandle,self.sfile = tempfile.mkstemp(prefix=self.toolname,suffix=".%s" % (opts.interpreter))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
134 tscript = open(self.sfile,'w') # use self.sfile as script source for Popen
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
135 tscript.write(self.script)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
136 tscript.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
137 self.indentedScript = '\n'.join([' %s' % x for x in s]) # for restructured text in help
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
138 self.escapedScript = '\n'.join([html_escape(x) for x in s])
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
139 self.elog = os.path.join(self.opts.output_dir,"%s_error.log" % self.toolname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
140 if opts.output_dir: # may not want these complexities
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
141 self.tlog = os.path.join(self.opts.output_dir,"%s_runner.log" % self.toolname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
142 art = '%s.%s' % (self.toolname,opts.interpreter)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
143 artpath = os.path.join(self.opts.output_dir,art) # need full path
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
144 artifact = open(artpath,'w') # use self.sfile as script source for Popen
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
145 artifact.write(self.script)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
146 artifact.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
147 self.cl = []
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
148 self.html = []
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
149 a = self.cl.append
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
150 a(opts.interpreter)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
151 if self.treatbashSpecial and opts.interpreter in ['bash','sh']:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
152 a(self.sfile)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
153 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
154 a('-') # stdin
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
155 a(opts.input_tab)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
156 a(opts.output_tab)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
157 self.outFormats = 'tabular' # TODO make this an option at tool generation time
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
158 self.inputFormats = 'tabular' # TODO make this an option at tool generation time
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
159 self.test1Input = '%s_test1_input.xls' % self.toolname
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
160 self.test1Output = '%s_test1_output.xls' % self.toolname
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
161 self.test1HTML = '%s_test1_output.html' % self.toolname
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
162
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
163 def makeXML(self):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
164 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
165 Create a Galaxy xml tool wrapper for the new script as a string to write out
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
166 fixme - use templating or something less fugly than this example of what we produce
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
167
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
168 <tool id="reverse" name="reverse" version="0.01">
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
169 <description>a tabular file</description>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
170 <command interpreter="python">
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
171 reverse.py --script_path "$runMe" --interpreter "python"
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
172 --tool_name "reverse" --input_tab "$input1" --output_tab "$tab_file"
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
173 </command>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
174 <inputs>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
175 <param name="input1" type="data" format="tabular" label="Select a suitable input file from your history"/><param name="job_name" type="text" label="Supply a name for the outputs to remind you what they contain" value="reverse"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
176
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
177 </inputs>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
178 <outputs>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
179 <data format="tabular" name="tab_file" label="${job_name}"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
180
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
181 </outputs>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
182 <help>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
183
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
184 **What it Does**
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
185
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
186 Reverse the columns in a tabular file
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
187
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
188 </help>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
189 <configfiles>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
190 <configfile name="runMe">
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
191
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
192 # reverse order of columns in a tabular file
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
193 import sys
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
194 inp = sys.argv[1]
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
195 outp = sys.argv[2]
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
196 i = open(inp,'r')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
197 o = open(outp,'w')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
198 for row in i:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
199 rs = row.rstrip().split('\t')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
200 rs.reverse()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
201 o.write('\t'.join(rs))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
202 o.write('\n')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
203 i.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
204 o.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
205
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
206
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
207 </configfile>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
208 </configfiles>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
209 </tool>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
210
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
211 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
212 newXML="""<tool id="%(toolid)s" name="%(toolname)s" version="%(tool_version)s">
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
213 %(tooldesc)s
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
214 %(command)s
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
215 <inputs>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
216 %(inputs)s
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
217 </inputs>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
218 <outputs>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
219 %(outputs)s
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
220 </outputs>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
221 <configfiles>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
222 <configfile name="runMe">
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
223 %(script)s
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
224 </configfile>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
225 </configfiles>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
226 %(tooltests)s
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
227 <help>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
228 %(help)s
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
229 </help>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
230 </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
231
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
232 newCommand="""<command interpreter="python">
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
233 %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s"
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
234 --tool_name "%(toolname)s" %(command_inputs)s %(command_outputs)s
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
235 </command>""" # may NOT be an input or htmlout
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
236 tooltestsTabOnly = """<tests><test>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
237 <param name="input1" value="%(test1Input)s" ftype="tabular"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
238 <param name="job_name" value="test1"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
239 <param name="runMe" value="$runMe"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
240 <output name="tab_file" file="%(test1Output)s" ftype="tabular"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
241 </test></tests>"""
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
242 tooltestsHTMLOnly = """<tests><test>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
243 <param name="input1" value="%(test1Input)s" ftype="tabular"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
244 <param name="job_name" value="test1"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
245 <param name="runMe" value="$runMe"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
246 <output name="html_file" file="%(test1HTML)s" ftype="html" lines_diff="5"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
247 </test></tests>"""
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
248 tooltestsBoth = """<tests><test>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
249 <param name="input1" value="%(test1Input)s" ftype="tabular"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
250 <param name="job_name" value="test1"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
251 <param name="runMe" value="$runMe"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
252 <output name="tab_file" file="%(test1Output)s" ftype="tabular" />
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
253 <output name="html_file" file="%(test1HTML)s" ftype="html" lines_diff="10"/>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
254 </test></tests>"""
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
255 xdict = {}
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
256 xdict['tool_version'] = self.opts.tool_version
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
257 xdict['test1Input'] = self.test1Input
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
258 xdict['test1HTML'] = self.test1HTML
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
259 xdict['test1Output'] = self.test1Output
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
260 if self.opts.make_HTML and self.opts.output_tab <> 'None':
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
261 xdict['tooltests'] = tooltestsBoth % xdict
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
262 elif self.opts.make_HTML:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
263 xdict['tooltests'] = tooltestsHTMLOnly % xdict
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
264 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
265 xdict['tooltests'] = tooltestsTabOnly % xdict
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
266 xdict['script'] = self.escapedScript
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
267 # configfile is least painful way to embed script to avoid external dependencies
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
268 # but requires escaping of <, > and $ to avoid Mako parsing
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
269 if self.opts.help_text:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
270 xdict['help'] = open(self.opts.help_text,'r').read()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
271 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
272 xdict['help'] = 'Please ask the tool author for help as none was supplied at tool generation'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
273 coda = ['**Script**','Pressing execute will run the following code over your input file and generate some outputs in your history::']
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
274 coda.append(self.indentedScript)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
275 coda.append('**Attribution** This Galaxy tool was created by %s at %s\nusing the Galaxy Tool Factory.' % (self.opts.user_email,timenow()))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
276 coda.append('See %s for details of that project' % (toolFactoryURL))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
277 coda.append('Please cite: Creating re-usable tools from scripts: The Galaxy Tool Factory. Ross Lazarus; Antony Kaspi; Mark Ziemann; The Galaxy Team. ')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
278 coda.append('Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
279 xdict['help'] = '%s\n%s' % (xdict['help'],'\n'.join(coda))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
280 if self.opts.tool_desc:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
281 xdict['tooldesc'] = '<description>%s</description>' % self.opts.tool_desc
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
282 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
283 xdict['tooldesc'] = ''
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
284 xdict['command_outputs'] = ''
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
285 xdict['outputs'] = ''
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
286 if self.opts.input_tab <> 'None':
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
287 xdict['command_inputs'] = '--input_tab "$input1" ' # the space may matter a lot if we append something
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
288 xdict['inputs'] = '<param name="input1" type="data" format="%s" label="Select a suitable input file from your history"/> \n' % self.inputFormats
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
289 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
290 xdict['command_inputs'] = '' # assume no input - eg a random data generator
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
291 xdict['inputs'] = ''
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
292 xdict['inputs'] += '<param name="job_name" type="text" label="Supply a name for the outputs to remind you what they contain" value="%s"/> \n' % self.toolname
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
293 xdict['toolname'] = self.toolname
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
294 xdict['toolid'] = self.toolid
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
295 xdict['interpreter'] = self.opts.interpreter
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
296 xdict['scriptname'] = self.sfile
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
297 if self.opts.make_HTML:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
298 xdict['command_outputs'] += ' --output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes" '
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
299 xdict['outputs'] += ' <data format="html" name="html_file" label="${job_name}.html"/>\n'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
300 if self.opts.output_tab <> 'None':
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
301 xdict['command_outputs'] += ' --output_tab "$tab_file"'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
302 xdict['outputs'] += ' <data format="%s" name="tab_file" label="${job_name}"/>\n' % self.outFormats
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
303 xdict['command'] = newCommand % xdict
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
304 xmls = newXML % xdict
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
305 xf = open(self.xmlfile,'w')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
306 xf.write(xmls)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
307 xf.write('\n')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
308 xf.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
309 # ready for the tarball
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
310
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
311
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
312 def makeTooltar(self):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
313 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
314 a tool is a gz tarball with eg
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
315 /toolname/tool.xml /toolname/tool.py /toolname/test-data/test1_in.foo ...
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
316 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
317 retval = self.run()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
318 if retval:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
319 print >> sys.stderr,'## Run failed. Cannot build yet. Please fix and retry'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
320 sys.exit(1)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
321 self.makeXML()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
322 tdir = self.toolname
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
323 os.mkdir(tdir)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
324 if self.opts.input_tab <> 'None': # no reproducible test otherwise? TODO: maybe..
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
325 testdir = os.path.join(tdir,'test-data')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
326 os.mkdir(testdir) # make tests directory
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
327 shutil.copyfile(self.opts.input_tab,os.path.join(testdir,self.test1Input))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
328 if self.opts.output_tab <> 'None':
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
329 shutil.copyfile(self.opts.output_tab,os.path.join(testdir,self.test1Output))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
330 if self.opts.make_HTML:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
331 shutil.copyfile(self.opts.output_html,os.path.join(testdir,self.test1HTML))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
332 if self.opts.output_dir:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
333 shutil.copyfile(self.tlog,os.path.join(testdir,'test1_out.log'))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
334 op = '%s.py' % self.toolname # new name
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
335 outpiname = os.path.join(tdir,op) # path for the tool tarball
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
336 pyin = os.path.basename(self.pyfile) # our name - we rewrite ourselves (TM)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
337 notes = ['# %s - a self annotated version of %s generated by running %s\n' % (op,pyin,pyin),]
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
338 notes.append('# to make a new Galaxy tool called %s\n' % self.toolname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
339 notes.append('# User %s at %s\n' % (self.opts.user_email,timenow()))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
340 pi = open(self.pyfile,'r').readlines() # our code becomes new tool wrapper (!) - first Galaxy worm
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
341 notes += pi
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
342 outpi = open(outpiname,'w')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
343 outpi.write(''.join(notes))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
344 outpi.write('\n')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
345 outpi.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
346 stname = os.path.join(tdir,self.sfile)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
347 if not os.path.exists(stname):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
348 shutil.copyfile(self.sfile, stname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
349 xtname = os.path.join(tdir,self.xmlfile)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
350 if not os.path.exists(xtname):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
351 shutil.copyfile(self.xmlfile,xtname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
352 tarpath = "%s.gz" % self.toolname
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
353 tar = tarfile.open(tarpath, "w:gz")
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
354 tar.add(tdir,arcname=self.toolname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
355 tar.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
356 shutil.copyfile(tarpath,self.opts.new_tool)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
357 shutil.rmtree(tdir)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
358 ## TODO: replace with optional direct upload to local toolshed?
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
359 return retval
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
360
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
361
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
362 def compressPDF(self,inpdf=None,thumbformat='png'):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
363 """need absolute path to pdf
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
364 note that GS gets confoozled if no $TMP or $TEMP
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
365 so we set it
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
366 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
367 assert os.path.isfile(inpdf), "## Input %s supplied to %s compressPDF not found" % (inpdf,self.myName)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
368 our_env = os.environ.copy()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
369 if not (our_env.get('TMP',None) or our_env.get('TEMP',None)):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
370 our_env['TMP'] = '/tmp'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
371 if not self.temp_warned:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
372 print >> sys.stdout,'## WARNING - no $TMP or $TEMP!!! Please fix - using /tmp temporarily'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
373 self.temp_warned = True
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
374 hlog = os.path.join(self.opts.output_dir,"compress_%s.txt" % os.path.basename(inpdf))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
375 sto = open(hlog,'w')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
376 outpdf = '%s_compressed' % inpdf
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
377 cl = ["gs", "-sDEVICE=pdfwrite", "-dNOPAUSE", "-dBATCH","-dPDFSETTINGS=/printer", "-sOutputFile=%s" % outpdf,inpdf]
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
378 x = subprocess.Popen(cl,stdout=sto,stderr=sto,cwd=self.opts.output_dir,env=our_env)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
379 retval1 = x.wait()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
380 sto.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
381 if retval1 == 0:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
382 os.unlink(inpdf)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
383 shutil.move(outpdf,inpdf)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
384 os.unlink(hlog)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
385 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
386 x = open(hlog,'r').readlines()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
387 print >> sys.stdout,x
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
388 hlog = os.path.join(self.opts.output_dir,"thumbnail_%s.txt" % os.path.basename(inpdf))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
389 sto = open(hlog,'w')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
390 outpng = '%s.%s' % (os.path.splitext(inpdf)[0],thumbformat)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
391 if self.useGM:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
392 cl2 = ['gm', 'convert', inpdf, outpng]
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
393 else: # assume imagemagick
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
394 cl2 = ['convert', inpdf, outpng]
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
395 x = subprocess.Popen(cl2,stdout=sto,stderr=sto,cwd=self.opts.output_dir,env=our_env)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
396 retval2 = x.wait()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
397 sto.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
398 if retval2 <> 0:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
399 x = open(hlog,'r').readlines()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
400 print >> sys.stdout,x
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
401 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
402 os.unlink(hlog)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
403 retval = retval1 or retval2
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
404 return retval
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
405
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
406
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
407 def getfSize(self,fpath,outpath):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
408 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
409 format a nice file size string
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
410 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
411 size = ''
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
412 fp = os.path.join(outpath,fpath)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
413 if os.path.isfile(fp):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
414 size = '0 B'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
415 n = float(os.path.getsize(fp))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
416 if n > 2**20:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
417 size = '%1.1f MB' % (n/2**20)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
418 elif n > 2**10:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
419 size = '%1.1f KB' % (n/2**10)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
420 elif n > 0:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
421 size = '%d B' % (int(n))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
422 return size
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
423
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
424 def makeHtml(self):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
425 """ Create an HTML file content to list all the artifacts found in the output_dir
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
426 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
427
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
428 galhtmlprefix = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
429 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
430 <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
431 <meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" />
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
432 <title></title>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
433 <link rel="stylesheet" href="/static/style/base.css" type="text/css" />
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
434 </head>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
435 <body>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
436 <div class="toolFormBody">
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
437 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
438 galhtmlattr = """<hr/><div class="infomessage">This tool (%s) was generated by the <a href="https://bitbucket.org/fubar/galaxytoolfactory/overview">Galaxy Tool Factory</a></div><br/>"""
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
439 galhtmlpostfix = """</div></body></html>\n"""
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
440
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
441 flist = os.listdir(self.opts.output_dir)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
442 flist = [x for x in flist if x <> 'Rplots.pdf']
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
443 flist.sort()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
444 html = []
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
445 html.append(galhtmlprefix % progname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
446 html.append('<div class="infomessage">Galaxy Tool "%s" run at %s</div><br/>' % (self.toolname,timenow()))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
447 fhtml = []
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
448 if len(flist) > 0:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
449 logfiles = [x for x in flist if x.lower().endswith('.log')] # log file names determine sections
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
450 logfiles.sort()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
451 logfiles = [x for x in logfiles if os.path.abspath(x) <> os.path.abspath(self.tlog)]
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
452 logfiles.append(os.path.abspath(self.tlog)) # make it the last one
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
453 pdflist = []
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
454 npdf = len([x for x in flist if os.path.splitext(x)[-1].lower() == '.pdf'])
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
455 for rownum,fname in enumerate(flist):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
456 dname,e = os.path.splitext(fname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
457 sfsize = self.getfSize(fname,self.opts.output_dir)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
458 if e.lower() == '.pdf' : # compress and make a thumbnail
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
459 thumb = '%s.%s' % (dname,self.thumbformat)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
460 pdff = os.path.join(self.opts.output_dir,fname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
461 retval = self.compressPDF(inpdf=pdff,thumbformat=self.thumbformat)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
462 if retval == 0:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
463 pdflist.append((fname,thumb))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
464 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
465 pdflist.append((fname,fname))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
466 if (rownum+1) % 2 == 0:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
467 fhtml.append('<tr class="odd_row"><td><a href="%s">%s</a></td><td>%s</td></tr>' % (fname,fname,sfsize))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
468 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
469 fhtml.append('<tr><td><a href="%s">%s</a></td><td>%s</td></tr>' % (fname,fname,sfsize))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
470 for logfname in logfiles: # expect at least tlog - if more
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
471 if os.path.abspath(logfname) == os.path.abspath(self.tlog): # handled later
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
472 sectionname = 'All tool run'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
473 if (len(logfiles) > 1):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
474 sectionname = 'Other'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
475 ourpdfs = pdflist
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
476 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
477 realname = os.path.basename(logfname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
478 sectionname = os.path.splitext(realname)[0].split('_')[0] # break in case _ added to log
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
479 ourpdfs = [x for x in pdflist if os.path.basename(x[0]).split('_')[0] == sectionname]
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
480 pdflist = [x for x in pdflist if os.path.basename(x[0]).split('_')[0] <> sectionname] # remove
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
481 nacross = 1
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
482 npdf = len(ourpdfs)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
483
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
484 if npdf > 0:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
485 nacross = math.sqrt(npdf) ## int(round(math.log(npdf,2)))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
486 if int(nacross)**2 != npdf:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
487 nacross += 1
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
488 nacross = int(nacross)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
489 width = min(400,int(1200/nacross))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
490 html.append('<div class="toolFormTitle">%s images and outputs</div>' % sectionname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
491 html.append('(Click on a thumbnail image to download the corresponding original PDF image)<br/>')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
492 ntogo = nacross # counter for table row padding with empty cells
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
493 html.append('<div><table class="simple" cellpadding="2" cellspacing="2">\n<tr>')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
494 for i,paths in enumerate(ourpdfs):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
495 fname,thumb = paths
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
496 s= """<td><a href="%s"><img src="%s" title="Click to download a PDF of %s" hspace="5" width="%d"
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
497 alt="Image called %s"/></a></td>\n""" % (fname,thumb,fname,width,fname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
498 if ((i+1) % nacross == 0):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
499 s += '</tr>\n'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
500 ntogo = 0
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
501 if i < (npdf - 1): # more to come
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
502 s += '<tr>'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
503 ntogo = nacross
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
504 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
505 ntogo -= 1
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
506 html.append(s)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
507 if html[-1].strip().endswith('</tr>'):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
508 html.append('</table></div>\n')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
509 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
510 if ntogo > 0: # pad
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
511 html.append('<td>&nbsp;</td>'*ntogo)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
512 html.append('</tr></table></div>\n')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
513 logt = open(logfname,'r').readlines()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
514 logtext = [x for x in logt if x.strip() > '']
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
515 html.append('<div class="toolFormTitle">%s log output</div>' % sectionname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
516 if len(logtext) > 1:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
517 html.append('\n<pre>\n')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
518 html += logtext
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
519 html.append('\n</pre>\n')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
520 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
521 html.append('%s is empty<br/>' % logfname)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
522 if len(fhtml) > 0:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
523 fhtml.insert(0,'<div><table class="colored" cellpadding="3" cellspacing="3"><tr><th>Output File Name (click to view)</th><th>Size</th></tr>\n')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
524 fhtml.append('</table></div><br/>')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
525 html.append('<div class="toolFormTitle">All output files available for downloading</div>\n')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
526 html += fhtml # add all non-pdf files to the end of the display
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
527 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
528 html.append('<div class="warningmessagelarge">### Error - %s returned no files - please confirm that parameters are sane</div>' % self.opts.interpreter)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
529 html.append(galhtmlpostfix)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
530 htmlf = file(self.opts.output_html,'w')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
531 htmlf.write('\n'.join(html))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
532 htmlf.write('\n')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
533 htmlf.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
534 self.html = html
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
535
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
536
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
537 def run(self):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
538 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
539 scripts must be small enough not to fill the pipe!
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
540 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
541 if self.treatbashSpecial and self.opts.interpreter in ['bash','sh']:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
542 retval = self.runBash()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
543 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
544 if self.opts.output_dir:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
545 ste = open(self.elog,'w')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
546 sto = open(self.tlog,'w')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
547 sto.write('## Toolfactory generated command line = %s\n' % ' '.join(self.cl))
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
548 sto.flush()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
549 p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=ste,stdin=subprocess.PIPE,cwd=self.opts.output_dir)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
550 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
551 p = subprocess.Popen(self.cl,shell=False,stdin=subprocess.PIPE)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
552 p.stdin.write(self.script)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
553 p.stdin.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
554 retval = p.wait()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
555 if self.opts.output_dir:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
556 sto.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
557 ste.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
558 err = open(self.elog,'r').readlines()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
559 if retval <> 0 and err: # problem
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
560 print >> sys.stderr,err
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
561 if self.opts.make_HTML:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
562 self.makeHtml()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
563 return retval
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
564
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
565 def runBash(self):
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
566 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
567 cannot use - for bash so use self.sfile
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
568 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
569 if self.opts.output_dir:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
570 s = '## Toolfactory generated command line = %s\n' % ' '.join(self.cl)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
571 sto = open(self.tlog,'w')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
572 sto.write(s)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
573 sto.flush()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
574 p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=sto,cwd=self.opts.output_dir)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
575 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
576 p = subprocess.Popen(self.cl,shell=False)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
577 retval = p.wait()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
578 if self.opts.output_dir:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
579 sto.close()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
580 if self.opts.make_HTML:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
581 self.makeHtml()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
582 return retval
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
583
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
584
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
585 def main():
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
586 u = """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
587 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
588 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript"
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
589 </command>
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
590 """
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
591 op = optparse.OptionParser()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
592 a = op.add_option
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
593 a('--script_path',default=None)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
594 a('--tool_name',default=None)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
595 a('--interpreter',default=None)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
596 a('--output_dir',default=None)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
597 a('--output_html',default=None)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
598 a('--input_tab',default="None")
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
599 a('--output_tab',default="None")
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
600 a('--user_email',default='Unknown')
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
601 a('--bad_user',default=None)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
602 a('--make_Tool',default=None)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
603 a('--make_HTML',default=None)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
604 a('--help_text',default=None)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
605 a('--tool_desc',default=None)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
606 a('--new_tool',default=None)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
607 a('--tool_version',default=None)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
608 opts, args = op.parse_args()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
609 assert not opts.bad_user,'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to admin_users in universe_wsgi.ini' % (opts.bad_user,opts.bad_user)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
610 assert opts.tool_name,'## Tool Factory expects a tool name - eg --tool_name=DESeq'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
611 assert opts.interpreter,'## Tool Factory wrapper expects an interpreter - eg --interpreter=Rscript'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
612 assert os.path.isfile(opts.script_path),'## Tool Factory wrapper expects a script path - eg --script_path=foo.R'
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
613 if opts.output_dir:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
614 try:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
615 os.makedirs(opts.output_dir)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
616 except:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
617 pass
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
618 r = ScriptRunner(opts)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
619 if opts.make_Tool:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
620 retcode = r.makeTooltar()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
621 else:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
622 retcode = r.run()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
623 os.unlink(r.sfile)
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
624 if retcode:
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
625 sys.exit(retcode) # indicate failure to job runner
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
626
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
627
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
628 if __name__ == "__main__":
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
629 main()
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
630
c0fa3dde02d9 Uploaded
fubar
parents:
diff changeset
631