annotate toolfactory/rgToolFactory2.py @ 39:2cd6555baf44 draft

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