annotate rgToolFactory2.py @ 42:b938475235e3 draft

Uploaded
author fubar
date Sun, 16 Aug 2020 08:33:09 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42
b938475235e3 Uploaded
fubar
parents:
diff changeset
1 #!/usr/bin/env python
b938475235e3 Uploaded
fubar
parents:
diff changeset
2 # rgToolFactory.py
b938475235e3 Uploaded
fubar
parents:
diff changeset
3 # see https://github.com/fubar2/toolfactory
b938475235e3 Uploaded
fubar
parents:
diff changeset
4 #
b938475235e3 Uploaded
fubar
parents:
diff changeset
5 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
b938475235e3 Uploaded
fubar
parents:
diff changeset
6 #
b938475235e3 Uploaded
fubar
parents:
diff changeset
7 # all rights reserved
b938475235e3 Uploaded
fubar
parents:
diff changeset
8 # Licensed under the LGPL
b938475235e3 Uploaded
fubar
parents:
diff changeset
9 # suggestions for improvement and bug fixes welcome at https://github.com/fubar2/toolfactory
b938475235e3 Uploaded
fubar
parents:
diff changeset
10 #
b938475235e3 Uploaded
fubar
parents:
diff changeset
11 # July 2020: BCC was fun and I feel like rip van winkle after 5 years.
b938475235e3 Uploaded
fubar
parents:
diff changeset
12 # Decided to
b938475235e3 Uploaded
fubar
parents:
diff changeset
13 # 1. Fix the toolfactory so it works - done for simplest case
b938475235e3 Uploaded
fubar
parents:
diff changeset
14 # 2. Fix planemo so the toolfactory function works
b938475235e3 Uploaded
fubar
parents:
diff changeset
15 # 3. Rewrite bits using galaxyxml functions where that makes sense - done
b938475235e3 Uploaded
fubar
parents:
diff changeset
16 #
b938475235e3 Uploaded
fubar
parents:
diff changeset
17 # removed all the old complications including making the new tool use this same script
b938475235e3 Uploaded
fubar
parents:
diff changeset
18 # galaxyxml now generates the tool xml https://github.com/hexylena/galaxyxml
b938475235e3 Uploaded
fubar
parents:
diff changeset
19 # No support for automatic HTML file creation from arbitrary outputs
b938475235e3 Uploaded
fubar
parents:
diff changeset
20 # essential problem is to create two command lines - one for the tool xml and a different
b938475235e3 Uploaded
fubar
parents:
diff changeset
21 # one to run the executable with the supplied test data and settings
b938475235e3 Uploaded
fubar
parents:
diff changeset
22 # Be simpler to write the tool, then run it with planemo and soak up the test outputs.
b938475235e3 Uploaded
fubar
parents:
diff changeset
23
b938475235e3 Uploaded
fubar
parents:
diff changeset
24
b938475235e3 Uploaded
fubar
parents:
diff changeset
25
b938475235e3 Uploaded
fubar
parents:
diff changeset
26 import argparse
b938475235e3 Uploaded
fubar
parents:
diff changeset
27 import logging
b938475235e3 Uploaded
fubar
parents:
diff changeset
28 import os
b938475235e3 Uploaded
fubar
parents:
diff changeset
29 import re
b938475235e3 Uploaded
fubar
parents:
diff changeset
30 import shutil
b938475235e3 Uploaded
fubar
parents:
diff changeset
31 import subprocess
b938475235e3 Uploaded
fubar
parents:
diff changeset
32 import sys
b938475235e3 Uploaded
fubar
parents:
diff changeset
33 import tarfile
b938475235e3 Uploaded
fubar
parents:
diff changeset
34 import tempfile
b938475235e3 Uploaded
fubar
parents:
diff changeset
35 import time
b938475235e3 Uploaded
fubar
parents:
diff changeset
36
b938475235e3 Uploaded
fubar
parents:
diff changeset
37 import galaxyxml.tool as gxt
b938475235e3 Uploaded
fubar
parents:
diff changeset
38 import galaxyxml.tool.parameters as gxtp
b938475235e3 Uploaded
fubar
parents:
diff changeset
39
b938475235e3 Uploaded
fubar
parents:
diff changeset
40 import lxml
b938475235e3 Uploaded
fubar
parents:
diff changeset
41
b938475235e3 Uploaded
fubar
parents:
diff changeset
42 myversion = "V2.1 July 2020"
b938475235e3 Uploaded
fubar
parents:
diff changeset
43 verbose = True
b938475235e3 Uploaded
fubar
parents:
diff changeset
44 debug = True
b938475235e3 Uploaded
fubar
parents:
diff changeset
45 toolFactoryURL = "https://github.com/fubar2/toolfactory"
b938475235e3 Uploaded
fubar
parents:
diff changeset
46 ourdelim = "~~~"
b938475235e3 Uploaded
fubar
parents:
diff changeset
47
b938475235e3 Uploaded
fubar
parents:
diff changeset
48 # --input_files="$input_files~~~$CL~~~$input_formats~~~$input_label
b938475235e3 Uploaded
fubar
parents:
diff changeset
49 # ~~~$input_help"
b938475235e3 Uploaded
fubar
parents:
diff changeset
50 IPATHPOS = 0
b938475235e3 Uploaded
fubar
parents:
diff changeset
51 ICLPOS = 1
b938475235e3 Uploaded
fubar
parents:
diff changeset
52 IFMTPOS = 2
b938475235e3 Uploaded
fubar
parents:
diff changeset
53 ILABPOS = 3
b938475235e3 Uploaded
fubar
parents:
diff changeset
54 IHELPOS = 4
b938475235e3 Uploaded
fubar
parents:
diff changeset
55 IOCLPOS = 5
b938475235e3 Uploaded
fubar
parents:
diff changeset
56
b938475235e3 Uploaded
fubar
parents:
diff changeset
57 # --output_files "$otab.history_name~~~$otab.history_format~~~$otab.CL
b938475235e3 Uploaded
fubar
parents:
diff changeset
58 ONAMEPOS = 0
b938475235e3 Uploaded
fubar
parents:
diff changeset
59 OFMTPOS = 1
b938475235e3 Uploaded
fubar
parents:
diff changeset
60 OCLPOS = 2
b938475235e3 Uploaded
fubar
parents:
diff changeset
61 OOCLPOS = 3
b938475235e3 Uploaded
fubar
parents:
diff changeset
62
b938475235e3 Uploaded
fubar
parents:
diff changeset
63 # --additional_parameters="$i.param_name~~~$i.param_value~~~
b938475235e3 Uploaded
fubar
parents:
diff changeset
64 # $i.param_label~~~$i.param_help~~~$i.param_type~~~$i.CL~~~i$.param_CLoverride"
b938475235e3 Uploaded
fubar
parents:
diff changeset
65 ANAMEPOS = 0
b938475235e3 Uploaded
fubar
parents:
diff changeset
66 AVALPOS = 1
b938475235e3 Uploaded
fubar
parents:
diff changeset
67 ALABPOS = 2
b938475235e3 Uploaded
fubar
parents:
diff changeset
68 AHELPPOS = 3
b938475235e3 Uploaded
fubar
parents:
diff changeset
69 ATYPEPOS = 4
b938475235e3 Uploaded
fubar
parents:
diff changeset
70 ACLPOS = 5
b938475235e3 Uploaded
fubar
parents:
diff changeset
71 AOVERPOS = 6
b938475235e3 Uploaded
fubar
parents:
diff changeset
72 AOCLPOS = 7
b938475235e3 Uploaded
fubar
parents:
diff changeset
73
b938475235e3 Uploaded
fubar
parents:
diff changeset
74
b938475235e3 Uploaded
fubar
parents:
diff changeset
75 foo = len(lxml.__version__)
b938475235e3 Uploaded
fubar
parents:
diff changeset
76 # fug you, flake8. Say my name!
b938475235e3 Uploaded
fubar
parents:
diff changeset
77
b938475235e3 Uploaded
fubar
parents:
diff changeset
78 def timenow():
b938475235e3 Uploaded
fubar
parents:
diff changeset
79 """return current time as a string
b938475235e3 Uploaded
fubar
parents:
diff changeset
80 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
81 return time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(time.time()))
b938475235e3 Uploaded
fubar
parents:
diff changeset
82
b938475235e3 Uploaded
fubar
parents:
diff changeset
83
b938475235e3 Uploaded
fubar
parents:
diff changeset
84 def quote_non_numeric(s):
b938475235e3 Uploaded
fubar
parents:
diff changeset
85 """return a prequoted string for non-numerics
b938475235e3 Uploaded
fubar
parents:
diff changeset
86 useful for perl and Rscript parameter passing?
b938475235e3 Uploaded
fubar
parents:
diff changeset
87 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
88 try:
b938475235e3 Uploaded
fubar
parents:
diff changeset
89 _ = float(s)
b938475235e3 Uploaded
fubar
parents:
diff changeset
90 return s
b938475235e3 Uploaded
fubar
parents:
diff changeset
91 except ValueError:
b938475235e3 Uploaded
fubar
parents:
diff changeset
92 return '"%s"' % s
b938475235e3 Uploaded
fubar
parents:
diff changeset
93
b938475235e3 Uploaded
fubar
parents:
diff changeset
94
b938475235e3 Uploaded
fubar
parents:
diff changeset
95 html_escape_table = {"&": "&amp;", ">": "&gt;", "<": "&lt;", "$": r"\$"}
b938475235e3 Uploaded
fubar
parents:
diff changeset
96
b938475235e3 Uploaded
fubar
parents:
diff changeset
97
b938475235e3 Uploaded
fubar
parents:
diff changeset
98 def html_escape(text):
b938475235e3 Uploaded
fubar
parents:
diff changeset
99 """Produce entities within text."""
b938475235e3 Uploaded
fubar
parents:
diff changeset
100 return "".join(html_escape_table.get(c, c) for c in text)
b938475235e3 Uploaded
fubar
parents:
diff changeset
101
b938475235e3 Uploaded
fubar
parents:
diff changeset
102
b938475235e3 Uploaded
fubar
parents:
diff changeset
103 def html_unescape(text):
b938475235e3 Uploaded
fubar
parents:
diff changeset
104 """Revert entities within text. Multiple character targets so use replace"""
b938475235e3 Uploaded
fubar
parents:
diff changeset
105 t = text.replace("&amp;", "&")
b938475235e3 Uploaded
fubar
parents:
diff changeset
106 t = t.replace("&gt;", ">")
b938475235e3 Uploaded
fubar
parents:
diff changeset
107 t = t.replace("&lt;", "<")
b938475235e3 Uploaded
fubar
parents:
diff changeset
108 t = t.replace("\\$", "$")
b938475235e3 Uploaded
fubar
parents:
diff changeset
109 return t
b938475235e3 Uploaded
fubar
parents:
diff changeset
110
b938475235e3 Uploaded
fubar
parents:
diff changeset
111
b938475235e3 Uploaded
fubar
parents:
diff changeset
112 def parse_citations(citations_text):
b938475235e3 Uploaded
fubar
parents:
diff changeset
113 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
114 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
115 citations = [c for c in citations_text.split("**ENTRY**") if c.strip()]
b938475235e3 Uploaded
fubar
parents:
diff changeset
116 citation_tuples = []
b938475235e3 Uploaded
fubar
parents:
diff changeset
117 for citation in citations:
b938475235e3 Uploaded
fubar
parents:
diff changeset
118 if citation.startswith("doi"):
b938475235e3 Uploaded
fubar
parents:
diff changeset
119 citation_tuples.append(("doi", citation[len("doi") :].strip()))
b938475235e3 Uploaded
fubar
parents:
diff changeset
120 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
121 citation_tuples.append(
b938475235e3 Uploaded
fubar
parents:
diff changeset
122 ("bibtex", citation[len("bibtex") :].strip())
b938475235e3 Uploaded
fubar
parents:
diff changeset
123 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
124 return citation_tuples
b938475235e3 Uploaded
fubar
parents:
diff changeset
125
b938475235e3 Uploaded
fubar
parents:
diff changeset
126
b938475235e3 Uploaded
fubar
parents:
diff changeset
127 class ScriptRunner:
b938475235e3 Uploaded
fubar
parents:
diff changeset
128 """Wrapper for an arbitrary script
b938475235e3 Uploaded
fubar
parents:
diff changeset
129 uses galaxyxml
b938475235e3 Uploaded
fubar
parents:
diff changeset
130
b938475235e3 Uploaded
fubar
parents:
diff changeset
131 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
132
b938475235e3 Uploaded
fubar
parents:
diff changeset
133 def __init__(self, args=None):
b938475235e3 Uploaded
fubar
parents:
diff changeset
134 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
135 prepare command line cl for running the tool here
b938475235e3 Uploaded
fubar
parents:
diff changeset
136 and prepare elements needed for galaxyxml tool generation
b938475235e3 Uploaded
fubar
parents:
diff changeset
137 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
138
b938475235e3 Uploaded
fubar
parents:
diff changeset
139 self.infiles = [x.split(ourdelim) for x in args.input_files]
b938475235e3 Uploaded
fubar
parents:
diff changeset
140 self.outfiles = [x.split(ourdelim) for x in args.output_files]
b938475235e3 Uploaded
fubar
parents:
diff changeset
141 self.addpar = [x.split(ourdelim) for x in args.additional_parameters]
b938475235e3 Uploaded
fubar
parents:
diff changeset
142 self.args = args
b938475235e3 Uploaded
fubar
parents:
diff changeset
143 self.cleanuppar()
b938475235e3 Uploaded
fubar
parents:
diff changeset
144 self.lastclredirect = None
b938475235e3 Uploaded
fubar
parents:
diff changeset
145 self.lastxclredirect = None
b938475235e3 Uploaded
fubar
parents:
diff changeset
146 self.cl = []
b938475235e3 Uploaded
fubar
parents:
diff changeset
147 self.xmlcl = []
b938475235e3 Uploaded
fubar
parents:
diff changeset
148 self.is_positional = self.args.parampass == "positional"
b938475235e3 Uploaded
fubar
parents:
diff changeset
149 aCL = self.cl.append
b938475235e3 Uploaded
fubar
parents:
diff changeset
150 assert args.parampass in [
b938475235e3 Uploaded
fubar
parents:
diff changeset
151 "0",
b938475235e3 Uploaded
fubar
parents:
diff changeset
152 "argparse",
b938475235e3 Uploaded
fubar
parents:
diff changeset
153 "positional",
b938475235e3 Uploaded
fubar
parents:
diff changeset
154 ], 'Parameter passing in args.parampass must be "0","positional" or "argparse"'
b938475235e3 Uploaded
fubar
parents:
diff changeset
155 self.tool_name = re.sub("[^a-zA-Z0-9_]+", "", args.tool_name)
b938475235e3 Uploaded
fubar
parents:
diff changeset
156 self.tool_id = self.tool_name
b938475235e3 Uploaded
fubar
parents:
diff changeset
157 if self.args.interpreter_name:
b938475235e3 Uploaded
fubar
parents:
diff changeset
158 exe = "$runMe"
b938475235e3 Uploaded
fubar
parents:
diff changeset
159 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
160 exe = self.args.exe_package
b938475235e3 Uploaded
fubar
parents:
diff changeset
161 assert (
b938475235e3 Uploaded
fubar
parents:
diff changeset
162 exe is not None
b938475235e3 Uploaded
fubar
parents:
diff changeset
163 ), "No interpeter or executable passed in - nothing to run so cannot build"
b938475235e3 Uploaded
fubar
parents:
diff changeset
164 self.tool = gxt.Tool(
b938475235e3 Uploaded
fubar
parents:
diff changeset
165 self.args.tool_name,
b938475235e3 Uploaded
fubar
parents:
diff changeset
166 self.tool_id,
b938475235e3 Uploaded
fubar
parents:
diff changeset
167 self.args.tool_version,
b938475235e3 Uploaded
fubar
parents:
diff changeset
168 self.args.tool_desc,
b938475235e3 Uploaded
fubar
parents:
diff changeset
169 exe,
b938475235e3 Uploaded
fubar
parents:
diff changeset
170 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
171 self.tinputs = gxtp.Inputs()
b938475235e3 Uploaded
fubar
parents:
diff changeset
172 self.toutputs = gxtp.Outputs()
b938475235e3 Uploaded
fubar
parents:
diff changeset
173 self.testparam = []
b938475235e3 Uploaded
fubar
parents:
diff changeset
174 if (
b938475235e3 Uploaded
fubar
parents:
diff changeset
175 self.args.runmode == "Executable" or self.args.runmode == "system"
b938475235e3 Uploaded
fubar
parents:
diff changeset
176 ): # binary - no need
b938475235e3 Uploaded
fubar
parents:
diff changeset
177 aCL(self.args.exe_package) # this little CL will just run
b938475235e3 Uploaded
fubar
parents:
diff changeset
178 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
179 self.prepScript()
b938475235e3 Uploaded
fubar
parents:
diff changeset
180 self.elog = "%s_error_log.txt" % self.tool_name
b938475235e3 Uploaded
fubar
parents:
diff changeset
181 self.tlog = "%s_runner_log.txt" % self.tool_name
b938475235e3 Uploaded
fubar
parents:
diff changeset
182
b938475235e3 Uploaded
fubar
parents:
diff changeset
183 if self.args.parampass == "0":
b938475235e3 Uploaded
fubar
parents:
diff changeset
184 self.clsimple()
b938475235e3 Uploaded
fubar
parents:
diff changeset
185 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
186 clsuffix = []
b938475235e3 Uploaded
fubar
parents:
diff changeset
187 xclsuffix = []
b938475235e3 Uploaded
fubar
parents:
diff changeset
188 for i, p in enumerate(self.infiles):
b938475235e3 Uploaded
fubar
parents:
diff changeset
189 if p[IOCLPOS] == "STDIN":
b938475235e3 Uploaded
fubar
parents:
diff changeset
190 appendme = [
b938475235e3 Uploaded
fubar
parents:
diff changeset
191 p[IOCLPOS],
b938475235e3 Uploaded
fubar
parents:
diff changeset
192 p[ICLPOS],
b938475235e3 Uploaded
fubar
parents:
diff changeset
193 p[IPATHPOS],
b938475235e3 Uploaded
fubar
parents:
diff changeset
194 "< %s" % p[IPATHPOS],
b938475235e3 Uploaded
fubar
parents:
diff changeset
195 ]
b938475235e3 Uploaded
fubar
parents:
diff changeset
196 xappendme = [
b938475235e3 Uploaded
fubar
parents:
diff changeset
197 p[IOCLPOS],
b938475235e3 Uploaded
fubar
parents:
diff changeset
198 p[ICLPOS],
b938475235e3 Uploaded
fubar
parents:
diff changeset
199 p[IPATHPOS],
b938475235e3 Uploaded
fubar
parents:
diff changeset
200 "< $%s" % p[ICLPOS],
b938475235e3 Uploaded
fubar
parents:
diff changeset
201 ]
b938475235e3 Uploaded
fubar
parents:
diff changeset
202 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
203 appendme = [p[IOCLPOS], p[ICLPOS], p[IPATHPOS], ""]
b938475235e3 Uploaded
fubar
parents:
diff changeset
204 xappendme = [p[IOCLPOS], p[ICLPOS], "$%s" % p[ICLPOS], ""]
b938475235e3 Uploaded
fubar
parents:
diff changeset
205 clsuffix.append(appendme)
b938475235e3 Uploaded
fubar
parents:
diff changeset
206 xclsuffix.append(xappendme)
b938475235e3 Uploaded
fubar
parents:
diff changeset
207 # print('##infile i=%d, appendme=%s' % (i,appendme))
b938475235e3 Uploaded
fubar
parents:
diff changeset
208 for i, p in enumerate(self.outfiles):
b938475235e3 Uploaded
fubar
parents:
diff changeset
209 if p[OOCLPOS] == "STDOUT":
b938475235e3 Uploaded
fubar
parents:
diff changeset
210 self.lastclredirect = [">", p[ONAMEPOS]]
b938475235e3 Uploaded
fubar
parents:
diff changeset
211 self.lastxclredirect = [">", "$%s" % p[OCLPOS]]
b938475235e3 Uploaded
fubar
parents:
diff changeset
212 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
213 clsuffix.append([p[OOCLPOS], p[OCLPOS], p[ONAMEPOS], ""])
b938475235e3 Uploaded
fubar
parents:
diff changeset
214 xclsuffix.append(
b938475235e3 Uploaded
fubar
parents:
diff changeset
215 [p[OOCLPOS], p[OCLPOS], "$%s" % p[ONAMEPOS], ""]
b938475235e3 Uploaded
fubar
parents:
diff changeset
216 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
217 for p in self.addpar:
b938475235e3 Uploaded
fubar
parents:
diff changeset
218 clsuffix.append(
b938475235e3 Uploaded
fubar
parents:
diff changeset
219 [p[AOCLPOS], p[ACLPOS], p[AVALPOS], p[AOVERPOS]]
b938475235e3 Uploaded
fubar
parents:
diff changeset
220 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
221 xclsuffix.append(
b938475235e3 Uploaded
fubar
parents:
diff changeset
222 [p[AOCLPOS], p[ACLPOS], '"$%s"' % p[ANAMEPOS], p[AOVERPOS]]
b938475235e3 Uploaded
fubar
parents:
diff changeset
223 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
224 clsuffix.sort()
b938475235e3 Uploaded
fubar
parents:
diff changeset
225 xclsuffix.sort()
b938475235e3 Uploaded
fubar
parents:
diff changeset
226 self.xclsuffix = xclsuffix
b938475235e3 Uploaded
fubar
parents:
diff changeset
227 self.clsuffix = clsuffix
b938475235e3 Uploaded
fubar
parents:
diff changeset
228 if self.args.parampass == "positional":
b938475235e3 Uploaded
fubar
parents:
diff changeset
229 self.clpositional()
b938475235e3 Uploaded
fubar
parents:
diff changeset
230 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
231 self.clargparse()
b938475235e3 Uploaded
fubar
parents:
diff changeset
232
b938475235e3 Uploaded
fubar
parents:
diff changeset
233 def prepScript(self):
b938475235e3 Uploaded
fubar
parents:
diff changeset
234 aCL = self.cl.append
b938475235e3 Uploaded
fubar
parents:
diff changeset
235 rx = open(self.args.script_path, "r").readlines()
b938475235e3 Uploaded
fubar
parents:
diff changeset
236 rx = [x.rstrip() for x in rx]
b938475235e3 Uploaded
fubar
parents:
diff changeset
237 rxcheck = [x.strip() for x in rx if x.strip() > ""]
b938475235e3 Uploaded
fubar
parents:
diff changeset
238 assert len(rxcheck) > 0, "Supplied script is empty. Cannot run"
b938475235e3 Uploaded
fubar
parents:
diff changeset
239 self.script = "\n".join(rx)
b938475235e3 Uploaded
fubar
parents:
diff changeset
240 fhandle, self.sfile = tempfile.mkstemp(
b938475235e3 Uploaded
fubar
parents:
diff changeset
241 prefix=self.tool_name, suffix="_%s" % (self.args.interpreter_name)
b938475235e3 Uploaded
fubar
parents:
diff changeset
242 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
243 tscript = open(self.sfile, "w")
b938475235e3 Uploaded
fubar
parents:
diff changeset
244 tscript.write(self.script)
b938475235e3 Uploaded
fubar
parents:
diff changeset
245 tscript.close()
b938475235e3 Uploaded
fubar
parents:
diff changeset
246 self.indentedScript = " %s" % "\n".join(
b938475235e3 Uploaded
fubar
parents:
diff changeset
247 [" %s" % html_escape(x) for x in rx]
b938475235e3 Uploaded
fubar
parents:
diff changeset
248 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
249 self.escapedScript = "%s" % "\n".join(
b938475235e3 Uploaded
fubar
parents:
diff changeset
250 [" %s" % html_escape(x) for x in rx]
b938475235e3 Uploaded
fubar
parents:
diff changeset
251 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
252 art = "%s.%s" % (self.tool_name, self.args.interpreter_name)
b938475235e3 Uploaded
fubar
parents:
diff changeset
253 artifact = open(art, "wb")
b938475235e3 Uploaded
fubar
parents:
diff changeset
254 if self.args.interpreter_name == "python":
b938475235e3 Uploaded
fubar
parents:
diff changeset
255 artifact.write(bytes("#!/usr/bin/env python\n", "utf8"))
b938475235e3 Uploaded
fubar
parents:
diff changeset
256 artifact.write(bytes(self.script, "utf8"))
b938475235e3 Uploaded
fubar
parents:
diff changeset
257 artifact.close()
b938475235e3 Uploaded
fubar
parents:
diff changeset
258 aCL(self.args.interpreter_name)
b938475235e3 Uploaded
fubar
parents:
diff changeset
259 aCL(self.sfile)
b938475235e3 Uploaded
fubar
parents:
diff changeset
260
b938475235e3 Uploaded
fubar
parents:
diff changeset
261 def cleanuppar(self):
b938475235e3 Uploaded
fubar
parents:
diff changeset
262 """ positional parameters are complicated by their numeric ordinal"""
b938475235e3 Uploaded
fubar
parents:
diff changeset
263 for i, p in enumerate(self.infiles):
b938475235e3 Uploaded
fubar
parents:
diff changeset
264 if self.args.parampass == "positional":
b938475235e3 Uploaded
fubar
parents:
diff changeset
265 assert p[ICLPOS].isdigit(), (
b938475235e3 Uploaded
fubar
parents:
diff changeset
266 "Positional parameters must be ordinal integers - got %s for %s"
b938475235e3 Uploaded
fubar
parents:
diff changeset
267 % (p[ICLPOS], p[ILABPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
268 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
269 p.append(p[ICLPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
270 if p[ICLPOS].isdigit() or self.args.parampass == "0":
b938475235e3 Uploaded
fubar
parents:
diff changeset
271 scl = "input%d" % (i + 1)
b938475235e3 Uploaded
fubar
parents:
diff changeset
272 p[ICLPOS] = scl
b938475235e3 Uploaded
fubar
parents:
diff changeset
273 self.infiles[i] = p
b938475235e3 Uploaded
fubar
parents:
diff changeset
274 for i, p in enumerate(
b938475235e3 Uploaded
fubar
parents:
diff changeset
275 self.outfiles
b938475235e3 Uploaded
fubar
parents:
diff changeset
276 ): # trying to automagically gather using extensions
b938475235e3 Uploaded
fubar
parents:
diff changeset
277 if self.args.parampass == "positional" and p[OCLPOS] != "STDOUT":
b938475235e3 Uploaded
fubar
parents:
diff changeset
278 assert p[OCLPOS].isdigit(), (
b938475235e3 Uploaded
fubar
parents:
diff changeset
279 "Positional parameters must be ordinal integers - got %s for %s"
b938475235e3 Uploaded
fubar
parents:
diff changeset
280 % (p[OCLPOS], p[ONAMEPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
281 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
282 p.append(p[OCLPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
283 if p[OCLPOS].isdigit() or p[OCLPOS] == "STDOUT":
b938475235e3 Uploaded
fubar
parents:
diff changeset
284 scl = p[ONAMEPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
285 p[OCLPOS] = scl
b938475235e3 Uploaded
fubar
parents:
diff changeset
286 self.outfiles[i] = p
b938475235e3 Uploaded
fubar
parents:
diff changeset
287 for i, p in enumerate(self.addpar):
b938475235e3 Uploaded
fubar
parents:
diff changeset
288 if self.args.parampass == "positional":
b938475235e3 Uploaded
fubar
parents:
diff changeset
289 assert p[ACLPOS].isdigit(), (
b938475235e3 Uploaded
fubar
parents:
diff changeset
290 "Positional parameters must be ordinal integers - got %s for %s"
b938475235e3 Uploaded
fubar
parents:
diff changeset
291 % (p[ACLPOS], p[ANAMEPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
292 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
293 p.append(p[ACLPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
294 if p[ACLPOS].isdigit():
b938475235e3 Uploaded
fubar
parents:
diff changeset
295 scl = "input%s" % p[ACLPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
296 p[ACLPOS] = scl
b938475235e3 Uploaded
fubar
parents:
diff changeset
297 self.addpar[i] = p
b938475235e3 Uploaded
fubar
parents:
diff changeset
298
b938475235e3 Uploaded
fubar
parents:
diff changeset
299 def clsimple(self):
b938475235e3 Uploaded
fubar
parents:
diff changeset
300 """ no parameters - uses < and > for i/o
b938475235e3 Uploaded
fubar
parents:
diff changeset
301 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
302 aCL = self.cl.append
b938475235e3 Uploaded
fubar
parents:
diff changeset
303 aCL("<")
b938475235e3 Uploaded
fubar
parents:
diff changeset
304 aCL(self.infiles[0][IPATHPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
305 aCL(">")
b938475235e3 Uploaded
fubar
parents:
diff changeset
306 aCL(self.outfiles[0][OCLPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
307 aXCL = self.xmlcl.append
b938475235e3 Uploaded
fubar
parents:
diff changeset
308 aXCL("<")
b938475235e3 Uploaded
fubar
parents:
diff changeset
309 aXCL("$%s" % self.infiles[0][ICLPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
310 aXCL(">")
b938475235e3 Uploaded
fubar
parents:
diff changeset
311 aXCL("$%s" % self.outfiles[0][ONAMEPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
312
b938475235e3 Uploaded
fubar
parents:
diff changeset
313 def clpositional(self):
b938475235e3 Uploaded
fubar
parents:
diff changeset
314 # inputs in order then params
b938475235e3 Uploaded
fubar
parents:
diff changeset
315 aCL = self.cl.append
b938475235e3 Uploaded
fubar
parents:
diff changeset
316 for (o_v, k, v, koverride) in self.clsuffix:
b938475235e3 Uploaded
fubar
parents:
diff changeset
317 if " " in v:
b938475235e3 Uploaded
fubar
parents:
diff changeset
318 aCL("%s" % v)
b938475235e3 Uploaded
fubar
parents:
diff changeset
319 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
320 aCL(v)
b938475235e3 Uploaded
fubar
parents:
diff changeset
321 aXCL = self.xmlcl.append
b938475235e3 Uploaded
fubar
parents:
diff changeset
322 for (o_v, k, v, koverride) in self.xclsuffix:
b938475235e3 Uploaded
fubar
parents:
diff changeset
323 aXCL(v)
b938475235e3 Uploaded
fubar
parents:
diff changeset
324 if self.lastxclredirect:
b938475235e3 Uploaded
fubar
parents:
diff changeset
325 aXCL(self.lastxclredirect[0])
b938475235e3 Uploaded
fubar
parents:
diff changeset
326 aXCL(self.lastxclredirect[1])
b938475235e3 Uploaded
fubar
parents:
diff changeset
327
b938475235e3 Uploaded
fubar
parents:
diff changeset
328 def clargparse(self):
b938475235e3 Uploaded
fubar
parents:
diff changeset
329 """ argparse style
b938475235e3 Uploaded
fubar
parents:
diff changeset
330 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
331 aCL = self.cl.append
b938475235e3 Uploaded
fubar
parents:
diff changeset
332 aXCL = self.xmlcl.append
b938475235e3 Uploaded
fubar
parents:
diff changeset
333 # inputs then params in argparse named form
b938475235e3 Uploaded
fubar
parents:
diff changeset
334 for (o_v, k, v, koverride) in self.xclsuffix:
b938475235e3 Uploaded
fubar
parents:
diff changeset
335 if koverride > "":
b938475235e3 Uploaded
fubar
parents:
diff changeset
336 k = koverride
b938475235e3 Uploaded
fubar
parents:
diff changeset
337 elif len(k.strip()) == 1:
b938475235e3 Uploaded
fubar
parents:
diff changeset
338 k = "-%s" % k
b938475235e3 Uploaded
fubar
parents:
diff changeset
339 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
340 k = "--%s" % k
b938475235e3 Uploaded
fubar
parents:
diff changeset
341 aXCL(k)
b938475235e3 Uploaded
fubar
parents:
diff changeset
342 aXCL(v)
b938475235e3 Uploaded
fubar
parents:
diff changeset
343 for (o_v, k, v, koverride) in self.clsuffix:
b938475235e3 Uploaded
fubar
parents:
diff changeset
344 if koverride > "":
b938475235e3 Uploaded
fubar
parents:
diff changeset
345 k = koverride
b938475235e3 Uploaded
fubar
parents:
diff changeset
346 elif len(k.strip()) == 1:
b938475235e3 Uploaded
fubar
parents:
diff changeset
347 k = "-%s" % k
b938475235e3 Uploaded
fubar
parents:
diff changeset
348 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
349 k = "--%s" % k
b938475235e3 Uploaded
fubar
parents:
diff changeset
350 aCL(k)
b938475235e3 Uploaded
fubar
parents:
diff changeset
351 aCL(v)
b938475235e3 Uploaded
fubar
parents:
diff changeset
352
b938475235e3 Uploaded
fubar
parents:
diff changeset
353 def getNdash(self, newname):
b938475235e3 Uploaded
fubar
parents:
diff changeset
354 if self.is_positional:
b938475235e3 Uploaded
fubar
parents:
diff changeset
355 ndash = 0
b938475235e3 Uploaded
fubar
parents:
diff changeset
356 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
357 ndash = 2
b938475235e3 Uploaded
fubar
parents:
diff changeset
358 if len(newname) < 2:
b938475235e3 Uploaded
fubar
parents:
diff changeset
359 ndash = 1
b938475235e3 Uploaded
fubar
parents:
diff changeset
360 return ndash
b938475235e3 Uploaded
fubar
parents:
diff changeset
361
b938475235e3 Uploaded
fubar
parents:
diff changeset
362 def doXMLparam(self):
b938475235e3 Uploaded
fubar
parents:
diff changeset
363 """flake8 made me do this..."""
b938475235e3 Uploaded
fubar
parents:
diff changeset
364 for p in self.outfiles:
b938475235e3 Uploaded
fubar
parents:
diff changeset
365 newname, newfmt, newcl, oldcl = p
b938475235e3 Uploaded
fubar
parents:
diff changeset
366 ndash = self.getNdash(newcl)
b938475235e3 Uploaded
fubar
parents:
diff changeset
367 aparm = gxtp.OutputData(newcl, format=newfmt, num_dashes=ndash)
b938475235e3 Uploaded
fubar
parents:
diff changeset
368 aparm.positional = self.is_positional
b938475235e3 Uploaded
fubar
parents:
diff changeset
369 if self.is_positional:
b938475235e3 Uploaded
fubar
parents:
diff changeset
370 if oldcl == "STDOUT":
b938475235e3 Uploaded
fubar
parents:
diff changeset
371 aparm.positional = 9999999
b938475235e3 Uploaded
fubar
parents:
diff changeset
372 aparm.command_line_override = "> $%s" % newcl
b938475235e3 Uploaded
fubar
parents:
diff changeset
373 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
374 aparm.positional = int(oldcl)
b938475235e3 Uploaded
fubar
parents:
diff changeset
375 aparm.command_line_override = "$%s" % newcl
b938475235e3 Uploaded
fubar
parents:
diff changeset
376 self.toutputs.append(aparm)
b938475235e3 Uploaded
fubar
parents:
diff changeset
377 tp = gxtp.TestOutput(
b938475235e3 Uploaded
fubar
parents:
diff changeset
378 name=newcl, value="%s_sample" % newcl, format=newfmt
b938475235e3 Uploaded
fubar
parents:
diff changeset
379 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
380 self.testparam.append(tp)
b938475235e3 Uploaded
fubar
parents:
diff changeset
381 for p in self.infiles:
b938475235e3 Uploaded
fubar
parents:
diff changeset
382 newname = p[ICLPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
383 newfmt = p[IFMTPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
384 ndash = self.getNdash(newname)
b938475235e3 Uploaded
fubar
parents:
diff changeset
385 if not len(p[ILABPOS]) > 0:
b938475235e3 Uploaded
fubar
parents:
diff changeset
386 alab = p[ICLPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
387 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
388 alab = p[ILABPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
389 aninput = gxtp.DataParam(
b938475235e3 Uploaded
fubar
parents:
diff changeset
390 newname,
b938475235e3 Uploaded
fubar
parents:
diff changeset
391 optional=False,
b938475235e3 Uploaded
fubar
parents:
diff changeset
392 label=alab,
b938475235e3 Uploaded
fubar
parents:
diff changeset
393 help=p[IHELPOS],
b938475235e3 Uploaded
fubar
parents:
diff changeset
394 format=newfmt,
b938475235e3 Uploaded
fubar
parents:
diff changeset
395 multiple=False,
b938475235e3 Uploaded
fubar
parents:
diff changeset
396 num_dashes=ndash,
b938475235e3 Uploaded
fubar
parents:
diff changeset
397 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
398 aninput.positional = self.is_positional
b938475235e3 Uploaded
fubar
parents:
diff changeset
399 self.tinputs.append(aninput)
b938475235e3 Uploaded
fubar
parents:
diff changeset
400 tparm = gxtp.TestParam(name=newname, value="%s_sample" % newname)
b938475235e3 Uploaded
fubar
parents:
diff changeset
401 self.testparam.append(tparm)
b938475235e3 Uploaded
fubar
parents:
diff changeset
402 for p in self.addpar:
b938475235e3 Uploaded
fubar
parents:
diff changeset
403 newname, newval, newlabel, newhelp, newtype, newcl, override, oldcl = p
b938475235e3 Uploaded
fubar
parents:
diff changeset
404 if not len(newlabel) > 0:
b938475235e3 Uploaded
fubar
parents:
diff changeset
405 newlabel = newname
b938475235e3 Uploaded
fubar
parents:
diff changeset
406 ndash = self.getNdash(newname)
b938475235e3 Uploaded
fubar
parents:
diff changeset
407 if newtype == "text":
b938475235e3 Uploaded
fubar
parents:
diff changeset
408 aparm = gxtp.TextParam(
b938475235e3 Uploaded
fubar
parents:
diff changeset
409 newname,
b938475235e3 Uploaded
fubar
parents:
diff changeset
410 label=newlabel,
b938475235e3 Uploaded
fubar
parents:
diff changeset
411 help=newhelp,
b938475235e3 Uploaded
fubar
parents:
diff changeset
412 value=newval,
b938475235e3 Uploaded
fubar
parents:
diff changeset
413 num_dashes=ndash,
b938475235e3 Uploaded
fubar
parents:
diff changeset
414 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
415 elif newtype == "integer":
b938475235e3 Uploaded
fubar
parents:
diff changeset
416 aparm = gxtp.IntegerParam(
b938475235e3 Uploaded
fubar
parents:
diff changeset
417 newname,
b938475235e3 Uploaded
fubar
parents:
diff changeset
418 label=newname,
b938475235e3 Uploaded
fubar
parents:
diff changeset
419 help=newhelp,
b938475235e3 Uploaded
fubar
parents:
diff changeset
420 value=newval,
b938475235e3 Uploaded
fubar
parents:
diff changeset
421 num_dashes=ndash,
b938475235e3 Uploaded
fubar
parents:
diff changeset
422 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
423 elif newtype == "float":
b938475235e3 Uploaded
fubar
parents:
diff changeset
424 aparm = gxtp.FloatParam(
b938475235e3 Uploaded
fubar
parents:
diff changeset
425 newname,
b938475235e3 Uploaded
fubar
parents:
diff changeset
426 label=newname,
b938475235e3 Uploaded
fubar
parents:
diff changeset
427 help=newhelp,
b938475235e3 Uploaded
fubar
parents:
diff changeset
428 value=newval,
b938475235e3 Uploaded
fubar
parents:
diff changeset
429 num_dashes=ndash,
b938475235e3 Uploaded
fubar
parents:
diff changeset
430 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
431 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
432 raise ValueError(
b938475235e3 Uploaded
fubar
parents:
diff changeset
433 'Unrecognised parameter type "%s" for\
b938475235e3 Uploaded
fubar
parents:
diff changeset
434 additional parameter %s in makeXML'
b938475235e3 Uploaded
fubar
parents:
diff changeset
435 % (newtype, newname)
b938475235e3 Uploaded
fubar
parents:
diff changeset
436 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
437 aparm.positional = self.is_positional
b938475235e3 Uploaded
fubar
parents:
diff changeset
438 if self.is_positional:
b938475235e3 Uploaded
fubar
parents:
diff changeset
439 aninput.positional = int(oldcl)
b938475235e3 Uploaded
fubar
parents:
diff changeset
440 self.tinputs.append(aparm)
b938475235e3 Uploaded
fubar
parents:
diff changeset
441 self.tparm = gxtp.TestParam(newname, value=newval)
b938475235e3 Uploaded
fubar
parents:
diff changeset
442 self.testparam.append(tparm)
b938475235e3 Uploaded
fubar
parents:
diff changeset
443
b938475235e3 Uploaded
fubar
parents:
diff changeset
444 def doNoXMLparam(self):
b938475235e3 Uploaded
fubar
parents:
diff changeset
445 alab = self.infiles[0][ILABPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
446 if len(alab) == 0:
b938475235e3 Uploaded
fubar
parents:
diff changeset
447 alab = self.infiles[0][ICLPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
448 max1s = (
b938475235e3 Uploaded
fubar
parents:
diff changeset
449 "Maximum one input if parampass is 0 - more than one input files supplied - %s"
b938475235e3 Uploaded
fubar
parents:
diff changeset
450 % str(self.infiles)
b938475235e3 Uploaded
fubar
parents:
diff changeset
451 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
452 assert len(self.infiles) == 1, max1s
b938475235e3 Uploaded
fubar
parents:
diff changeset
453 newname = self.infiles[0][ICLPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
454 aninput = gxtp.DataParam(
b938475235e3 Uploaded
fubar
parents:
diff changeset
455 newname,
b938475235e3 Uploaded
fubar
parents:
diff changeset
456 optional=False,
b938475235e3 Uploaded
fubar
parents:
diff changeset
457 label=alab,
b938475235e3 Uploaded
fubar
parents:
diff changeset
458 help=self.infiles[0][IHELPOS],
b938475235e3 Uploaded
fubar
parents:
diff changeset
459 format=self.infiles[0][IFMTPOS],
b938475235e3 Uploaded
fubar
parents:
diff changeset
460 multiple=False,
b938475235e3 Uploaded
fubar
parents:
diff changeset
461 num_dashes=0,
b938475235e3 Uploaded
fubar
parents:
diff changeset
462 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
463 aninput.command_line_override = "< $%s" % newname
b938475235e3 Uploaded
fubar
parents:
diff changeset
464 aninput.positional = self.is_positional
b938475235e3 Uploaded
fubar
parents:
diff changeset
465 self.tinputs.append(aninput)
b938475235e3 Uploaded
fubar
parents:
diff changeset
466 tp = gxtp.TestParam(name=newname, value="%s_sample" % newname)
b938475235e3 Uploaded
fubar
parents:
diff changeset
467 self.testparam.append(tp)
b938475235e3 Uploaded
fubar
parents:
diff changeset
468 newname = self.outfiles[0][OCLPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
469 newfmt = self.outfiles[0][OFMTPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
470 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0)
b938475235e3 Uploaded
fubar
parents:
diff changeset
471 anout.command_line_override = "> $%s" % newname
b938475235e3 Uploaded
fubar
parents:
diff changeset
472 anout.positional = self.is_positional
b938475235e3 Uploaded
fubar
parents:
diff changeset
473 self.toutputs.append(anout)
b938475235e3 Uploaded
fubar
parents:
diff changeset
474 tp = gxtp.TestOutput(
b938475235e3 Uploaded
fubar
parents:
diff changeset
475 name=newname, value="%s_sample" % newname, format=newfmt
b938475235e3 Uploaded
fubar
parents:
diff changeset
476 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
477 self.testparam.append(tp)
b938475235e3 Uploaded
fubar
parents:
diff changeset
478
b938475235e3 Uploaded
fubar
parents:
diff changeset
479 def makeXML(self):
b938475235e3 Uploaded
fubar
parents:
diff changeset
480 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
481 Create a Galaxy xml tool wrapper for the new script
b938475235e3 Uploaded
fubar
parents:
diff changeset
482 Uses galaxyhtml
b938475235e3 Uploaded
fubar
parents:
diff changeset
483 Hmmm. How to get the command line into correct order...
b938475235e3 Uploaded
fubar
parents:
diff changeset
484 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
485 self.tool.command_line_override = self.xmlcl
b938475235e3 Uploaded
fubar
parents:
diff changeset
486 if self.args.interpreter_name:
b938475235e3 Uploaded
fubar
parents:
diff changeset
487 self.tool.interpreter = self.args.interpreter_name
b938475235e3 Uploaded
fubar
parents:
diff changeset
488 if self.args.help_text:
b938475235e3 Uploaded
fubar
parents:
diff changeset
489 helptext = open(self.args.help_text, "r").readlines()
b938475235e3 Uploaded
fubar
parents:
diff changeset
490 helptext = [html_escape(x) for x in helptext]
b938475235e3 Uploaded
fubar
parents:
diff changeset
491 self.tool.help = "".join([x for x in helptext])
b938475235e3 Uploaded
fubar
parents:
diff changeset
492 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
493 self.tool.help = (
b938475235e3 Uploaded
fubar
parents:
diff changeset
494 "Please ask the tool author (%s) for help \
b938475235e3 Uploaded
fubar
parents:
diff changeset
495 as none was supplied at tool generation\n"
b938475235e3 Uploaded
fubar
parents:
diff changeset
496 % (self.args.user_email)
b938475235e3 Uploaded
fubar
parents:
diff changeset
497 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
498 self.tool.version_command = None # do not want
b938475235e3 Uploaded
fubar
parents:
diff changeset
499 requirements = gxtp.Requirements()
b938475235e3 Uploaded
fubar
parents:
diff changeset
500
b938475235e3 Uploaded
fubar
parents:
diff changeset
501 if self.args.interpreter_name:
b938475235e3 Uploaded
fubar
parents:
diff changeset
502 if self.args.interpreter_name == "python":
b938475235e3 Uploaded
fubar
parents:
diff changeset
503 requirements.append(
b938475235e3 Uploaded
fubar
parents:
diff changeset
504 gxtp.Requirement(
b938475235e3 Uploaded
fubar
parents:
diff changeset
505 "package", "python", self.args.interpreter_version
b938475235e3 Uploaded
fubar
parents:
diff changeset
506 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
507 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
508 elif self.args.interpreter_name not in ["bash", "sh"]:
b938475235e3 Uploaded
fubar
parents:
diff changeset
509 requirements.append(
b938475235e3 Uploaded
fubar
parents:
diff changeset
510 gxtp.Requirement(
b938475235e3 Uploaded
fubar
parents:
diff changeset
511 "package",
b938475235e3 Uploaded
fubar
parents:
diff changeset
512 self.args.interpreter_name,
b938475235e3 Uploaded
fubar
parents:
diff changeset
513 self.args.interpreter_version,
b938475235e3 Uploaded
fubar
parents:
diff changeset
514 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
515 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
516 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
517 if self.args.exe_package and self.args.parampass != "system":
b938475235e3 Uploaded
fubar
parents:
diff changeset
518 requirements.append(
b938475235e3 Uploaded
fubar
parents:
diff changeset
519 gxtp.Requirement(
b938475235e3 Uploaded
fubar
parents:
diff changeset
520 "package",
b938475235e3 Uploaded
fubar
parents:
diff changeset
521 self.args.exe_package,
b938475235e3 Uploaded
fubar
parents:
diff changeset
522 self.args.exe_package_version,
b938475235e3 Uploaded
fubar
parents:
diff changeset
523 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
524 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
525 self.tool.requirements = requirements
b938475235e3 Uploaded
fubar
parents:
diff changeset
526 if self.args.parampass == "0":
b938475235e3 Uploaded
fubar
parents:
diff changeset
527 self.doNoXMLparam()
b938475235e3 Uploaded
fubar
parents:
diff changeset
528 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
529 self.doXMLparam()
b938475235e3 Uploaded
fubar
parents:
diff changeset
530 self.tool.outputs = self.toutputs
b938475235e3 Uploaded
fubar
parents:
diff changeset
531 self.tool.inputs = self.tinputs
b938475235e3 Uploaded
fubar
parents:
diff changeset
532 if self.args.runmode not in ["Executable", "system"]:
b938475235e3 Uploaded
fubar
parents:
diff changeset
533 configfiles = gxtp.Configfiles()
b938475235e3 Uploaded
fubar
parents:
diff changeset
534 configfiles.append(gxtp.Configfile(name="runMe", text=self.script))
b938475235e3 Uploaded
fubar
parents:
diff changeset
535 self.tool.configfiles = configfiles
b938475235e3 Uploaded
fubar
parents:
diff changeset
536 tests = gxtp.Tests()
b938475235e3 Uploaded
fubar
parents:
diff changeset
537 test_a = gxtp.Test()
b938475235e3 Uploaded
fubar
parents:
diff changeset
538 for tp in self.testparam:
b938475235e3 Uploaded
fubar
parents:
diff changeset
539 test_a.append(tp)
b938475235e3 Uploaded
fubar
parents:
diff changeset
540 tests.append(test_a)
b938475235e3 Uploaded
fubar
parents:
diff changeset
541 self.tool.tests = tests
b938475235e3 Uploaded
fubar
parents:
diff changeset
542 self.tool.add_comment(
b938475235e3 Uploaded
fubar
parents:
diff changeset
543 "Created by %s at %s using the Galaxy Tool Factory."
b938475235e3 Uploaded
fubar
parents:
diff changeset
544 % (self.args.user_email, timenow())
b938475235e3 Uploaded
fubar
parents:
diff changeset
545 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
546 self.tool.add_comment("Source in git at: %s" % (toolFactoryURL))
b938475235e3 Uploaded
fubar
parents:
diff changeset
547 self.tool.add_comment(
b938475235e3 Uploaded
fubar
parents:
diff changeset
548 "Cite: Creating re-usable tools from scripts doi: \
b938475235e3 Uploaded
fubar
parents:
diff changeset
549 10.1093/bioinformatics/bts573"
b938475235e3 Uploaded
fubar
parents:
diff changeset
550 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
551 exml = self.tool.export()
b938475235e3 Uploaded
fubar
parents:
diff changeset
552 xf = open('%s.xml' % self.tool_name, "w")
b938475235e3 Uploaded
fubar
parents:
diff changeset
553 xf.write(exml)
b938475235e3 Uploaded
fubar
parents:
diff changeset
554 xf.write("\n")
b938475235e3 Uploaded
fubar
parents:
diff changeset
555 xf.close()
b938475235e3 Uploaded
fubar
parents:
diff changeset
556 # ready for the tarball
b938475235e3 Uploaded
fubar
parents:
diff changeset
557
b938475235e3 Uploaded
fubar
parents:
diff changeset
558 def makeTooltar(self):
b938475235e3 Uploaded
fubar
parents:
diff changeset
559 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
560 a tool is a gz tarball with eg
b938475235e3 Uploaded
fubar
parents:
diff changeset
561 /toolname/tool.xml /toolname/tool.py /toolname/test-data/test1_in.foo ...
b938475235e3 Uploaded
fubar
parents:
diff changeset
562 NOTE names for test inputs and outputs are munged here so must
b938475235e3 Uploaded
fubar
parents:
diff changeset
563 correspond to actual input and output names used on the generated cl
b938475235e3 Uploaded
fubar
parents:
diff changeset
564 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
565 retval = self.run()
b938475235e3 Uploaded
fubar
parents:
diff changeset
566 if retval:
b938475235e3 Uploaded
fubar
parents:
diff changeset
567 sys.stderr.write(
b938475235e3 Uploaded
fubar
parents:
diff changeset
568 "## Run failed. Cannot build yet. Please fix and retry"
b938475235e3 Uploaded
fubar
parents:
diff changeset
569 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
570 sys.exit(1)
b938475235e3 Uploaded
fubar
parents:
diff changeset
571 tdir = "tfout"
b938475235e3 Uploaded
fubar
parents:
diff changeset
572 if not os.path.exists(tdir):
b938475235e3 Uploaded
fubar
parents:
diff changeset
573 os.mkdir(tdir)
b938475235e3 Uploaded
fubar
parents:
diff changeset
574 self.makeXML()
b938475235e3 Uploaded
fubar
parents:
diff changeset
575 testdir = os.path.join(tdir, "test-data")
b938475235e3 Uploaded
fubar
parents:
diff changeset
576 if not os.path.exists(testdir):
b938475235e3 Uploaded
fubar
parents:
diff changeset
577 os.mkdir(testdir) # make tests directory
b938475235e3 Uploaded
fubar
parents:
diff changeset
578 for p in self.infiles:
b938475235e3 Uploaded
fubar
parents:
diff changeset
579 pth = p[IPATHPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
580 dest = os.path.join(testdir, "%s_sample" % p[ICLPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
581 shutil.copyfile(pth, dest)
b938475235e3 Uploaded
fubar
parents:
diff changeset
582 for p in self.outfiles:
b938475235e3 Uploaded
fubar
parents:
diff changeset
583 pth = p[OCLPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
584 if p[OOCLPOS] == "STDOUT" or self.args.parampass == "0":
b938475235e3 Uploaded
fubar
parents:
diff changeset
585 pth = p[ONAMEPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
586 dest = os.path.join(testdir, "%s_sample" % p[ONAMEPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
587 shutil.copyfile(pth, dest)
b938475235e3 Uploaded
fubar
parents:
diff changeset
588 dest = os.path.join(tdir, p[ONAMEPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
589 shutil.copyfile(pth, dest)
b938475235e3 Uploaded
fubar
parents:
diff changeset
590 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
591 pth = p[OCLPOS]
b938475235e3 Uploaded
fubar
parents:
diff changeset
592 dest = os.path.join(testdir, "%s_sample" % p[OCLPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
593 shutil.copyfile(pth, dest)
b938475235e3 Uploaded
fubar
parents:
diff changeset
594 dest = os.path.join(tdir, p[OCLPOS])
b938475235e3 Uploaded
fubar
parents:
diff changeset
595 shutil.copyfile(pth, dest)
b938475235e3 Uploaded
fubar
parents:
diff changeset
596
b938475235e3 Uploaded
fubar
parents:
diff changeset
597 if os.path.exists(self.tlog) and os.stat(self.tlog).st_size > 0:
b938475235e3 Uploaded
fubar
parents:
diff changeset
598 shutil.copyfile(self.tlog, os.path.join(testdir, "test1_log_outfiletxt"))
b938475235e3 Uploaded
fubar
parents:
diff changeset
599 if self.args.runmode not in ["Executable", "system"]:
b938475235e3 Uploaded
fubar
parents:
diff changeset
600 stname = os.path.join(tdir, "%s" % (self.sfile))
b938475235e3 Uploaded
fubar
parents:
diff changeset
601 if not os.path.exists(stname):
b938475235e3 Uploaded
fubar
parents:
diff changeset
602 shutil.copyfile(self.sfile, stname)
b938475235e3 Uploaded
fubar
parents:
diff changeset
603 xreal = '%s.xml' % self.tool_name
b938475235e3 Uploaded
fubar
parents:
diff changeset
604 xout = os.path.join(tdir,xreal)
b938475235e3 Uploaded
fubar
parents:
diff changeset
605 shutil.copyfile(xreal, xout)
b938475235e3 Uploaded
fubar
parents:
diff changeset
606 tarpath = "toolfactory_%s.tgz" % self.tool_name
b938475235e3 Uploaded
fubar
parents:
diff changeset
607 tf = tarfile.open(tarpath, "w:gz")
b938475235e3 Uploaded
fubar
parents:
diff changeset
608 tf.add(name=tdir, arcname=self.tool_name)
b938475235e3 Uploaded
fubar
parents:
diff changeset
609 tf.close()
b938475235e3 Uploaded
fubar
parents:
diff changeset
610 shutil.copyfile(tarpath, self.args.new_tool)
b938475235e3 Uploaded
fubar
parents:
diff changeset
611 shutil.copyfile(xreal,"tool_xml.txt")
b938475235e3 Uploaded
fubar
parents:
diff changeset
612 repdir = "TF_run_report_tempdir"
b938475235e3 Uploaded
fubar
parents:
diff changeset
613 if not os.path.exists(repdir):
b938475235e3 Uploaded
fubar
parents:
diff changeset
614 os.mkdir(repdir)
b938475235e3 Uploaded
fubar
parents:
diff changeset
615 repoutnames = [x[OCLPOS] for x in self.outfiles]
b938475235e3 Uploaded
fubar
parents:
diff changeset
616 with os.scandir('.') as outs:
b938475235e3 Uploaded
fubar
parents:
diff changeset
617 for entry in outs:
b938475235e3 Uploaded
fubar
parents:
diff changeset
618 if entry.name.endswith('.tgz') or not entry.is_file():
b938475235e3 Uploaded
fubar
parents:
diff changeset
619 continue
b938475235e3 Uploaded
fubar
parents:
diff changeset
620 if entry.name in repoutnames:
b938475235e3 Uploaded
fubar
parents:
diff changeset
621 shutil.copyfile(entry.name,os.path.join(repdir,entry.name))
b938475235e3 Uploaded
fubar
parents:
diff changeset
622 elif entry.name == "%s.xml" % self.tool_name:
b938475235e3 Uploaded
fubar
parents:
diff changeset
623 shutil.copyfile(entry.name,os.path.join(repdir,"new_tool_xml"))
b938475235e3 Uploaded
fubar
parents:
diff changeset
624 return retval
b938475235e3 Uploaded
fubar
parents:
diff changeset
625
b938475235e3 Uploaded
fubar
parents:
diff changeset
626 def run(self):
b938475235e3 Uploaded
fubar
parents:
diff changeset
627 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
628 Some devteam tools have this defensive stderr read so I'm keeping with the faith
b938475235e3 Uploaded
fubar
parents:
diff changeset
629 Feel free to update.
b938475235e3 Uploaded
fubar
parents:
diff changeset
630 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
631 s = "run cl=%s" % str(self.cl)
b938475235e3 Uploaded
fubar
parents:
diff changeset
632
b938475235e3 Uploaded
fubar
parents:
diff changeset
633 logging.debug(s)
b938475235e3 Uploaded
fubar
parents:
diff changeset
634 scl = " ".join(self.cl)
b938475235e3 Uploaded
fubar
parents:
diff changeset
635 err = None
b938475235e3 Uploaded
fubar
parents:
diff changeset
636 if self.args.parampass != "0":
b938475235e3 Uploaded
fubar
parents:
diff changeset
637 ste = open(self.elog, "wb")
b938475235e3 Uploaded
fubar
parents:
diff changeset
638 if self.lastclredirect:
b938475235e3 Uploaded
fubar
parents:
diff changeset
639 sto = open(
b938475235e3 Uploaded
fubar
parents:
diff changeset
640 self.lastclredirect[1], "wb"
b938475235e3 Uploaded
fubar
parents:
diff changeset
641 ) # is name of an output file
b938475235e3 Uploaded
fubar
parents:
diff changeset
642 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
643 sto = open(self.tlog, "wb")
b938475235e3 Uploaded
fubar
parents:
diff changeset
644 sto.write(
b938475235e3 Uploaded
fubar
parents:
diff changeset
645 bytes(
b938475235e3 Uploaded
fubar
parents:
diff changeset
646 "## Executing Toolfactory generated command line = %s\n"
b938475235e3 Uploaded
fubar
parents:
diff changeset
647 % scl,
b938475235e3 Uploaded
fubar
parents:
diff changeset
648 "utf8",
b938475235e3 Uploaded
fubar
parents:
diff changeset
649 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
650 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
651 sto.flush()
b938475235e3 Uploaded
fubar
parents:
diff changeset
652 p = subprocess.run(self.cl, shell=False, stdout=sto, stderr=ste)
b938475235e3 Uploaded
fubar
parents:
diff changeset
653 sto.close()
b938475235e3 Uploaded
fubar
parents:
diff changeset
654 ste.close()
b938475235e3 Uploaded
fubar
parents:
diff changeset
655 tmp_stderr = open(self.elog, "rb")
b938475235e3 Uploaded
fubar
parents:
diff changeset
656 err = ""
b938475235e3 Uploaded
fubar
parents:
diff changeset
657 buffsize = 1048576
b938475235e3 Uploaded
fubar
parents:
diff changeset
658 try:
b938475235e3 Uploaded
fubar
parents:
diff changeset
659 while True:
b938475235e3 Uploaded
fubar
parents:
diff changeset
660 err += str(tmp_stderr.read(buffsize))
b938475235e3 Uploaded
fubar
parents:
diff changeset
661 if not err or len(err) % buffsize != 0:
b938475235e3 Uploaded
fubar
parents:
diff changeset
662 break
b938475235e3 Uploaded
fubar
parents:
diff changeset
663 except OverflowError:
b938475235e3 Uploaded
fubar
parents:
diff changeset
664 pass
b938475235e3 Uploaded
fubar
parents:
diff changeset
665 tmp_stderr.close()
b938475235e3 Uploaded
fubar
parents:
diff changeset
666 retval = p.returncode
b938475235e3 Uploaded
fubar
parents:
diff changeset
667 else: # work around special case of simple scripts that take stdin and write to stdout
b938475235e3 Uploaded
fubar
parents:
diff changeset
668 sti = open(self.infiles[0][IPATHPOS], "rb")
b938475235e3 Uploaded
fubar
parents:
diff changeset
669 sto = open(self.outfiles[0][ONAMEPOS], "wb")
b938475235e3 Uploaded
fubar
parents:
diff changeset
670 # must use shell to redirect
b938475235e3 Uploaded
fubar
parents:
diff changeset
671 p = subprocess.run(self.cl, shell=False, stdout=sto, stdin=sti)
b938475235e3 Uploaded
fubar
parents:
diff changeset
672 retval = p.returncode
b938475235e3 Uploaded
fubar
parents:
diff changeset
673 sto.close()
b938475235e3 Uploaded
fubar
parents:
diff changeset
674 sti.close()
b938475235e3 Uploaded
fubar
parents:
diff changeset
675 if os.path.isfile(self.tlog) and os.stat(self.tlog).st_size == 0:
b938475235e3 Uploaded
fubar
parents:
diff changeset
676 os.unlink(self.tlog)
b938475235e3 Uploaded
fubar
parents:
diff changeset
677 if os.path.isfile(self.elog) and os.stat(self.elog).st_size == 0:
b938475235e3 Uploaded
fubar
parents:
diff changeset
678 os.unlink(self.elog)
b938475235e3 Uploaded
fubar
parents:
diff changeset
679 if p.returncode != 0 and err: # problem
b938475235e3 Uploaded
fubar
parents:
diff changeset
680 sys.stderr.write(err)
b938475235e3 Uploaded
fubar
parents:
diff changeset
681 logging.debug("run done")
b938475235e3 Uploaded
fubar
parents:
diff changeset
682 return retval
b938475235e3 Uploaded
fubar
parents:
diff changeset
683
b938475235e3 Uploaded
fubar
parents:
diff changeset
684
b938475235e3 Uploaded
fubar
parents:
diff changeset
685 def main():
b938475235e3 Uploaded
fubar
parents:
diff changeset
686 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
687 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as:
b938475235e3 Uploaded
fubar
parents:
diff changeset
688 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript"
b938475235e3 Uploaded
fubar
parents:
diff changeset
689 </command>
b938475235e3 Uploaded
fubar
parents:
diff changeset
690 """
b938475235e3 Uploaded
fubar
parents:
diff changeset
691 parser = argparse.ArgumentParser()
b938475235e3 Uploaded
fubar
parents:
diff changeset
692 a = parser.add_argument
b938475235e3 Uploaded
fubar
parents:
diff changeset
693 a("--script_path", default="")
b938475235e3 Uploaded
fubar
parents:
diff changeset
694 a("--tool_name", default=None)
b938475235e3 Uploaded
fubar
parents:
diff changeset
695 a("--interpreter_name", default=None)
b938475235e3 Uploaded
fubar
parents:
diff changeset
696 a("--interpreter_version", default=None)
b938475235e3 Uploaded
fubar
parents:
diff changeset
697 a("--exe_package", default=None)
b938475235e3 Uploaded
fubar
parents:
diff changeset
698 a("--exe_package_version", default=None)
b938475235e3 Uploaded
fubar
parents:
diff changeset
699 a("--input_files", default=[], action="append")
b938475235e3 Uploaded
fubar
parents:
diff changeset
700 a("--output_files", default=[], action="append")
b938475235e3 Uploaded
fubar
parents:
diff changeset
701 a("--user_email", default="Unknown")
b938475235e3 Uploaded
fubar
parents:
diff changeset
702 a("--bad_user", default=None)
b938475235e3 Uploaded
fubar
parents:
diff changeset
703 a("--make_Tool", default=None)
b938475235e3 Uploaded
fubar
parents:
diff changeset
704 a("--help_text", default=None)
b938475235e3 Uploaded
fubar
parents:
diff changeset
705 a("--tool_desc", default=None)
b938475235e3 Uploaded
fubar
parents:
diff changeset
706 a("--tool_version", default=None)
b938475235e3 Uploaded
fubar
parents:
diff changeset
707 a("--citations", default=None)
b938475235e3 Uploaded
fubar
parents:
diff changeset
708 a("--additional_parameters", action="append", default=[])
b938475235e3 Uploaded
fubar
parents:
diff changeset
709 a("--edit_additional_parameters", action="store_true", default=False)
b938475235e3 Uploaded
fubar
parents:
diff changeset
710 a("--parampass", default="positional")
b938475235e3 Uploaded
fubar
parents:
diff changeset
711 a("--tfout", default="./tfout")
b938475235e3 Uploaded
fubar
parents:
diff changeset
712 a("--new_tool", default="new_tool")
b938475235e3 Uploaded
fubar
parents:
diff changeset
713 a("--runmode", default=None)
b938475235e3 Uploaded
fubar
parents:
diff changeset
714 args = parser.parse_args()
b938475235e3 Uploaded
fubar
parents:
diff changeset
715 assert not args.bad_user, (
b938475235e3 Uploaded
fubar
parents:
diff changeset
716 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to "admin_users" in the Galaxy configuration file'
b938475235e3 Uploaded
fubar
parents:
diff changeset
717 % (args.bad_user, args.bad_user)
b938475235e3 Uploaded
fubar
parents:
diff changeset
718 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
719 assert (
b938475235e3 Uploaded
fubar
parents:
diff changeset
720 args.tool_name
b938475235e3 Uploaded
fubar
parents:
diff changeset
721 ), "## Tool Factory expects a tool name - eg --tool_name=DESeq"
b938475235e3 Uploaded
fubar
parents:
diff changeset
722 assert (
b938475235e3 Uploaded
fubar
parents:
diff changeset
723 args.interpreter_name or args.exe_package
b938475235e3 Uploaded
fubar
parents:
diff changeset
724 ), "## Tool Factory wrapper expects an interpreter or an executable package"
b938475235e3 Uploaded
fubar
parents:
diff changeset
725 assert args.exe_package or (
b938475235e3 Uploaded
fubar
parents:
diff changeset
726 len(args.script_path) > 0 and os.path.isfile(args.script_path)
b938475235e3 Uploaded
fubar
parents:
diff changeset
727 ), "## Tool Factory wrapper expects a script path - eg --script_path=foo.R if no executable"
b938475235e3 Uploaded
fubar
parents:
diff changeset
728 args.input_files = [
b938475235e3 Uploaded
fubar
parents:
diff changeset
729 x.replace('"', "").replace("'", "") for x in args.input_files
b938475235e3 Uploaded
fubar
parents:
diff changeset
730 ]
b938475235e3 Uploaded
fubar
parents:
diff changeset
731 # remove quotes we need to deal with spaces in CL params
b938475235e3 Uploaded
fubar
parents:
diff changeset
732 for i, x in enumerate(args.additional_parameters):
b938475235e3 Uploaded
fubar
parents:
diff changeset
733 args.additional_parameters[i] = args.additional_parameters[i].replace(
b938475235e3 Uploaded
fubar
parents:
diff changeset
734 '"', ""
b938475235e3 Uploaded
fubar
parents:
diff changeset
735 )
b938475235e3 Uploaded
fubar
parents:
diff changeset
736 r = ScriptRunner(args)
b938475235e3 Uploaded
fubar
parents:
diff changeset
737 if args.make_Tool:
b938475235e3 Uploaded
fubar
parents:
diff changeset
738 retcode = r.makeTooltar()
b938475235e3 Uploaded
fubar
parents:
diff changeset
739 else:
b938475235e3 Uploaded
fubar
parents:
diff changeset
740 retcode = r.run()
b938475235e3 Uploaded
fubar
parents:
diff changeset
741 if retcode:
b938475235e3 Uploaded
fubar
parents:
diff changeset
742 sys.exit(retcode) # indicate failure to job runner
b938475235e3 Uploaded
fubar
parents:
diff changeset
743
b938475235e3 Uploaded
fubar
parents:
diff changeset
744
b938475235e3 Uploaded
fubar
parents:
diff changeset
745 if __name__ == "__main__":
b938475235e3 Uploaded
fubar
parents:
diff changeset
746 main()