annotate toolfactory/rgToolFactory2.py @ 123:0566e2ee9789 draft

Uploaded
author fubar
date Fri, 08 Jan 2021 02:04:17 +0000
parents c763ae9237ca
children f267ed4a3026
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1 # replace with shebang for biocontainer
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
2 # see https://github.com/fubar2/toolfactory
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
3 #
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
4 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
5 #
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
6 # all rights reserved
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
7 # Licensed under the LGPL
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
8 # suggestions for improvement and bug fixes welcome at
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
9 # https://github.com/fubar2/toolfactory
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
10 #
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
11 # July 2020: BCC was fun and I feel like rip van winkle after 5 years.
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
12 # Decided to
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
13 # 1. Fix the toolfactory so it works - done for simplest case
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
14 # 2. Fix planemo so the toolfactory function works
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
15 # 3. Rewrite bits using galaxyxml functions where that makes sense - done
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
16
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
17 import argparse
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
18 import copy
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
19 import logging
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
20 import os
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
21 import re
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
22 import shutil
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
23 import subprocess
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
24 import sys
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
25 import tarfile
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
26 import tempfile
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
27 import time
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
28
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
29 from bioblend import ConnectionError
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
30 from bioblend import toolshed
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
31
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
32 import galaxyxml.tool as gxt
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
33 import galaxyxml.tool.parameters as gxtp
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
34
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
35 import lxml
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
36
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
37 import yaml
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
38
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
39 myversion = "V2.1 July 2020"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
40 verbose = True
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
41 debug = True
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
42 toolFactoryURL = "https://github.com/fubar2/toolfactory"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
43 ourdelim = "~~~"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
44
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
45 # --input_files="$intab.input_files~~~$intab.input_CL~~~
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
46 # $intab.input_formats# ~~~$intab.input_label
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
47 # ~~~$intab.input_help"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
48 IPATHPOS = 0
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
49 ICLPOS = 1
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
50 IFMTPOS = 2
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
51 ILABPOS = 3
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
52 IHELPOS = 4
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
53 IOCLPOS = 5
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
54
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
55 # --output_files "$otab.history_name~~~$otab.history_format~~~
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
56 # $otab.history_CL~~~$otab.history_test"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
57 ONAMEPOS = 0
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
58 OFMTPOS = 1
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
59 OCLPOS = 2
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
60 OTESTPOS = 3
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
61 OOCLPOS = 4
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
62
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
63
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
64 # --additional_parameters="$i.param_name~~~$i.param_value~~~
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
65 # $i.param_label~~~$i.param_help~~~$i.param_type
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
66 # ~~~$i.CL~~~i$.param_CLoverride"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
67 ANAMEPOS = 0
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
68 AVALPOS = 1
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
69 ALABPOS = 2
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
70 AHELPPOS = 3
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
71 ATYPEPOS = 4
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
72 ACLPOS = 5
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
73 AOVERPOS = 6
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
74 AOCLPOS = 7
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
75
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
76
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
77 foo = len(lxml.__version__)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
78 # fug you, flake8. Say my name!
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
79 FAKEEXE = "~~~REMOVE~~~ME~~~"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
80 # need this until a PR/version bump to fix galaxyxml prepending the exe even
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
81 # with override.
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
82
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
83
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
84 def timenow():
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
85 """return current time as a string"""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
86 return time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(time.time()))
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
87
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
88
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
89 def quote_non_numeric(s):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
90 """return a prequoted string for non-numerics
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
91 useful for perl and Rscript parameter passing?
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
92 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
93 try:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
94 _ = float(s)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
95 return s
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
96 except ValueError:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
97 return '"%s"' % s
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
98
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
99
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
100 html_escape_table = {
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
101 "&": "&",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
102 ">": ">",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
103 "<": "&lt;",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
104 "#": "&#35;",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
105 "$": "&#36;",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
106 }
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
107 cheetah_escape_table = {"$": "\\$", "#": "\\#"}
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
108
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
109
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
110 def html_escape(text):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
111 """Produce entities within text."""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
112 return "".join([html_escape_table.get(c, c) for c in text])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
113
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
114
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
115 def cheetah_escape(text):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
116 """Produce entities within text."""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
117 return "".join([cheetah_escape_table.get(c, c) for c in text])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
118
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
119
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
120 def parse_citations(citations_text):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
121 """"""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
122 citations = [c for c in citations_text.split("**ENTRY**") if c.strip()]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
123 citation_tuples = []
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
124 for citation in citations:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
125 if citation.startswith("doi"):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
126 citation_tuples.append(("doi", citation[len("doi") :].strip()))
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
127 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
128 citation_tuples.append(("bibtex", citation[len("bibtex") :].strip()))
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
129 return citation_tuples
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
130
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
131
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
132 class ScriptRunner:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
133 """Wrapper for an arbitrary script
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
134 uses galaxyxml
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
135
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
136 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
137
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
138 def __init__(self, args=None):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
139 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
140 prepare command line cl for running the tool here
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
141 and prepare elements needed for galaxyxml tool generation
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
142 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
143 self.ourcwd = os.getcwd()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
144 self.ourenv = copy.deepcopy(os.environ)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
145 self.infiles = [x.split(ourdelim) for x in args.input_files]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
146 self.outfiles = [x.split(ourdelim) for x in args.output_files]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
147 self.addpar = [x.split(ourdelim) for x in args.additional_parameters]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
148 self.args = args
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
149 self.cleanuppar()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
150 self.lastclredirect = None
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
151 self.lastxclredirect = None
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
152 self.cl = []
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
153 self.xmlcl = []
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
154 self.is_positional = self.args.parampass == "positional"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
155 if self.args.sysexe:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
156 self.executeme = self.args.sysexe
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
157 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
158 if self.args.packages:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
159 self.executeme = self.args.packages.split(",")[0].split(":")[0].strip()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
160 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
161 self.executeme = None
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
162 aCL = self.cl.append
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
163 aXCL = self.xmlcl.append
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
164 assert args.parampass in [
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
165 "0",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
166 "argparse",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
167 "positional",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
168 ], 'args.parampass must be "0","positional" or "argparse"'
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
169 self.tool_name = re.sub("[^a-zA-Z0-9_]+", "", args.tool_name)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
170 self.tool_id = self.tool_name
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
171 self.newtool = gxt.Tool(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
172 self.tool_name,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
173 self.tool_id,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
174 self.args.tool_version,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
175 self.args.tool_desc,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
176 FAKEEXE,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
177 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
178 self.newtarpath = "toolfactory_%s.tgz" % self.tool_name
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
179 self.tooloutdir = "./tfout"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
180 self.repdir = "./TF_run_report_tempdir"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
181 self.testdir = os.path.join(self.tooloutdir, "test-data")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
182 if not os.path.exists(self.tooloutdir):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
183 os.mkdir(self.tooloutdir)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
184 if not os.path.exists(self.testdir):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
185 os.mkdir(self.testdir)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
186 if not os.path.exists(self.repdir):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
187 os.mkdir(self.repdir)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
188 self.tinputs = gxtp.Inputs()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
189 self.toutputs = gxtp.Outputs()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
190 self.testparam = []
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
191 if self.args.script_path:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
192 self.prepScript()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
193 if self.args.command_override:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
194 scos = open(self.args.command_override, "r").readlines()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
195 self.command_override = [x.rstrip() for x in scos]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
196 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
197 self.command_override = None
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
198 if self.args.test_override:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
199 stos = open(self.args.test_override, "r").readlines()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
200 self.test_override = [x.rstrip() for x in stos]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
201 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
202 self.test_override = None
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
203 if self.args.cl_prefix: # DIY CL start
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
204 clp = self.args.cl_prefix.split(" ")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
205 for c in clp:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
206 aCL(c)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
207 aXCL(c)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
208 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
209 if self.args.script_path:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
210 aCL(self.executeme)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
211 aCL(self.sfile)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
212 aXCL(self.executeme)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
213 aXCL("$runme")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
214 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
215 aCL(self.executeme)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
216 aXCL(self.executeme)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
217 self.elog = os.path.join(self.repdir, "%s_error_log.txt" % self.tool_name)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
218 self.tlog = os.path.join(self.repdir, "%s_runner_log.txt" % self.tool_name)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
219
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
220 if self.args.parampass == "0":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
221 self.clsimple()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
222 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
223 clsuffix = []
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
224 xclsuffix = []
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
225 for i, p in enumerate(self.infiles):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
226 if p[IOCLPOS].upper() == "STDIN":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
227 appendme = [
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
228 p[ICLPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
229 p[ICLPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
230 p[IPATHPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
231 "< %s" % p[IPATHPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
232 ]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
233 xappendme = [
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
234 p[ICLPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
235 p[ICLPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
236 p[IPATHPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
237 "< $%s" % p[ICLPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
238 ]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
239 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
240 appendme = [p[IOCLPOS], p[ICLPOS], p[IPATHPOS], ""]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
241 xappendme = [p[IOCLPOS], p[ICLPOS], "$%s" % p[ICLPOS], ""]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
242 clsuffix.append(appendme)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
243 xclsuffix.append(xappendme)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
244 for i, p in enumerate(self.outfiles):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
245 if p[OOCLPOS] == "STDOUT":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
246 self.lastclredirect = [">", p[ONAMEPOS]]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
247 self.lastxclredirect = [">", "$%s" % p[OCLPOS]]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
248 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
249 clsuffix.append([p[OCLPOS], p[ONAMEPOS], p[ONAMEPOS], ""])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
250 xclsuffix.append([p[OCLPOS], p[ONAMEPOS], "$%s" % p[ONAMEPOS], ""])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
251 for p in self.addpar:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
252 clsuffix.append([p[AOCLPOS], p[ACLPOS], p[AVALPOS], p[AOVERPOS]])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
253 xclsuffix.append(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
254 [p[AOCLPOS], p[ACLPOS], '"$%s"' % p[ANAMEPOS], p[AOVERPOS]]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
255 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
256 clsuffix.sort()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
257 xclsuffix.sort()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
258 self.xclsuffix = xclsuffix
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
259 self.clsuffix = clsuffix
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
260 if self.args.parampass == "positional":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
261 self.clpositional()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
262 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
263 self.clargparse()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
264
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
265 def prepScript(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
266 rx = open(self.args.script_path, "r").readlines()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
267 rx = [x.rstrip() for x in rx]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
268 rxcheck = [x.strip() for x in rx if x.strip() > ""]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
269 assert len(rxcheck) > 0, "Supplied script is empty. Cannot run"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
270 self.script = "\n".join(rx)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
271 fhandle, self.sfile = tempfile.mkstemp(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
272 prefix=self.tool_name, suffix="_%s" % (self.executeme)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
273 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
274 tscript = open(self.sfile, "w")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
275 tscript.write(self.script)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
276 tscript.close()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
277 self.escapedScript = [cheetah_escape(x) for x in rx]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
278 self.spacedScript = [f" {x}" for x in rx if x.strip() > ""]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
279 art = "%s.%s" % (self.tool_name, self.executeme)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
280 artifact = open(art, "wb")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
281 artifact.write(bytes("\n".join(self.escapedScript), "utf8"))
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
282 artifact.close()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
283
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
284 def cleanuppar(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
285 """ positional parameters are complicated by their numeric ordinal"""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
286 if self.args.parampass == "positional":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
287 for i, p in enumerate(self.infiles):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
288 assert (
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
289 p[ICLPOS].isdigit() or p[ICLPOS].strip().upper() == "STDIN"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
290 ), "Positional parameters must be ordinal integers - got %s for %s" % (
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
291 p[ICLPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
292 p[ILABPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
293 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
294 for i, p in enumerate(self.outfiles):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
295 assert (
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
296 p[OCLPOS].isdigit() or p[OCLPOS].strip().upper() == "STDOUT"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
297 ), "Positional parameters must be ordinal integers - got %s for %s" % (
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
298 p[OCLPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
299 p[ONAMEPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
300 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
301 for i, p in enumerate(self.addpar):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
302 assert p[
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
303 ACLPOS
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
304 ].isdigit(), "Positional parameters must be ordinal integers - got %s for %s" % (
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
305 p[ACLPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
306 p[ANAMEPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
307 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
308 for i, p in enumerate(self.infiles):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
309 infp = copy.copy(p)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
310 icl = infp[ICLPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
311 infp.append(icl)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
312 if (
122
c763ae9237ca Uploaded
fubar
parents: 121
diff changeset
313 infp[ICLPOS].isdigit()
c763ae9237ca Uploaded
fubar
parents: 121
diff changeset
314 or self.args.parampass == "0"
121
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
315 or infp[ICLPOS].strip().upper() == "STDOUT"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
316 ):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
317 scl = "input%d" % (i + 1)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
318 infp[ICLPOS] = scl
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
319 self.infiles[i] = infp
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
320 for i, p in enumerate(self.outfiles):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
321 p.append(p[OCLPOS]) # keep copy
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
322 if (p[OOCLPOS].isdigit() and self.args.parampass != "positional") or p[
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
323 OOCLPOS
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
324 ].strip().upper() == "STDOUT":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
325 scl = p[ONAMEPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
326 p[OCLPOS] = scl
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
327 self.outfiles[i] = p
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
328 for i, p in enumerate(self.addpar):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
329 p.append(p[ACLPOS])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
330 if p[ACLPOS].isdigit():
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
331 scl = "param%s" % p[ACLPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
332 p[ACLPOS] = scl
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
333 self.addpar[i] = p
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
334
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
335 def clsimple(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
336 """no parameters - uses < and > for i/o"""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
337 aCL = self.cl.append
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
338 aXCL = self.xmlcl.append
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
339
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
340 if len(self.infiles) > 0:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
341 aCL("<")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
342 aCL(self.infiles[0][IPATHPOS])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
343 aXCL("<")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
344 aXCL("$%s" % self.infiles[0][ICLPOS])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
345 if len(self.outfiles) > 0:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
346 aCL(">")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
347 aCL(self.outfiles[0][OCLPOS])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
348 aXCL(">")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
349 aXCL("$%s" % self.outfiles[0][ONAMEPOS])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
350
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
351 def clpositional(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
352 # inputs in order then params
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
353 aCL = self.cl.append
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
354 for (o_v, k, v, koverride) in self.clsuffix:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
355 if " " in v:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
356 aCL("%s" % v)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
357 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
358 aCL(v)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
359 aXCL = self.xmlcl.append
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
360 for (o_v, k, v, koverride) in self.xclsuffix:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
361 aXCL(v)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
362 if self.lastxclredirect:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
363 aXCL(self.lastxclredirect[0])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
364 aXCL(self.lastxclredirect[1])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
365
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
366 def clargparse(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
367 """argparse style"""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
368 aCL = self.cl.append
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
369 aXCL = self.xmlcl.append
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
370 # inputs then params in argparse named form
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
371
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
372 for (o_v, k, v, koverride) in self.xclsuffix:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
373 if koverride > "":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
374 k = koverride
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
375 elif len(k.strip()) == 1:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
376 k = "-%s" % k
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
377 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
378 k = "--%s" % k
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
379 aXCL(k)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
380 aXCL(v)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
381 for (o_v, k, v, koverride) in self.clsuffix:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
382 if koverride > "":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
383 k = koverride
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
384 elif len(k.strip()) == 1:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
385 k = "-%s" % k
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
386 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
387 k = "--%s" % k
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
388 aCL(k)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
389 aCL(v)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
390
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
391 def getNdash(self, newname):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
392 if self.is_positional:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
393 ndash = 0
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
394 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
395 ndash = 2
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
396 if len(newname) < 2:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
397 ndash = 1
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
398 return ndash
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
399
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
400 def doXMLparam(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
401 """flake8 made me do this..."""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
402 for p in self.outfiles:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
403 # --output_files "$otab.history_name~~~$otab.history_format~~~$otab.history_CL~~~$otab.history_test"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
404 newname, newfmt, newcl, test, oldcl = p
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
405 test = test.strip()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
406 ndash = self.getNdash(newcl)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
407 aparm = gxtp.OutputData(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
408 name=newname, format=newfmt, num_dashes=ndash, label=newcl
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
409 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
410 aparm.positional = self.is_positional
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
411 if self.is_positional:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
412 if oldcl.upper() == "STDOUT":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
413 aparm.positional = 9999999
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
414 aparm.command_line_override = "> $%s" % newname
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
415 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
416 aparm.positional = int(oldcl)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
417 aparm.command_line_override = "$%s" % newname
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
418 self.toutputs.append(aparm)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
419 ld = None
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
420 if test.strip() > "":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
421 if test.startswith("diff"):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
422 c = "diff"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
423 ld = 0
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
424 if test.split(":")[1].isdigit:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
425 ld = int(test.split(":")[1])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
426 tp = gxtp.TestOutput(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
427 name=newname,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
428 value="%s_sample" % newname,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
429 compare=c,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
430 lines_diff=ld,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
431 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
432 elif test.startswith("sim_size"):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
433 c = "sim_size"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
434 tn = test.split(":")[1].strip()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
435 if tn > "":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
436 if "." in tn:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
437 delta = None
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
438 delta_frac = min(1.0, float(tn))
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
439 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
440 delta = int(tn)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
441 delta_frac = None
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
442 tp = gxtp.TestOutput(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
443 name=newname,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
444 value="%s_sample" % newname,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
445 compare=c,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
446 delta=delta,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
447 delta_frac=delta_frac,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
448 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
449 self.testparam.append(tp)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
450 for p in self.infiles:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
451 newname = p[ICLPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
452 newfmt = p[IFMTPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
453 ndash = self.getNdash(newname)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
454 if not len(p[ILABPOS]) > 0:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
455 alab = p[ICLPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
456 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
457 alab = p[ILABPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
458 aninput = gxtp.DataParam(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
459 newname,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
460 optional=False,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
461 label=alab,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
462 help=p[IHELPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
463 format=newfmt,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
464 multiple=False,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
465 num_dashes=ndash,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
466 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
467 aninput.positional = self.is_positional
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
468 self.tinputs.append(aninput)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
469 tparm = gxtp.TestParam(name=newname, value="%s_sample" % newname)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
470 self.testparam.append(tparm)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
471 for p in self.addpar:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
472 (
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
473 newname,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
474 newval,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
475 newlabel,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
476 newhelp,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
477 newtype,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
478 newcl,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
479 override,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
480 oldcl,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
481 ) = p
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
482 if not len(newlabel) > 0:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
483 newlabel = newname
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
484 ndash = self.getNdash(newname)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
485 if newtype == "text":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
486 aparm = gxtp.TextParam(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
487 newname,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
488 label=newlabel,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
489 help=newhelp,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
490 value=newval,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
491 num_dashes=ndash,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
492 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
493 elif newtype == "integer":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
494 aparm = gxtp.IntegerParam(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
495 newname,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
496 label=newname,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
497 help=newhelp,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
498 value=newval,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
499 num_dashes=ndash,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
500 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
501 elif newtype == "float":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
502 aparm = gxtp.FloatParam(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
503 newname,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
504 label=newname,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
505 help=newhelp,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
506 value=newval,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
507 num_dashes=ndash,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
508 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
509 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
510 raise ValueError(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
511 'Unrecognised parameter type "%s" for\
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
512 additional parameter %s in makeXML'
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
513 % (newtype, newname)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
514 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
515 aparm.positional = self.is_positional
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
516 if self.is_positional:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
517 aparm.positional = int(oldcl)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
518 self.tinputs.append(aparm)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
519 tparm = gxtp.TestParam(newname, value=newval)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
520 self.testparam.append(tparm)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
521
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
522 def doNoXMLparam(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
523 """filter style package - stdin to stdout"""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
524 if len(self.infiles) > 0:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
525 alab = self.infiles[0][ILABPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
526 if len(alab) == 0:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
527 alab = self.infiles[0][ICLPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
528 max1s = (
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
529 "Maximum one input if parampass is 0 but multiple input files supplied - %s"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
530 % str(self.infiles)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
531 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
532 assert len(self.infiles) == 1, max1s
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
533 newname = self.infiles[0][ICLPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
534 aninput = gxtp.DataParam(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
535 newname,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
536 optional=False,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
537 label=alab,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
538 help=self.infiles[0][IHELPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
539 format=self.infiles[0][IFMTPOS],
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
540 multiple=False,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
541 num_dashes=0,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
542 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
543 aninput.command_line_override = "< $%s" % newname
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
544 aninput.positional = self.is_positional
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
545 self.tinputs.append(aninput)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
546 tp = gxtp.TestParam(name=newname, value="%s_sample" % newname)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
547 self.testparam.append(tp)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
548 if len(self.outfiles) > 0:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
549 newname = self.outfiles[0][OCLPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
550 newfmt = self.outfiles[0][OFMTPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
551 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
552 anout.command_line_override = "> $%s" % newname
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
553 anout.positional = self.is_positional
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
554 self.toutputs.append(anout)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
555 tp = gxtp.TestOutput(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
556 name=newname, value="%s_sample" % newname
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
557 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
558 self.testparam.append(tp)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
559
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
560 def makeXML(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
561 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
562 Create a Galaxy xml tool wrapper for the new script
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
563 Uses galaxyhtml
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
564 Hmmm. How to get the command line into correct order...
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
565 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
566 if self.command_override:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
567 self.newtool.command_override = self.command_override # config file
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
568 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
569 self.newtool.command_override = self.xmlcl
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
570 cite = gxtp.Citations()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
571 acite = gxtp.Citation(type="doi", value="10.1093/bioinformatics/bts573")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
572 cite.append(acite)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
573 self.newtool.citations = cite
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
574 safertext = ""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
575 if self.args.help_text:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
576 helptext = open(self.args.help_text, "r").readlines()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
577 safertext = "\n".join([cheetah_escape(x) for x in helptext])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
578 if len(safertext.strip()) == 0:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
579 safertext = (
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
580 "Ask the tool author (%s) to rebuild with help text please\n"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
581 % (self.args.user_email)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
582 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
583 if self.args.script_path:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
584 if len(safertext) > 0:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
585 safertext = safertext + "\n\n------\n" # transition allowed!
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
586 scr = [x for x in self.spacedScript if x.strip() > ""]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
587 scr.insert(0, "\n\nScript::\n")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
588 if len(scr) > 300:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
589 scr = (
122
c763ae9237ca Uploaded
fubar
parents: 121
diff changeset
590 scr[:100]
c763ae9237ca Uploaded
fubar
parents: 121
diff changeset
591 + [" >300 lines - stuff deleted", " ......"]
121
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
592 + scr[-100:]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
593 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
594 scr.append("\n")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
595 safertext = safertext + "\n".join(scr)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
596 self.newtool.help = safertext
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
597 self.newtool.version_command = f'echo "{self.args.tool_version}"'
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
598 requirements = gxtp.Requirements()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
599 if self.args.packages:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
600 for d in self.args.packages.split(","):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
601 ver = ""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
602 d = d.replace("==", ":")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
603 d = d.replace("=", ":")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
604 if ":" in d:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
605 packg, ver = d.split(":")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
606 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
607 packg = d
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
608 requirements.append(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
609 gxtp.Requirement("package", packg.strip(), ver.strip())
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
610 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
611 self.newtool.requirements = requirements
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
612 if self.args.parampass == "0":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
613 self.doNoXMLparam()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
614 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
615 self.doXMLparam()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
616 self.newtool.outputs = self.toutputs
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
617 self.newtool.inputs = self.tinputs
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
618 if self.args.script_path:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
619 configfiles = gxtp.Configfiles()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
620 configfiles.append(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
621 gxtp.Configfile(name="runme", text="\n".join(self.escapedScript))
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
622 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
623 self.newtool.configfiles = configfiles
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
624 tests = gxtp.Tests()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
625 test_a = gxtp.Test()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
626 for tp in self.testparam:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
627 test_a.append(tp)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
628 tests.append(test_a)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
629 self.newtool.tests = tests
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
630 self.newtool.add_comment(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
631 "Created by %s at %s using the Galaxy Tool Factory."
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
632 % (self.args.user_email, timenow())
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
633 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
634 self.newtool.add_comment("Source in git at: %s" % (toolFactoryURL))
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
635 exml0 = self.newtool.export()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
636 exml = exml0.replace(FAKEEXE, "") # temporary work around until PR accepted
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
637 if (
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
638 self.test_override
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
639 ): # cannot do this inside galaxyxml as it expects lxml objects for tests
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
640 part1 = exml.split("<tests>")[0]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
641 part2 = exml.split("</tests>")[1]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
642 fixed = "%s\n%s\n%s" % (part1, self.test_override, part2)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
643 exml = fixed
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
644 # exml = exml.replace('range="1:"', 'range="1000:"')
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
645 xf = open("%s.xml" % self.tool_name, "w")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
646 xf.write(exml)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
647 xf.write("\n")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
648 xf.close()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
649 # ready for the tarball
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
650
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
651 def run(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
652 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
653 generate test outputs by running a command line
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
654 won't work if command or test override in play - planemo is the
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
655 easiest way to generate test outputs for that case so is
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
656 automagically selected
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
657 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
658 scl = " ".join(self.cl)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
659 err = None
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
660 if self.args.parampass != "0":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
661 if os.path.exists(self.elog):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
662 ste = open(self.elog, "a")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
663 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
664 ste = open(self.elog, "w")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
665 if self.lastclredirect:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
666 sto = open(self.lastclredirect[1], "wb") # is name of an output file
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
667 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
668 if os.path.exists(self.tlog):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
669 sto = open(self.tlog, "a")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
670 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
671 sto = open(self.tlog, "w")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
672 sto.write(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
673 "## Executing Toolfactory generated command line = %s\n" % scl
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
674 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
675 sto.flush()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
676 subp = subprocess.run(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
677 self.cl, env=self.ourenv, shell=False, stdout=sto, stderr=ste
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
678 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
679 sto.close()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
680 ste.close()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
681 retval = subp.returncode
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
682 else: # work around special case - stdin and write to stdout
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
683 if len(self.infiles) > 0:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
684 sti = open(self.infiles[0][IPATHPOS], "rb")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
685 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
686 sti = sys.stdin
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
687 if len(self.outfiles) > 0:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
688 sto = open(self.outfiles[0][ONAMEPOS], "wb")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
689 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
690 sto = sys.stdout
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
691 subp = subprocess.run(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
692 self.cl, env=self.ourenv, shell=False, stdout=sto, stdin=sti
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
693 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
694 sto.write("## Executing Toolfactory generated command line = %s\n" % scl)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
695 retval = subp.returncode
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
696 sto.close()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
697 sti.close()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
698 if os.path.isfile(self.tlog) and os.stat(self.tlog).st_size == 0:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
699 os.unlink(self.tlog)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
700 if os.path.isfile(self.elog) and os.stat(self.elog).st_size == 0:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
701 os.unlink(self.elog)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
702 if retval != 0 and err: # problem
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
703 sys.stderr.write(err)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
704 logging.debug("run done")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
705 return retval
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
706
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
707 def shedLoad(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
708 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
709 use bioblend to create new repository
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
710 or update existing
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
711
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
712 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
713 if os.path.exists(self.tlog):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
714 sto = open(self.tlog, "a")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
715 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
716 sto = open(self.tlog, "w")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
717
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
718 ts = toolshed.ToolShedInstance(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
719 url=self.args.toolshed_url,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
720 key=self.args.toolshed_api_key,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
721 verify=False,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
722 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
723 repos = ts.repositories.get_repositories()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
724 rnames = [x.get("name", "?") for x in repos]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
725 rids = [x.get("id", "?") for x in repos]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
726 tfcat = "ToolFactory generated tools"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
727 if self.tool_name not in rnames:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
728 tscat = ts.categories.get_categories()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
729 cnames = [x.get("name", "?").strip() for x in tscat]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
730 cids = [x.get("id", "?") for x in tscat]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
731 catID = None
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
732 if tfcat.strip() in cnames:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
733 ci = cnames.index(tfcat)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
734 catID = cids[ci]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
735 res = ts.repositories.create_repository(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
736 name=self.args.tool_name,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
737 synopsis="Synopsis:%s" % self.args.tool_desc,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
738 description=self.args.tool_desc,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
739 type="unrestricted",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
740 remote_repository_url=self.args.toolshed_url,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
741 homepage_url=None,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
742 category_ids=catID,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
743 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
744 tid = res.get("id", None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
745 sto.write(f"#create_repository {self.args.tool_name} tid={tid} res={res}\n")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
746 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
747 i = rnames.index(self.tool_name)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
748 tid = rids[i]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
749 try:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
750 res = ts.repositories.update_repository(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
751 id=tid, tar_ball_path=self.newtarpath, commit_message=None
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
752 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
753 sto.write(f"#update res id {id} ={res}\n")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
754 except ConnectionError:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
755 sto.write(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
756 "####### Is the toolshed running and the API key correct? Bioblend shed upload failed\n"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
757 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
758 sto.close()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
759
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
760 def eph_galaxy_load(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
761 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
762 use ephemeris to load the new tool from the local toolshed after planemo uploads it
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
763 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
764 if os.path.exists(self.tlog):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
765 tout = open(self.tlog, "a")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
766 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
767 tout = open(self.tlog, "w")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
768 cll = [
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
769 "shed-tools",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
770 "install",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
771 "-g",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
772 self.args.galaxy_url,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
773 "--latest",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
774 "-a",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
775 self.args.galaxy_api_key,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
776 "--name",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
777 self.tool_name,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
778 "--owner",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
779 "fubar",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
780 "--toolshed",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
781 self.args.toolshed_url,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
782 "--section_label",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
783 "ToolFactory",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
784 ]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
785 tout.write("running\n%s\n" % " ".join(cll))
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
786 subp = subprocess.run(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
787 cll,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
788 env=self.ourenv,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
789 cwd=self.ourcwd,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
790 shell=False,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
791 stderr=tout,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
792 stdout=tout,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
793 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
794 tout.write(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
795 "installed %s - got retcode %d\n" % (self.tool_name, subp.returncode)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
796 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
797 tout.close()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
798 return subp.returncode
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
799
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
800 def writeShedyml(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
801 """for planemo"""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
802 yuser = self.args.user_email.split("@")[0]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
803 yfname = os.path.join(self.tooloutdir, ".shed.yml")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
804 yamlf = open(yfname, "w")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
805 odict = {
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
806 "name": self.tool_name,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
807 "owner": yuser,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
808 "type": "unrestricted",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
809 "description": self.args.tool_desc,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
810 "synopsis": self.args.tool_desc,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
811 "category": "TF Generated Tools",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
812 }
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
813 yaml.dump(odict, yamlf, allow_unicode=True)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
814 yamlf.close()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
815
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
816 def makeTool(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
817 """write xmls and input samples into place"""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
818 self.makeXML()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
819 if self.args.script_path:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
820 stname = os.path.join(self.tooloutdir, "%s" % (self.sfile))
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
821 if not os.path.exists(stname):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
822 shutil.copyfile(self.sfile, stname)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
823 xreal = "%s.xml" % self.tool_name
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
824 xout = os.path.join(self.tooloutdir, xreal)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
825 shutil.copyfile(xreal, xout)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
826 for p in self.infiles:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
827 pth = p[IPATHPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
828 dest = os.path.join(self.testdir, "%s_sample" % p[ICLPOS])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
829 shutil.copyfile(pth, dest)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
830
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
831 def makeToolTar(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
832 """move outputs into test-data and prepare the tarball"""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
833 excludeme = "_planemo_test_report.html"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
834
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
835 def exclude_function(tarinfo):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
836 filename = tarinfo.name
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
837 return None if filename.endswith(excludeme) else tarinfo
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
838
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
839 if os.path.exists(self.tlog):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
840 tout = open(self.tlog, "a")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
841 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
842 tout = open(self.tlog, "w")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
843 for p in self.outfiles:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
844 oname = p[ONAMEPOS]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
845 tdest = os.path.join(self.testdir, "%s_sample" % oname)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
846 if not os.path.isfile(tdest):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
847 src = os.path.join(self.testdir, oname)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
848 if os.path.isfile(src):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
849 shutil.copyfile(src, tdest)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
850 dest = os.path.join(self.repdir, "%s.sample" % (oname))
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
851 shutil.copyfile(src, dest)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
852 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
853 tout.write(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
854 "###Output file %s not found in testdir %s. This is normal during the first Planemo run that generates test outputs"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
855 % (tdest, self.testdir)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
856 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
857 tf = tarfile.open(self.newtarpath, "w:gz")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
858 tf.add(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
859 name=self.tooloutdir,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
860 arcname=self.tool_name,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
861 filter=exclude_function,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
862 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
863 tf.close()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
864 shutil.copyfile(self.newtarpath, self.args.new_tool)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
865
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
866 def moveRunOutputs(self):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
867 """need to move planemo or run outputs into toolfactory collection"""
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
868 with os.scandir(self.tooloutdir) as outs:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
869 for entry in outs:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
870 if not entry.is_file():
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
871 continue
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
872 if "." in entry.name:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
873 nayme, ext = os.path.splitext(entry.name)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
874 if ext in [".yml", ".xml", ".json", ".yaml"]:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
875 ext = f"{ext}.txt"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
876 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
877 ext = ".txt"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
878 ofn = "%s%s" % (entry.name.replace(".", "_"), ext)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
879 dest = os.path.join(self.repdir, ofn)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
880 src = os.path.join(self.tooloutdir, entry.name)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
881 shutil.copyfile(src, dest)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
882 with os.scandir(self.testdir) as outs:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
883 for entry in outs:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
884 if (
122
c763ae9237ca Uploaded
fubar
parents: 121
diff changeset
885 (not entry.is_file())
c763ae9237ca Uploaded
fubar
parents: 121
diff changeset
886 or entry.name.endswith("_sample")
121
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
887 or entry.name.endswith("_planemo_test_report.html")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
888 ):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
889 continue
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
890 if "." in entry.name:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
891 nayme, ext = os.path.splitext(entry.name)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
892 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
893 ext = ".txt"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
894 newname = f"{entry.name}{ext}"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
895 dest = os.path.join(self.repdir, newname)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
896 src = os.path.join(self.testdir, entry.name)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
897 shutil.copyfile(src, dest)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
898
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
899 def planemo_test(self, genoutputs=True):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
900 """planemo is a requirement so is available for testing but needs a
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
901 different call if in the biocontainer - see above
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
902 and for generating test outputs if command or test overrides are
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
903 supplied test outputs are sent to repdir for display
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
904 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
905 xreal = "%s.xml" % self.tool_name
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
906 tool_test_path = os.path.join(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
907 self.repdir, f"{self.tool_name}_planemo_test_report.html"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
908 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
909 if os.path.exists(self.tlog):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
910 tout = open(self.tlog, "a")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
911 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
912 tout = open(self.tlog, "w")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
913 if genoutputs:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
914 dummy, tfile = tempfile.mkstemp()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
915 cll = [
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
916 "planemo",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
917 "test",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
918 "--test_data",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
919 os.path.abspath(self.testdir),
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
920 "--test_output",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
921 os.path.abspath(tool_test_path),
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
922 "--skip_venv",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
923 "--galaxy_root",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
924 self.args.galaxy_root,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
925 "--update_test_data",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
926 os.path.abspath(xreal),
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
927 ]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
928 p = subprocess.run(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
929 cll,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
930 env=self.ourenv,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
931 shell=False,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
932 cwd=self.tooloutdir,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
933 stderr=dummy,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
934 stdout=dummy,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
935 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
936
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
937 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
938 cll = [
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
939 "planemo",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
940 "test",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
941 "--test_data",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
942 os.path.abspath(self.testdir),
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
943 "--test_output",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
944 os.path.abspath(tool_test_path),
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
945 "--skip_venv",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
946 "--galaxy_root",
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
947 self.args.galaxy_root,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
948 os.path.abspath(xreal),
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
949 ]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
950 p = subprocess.run(
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
951 cll,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
952 shell=False,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
953 env=self.ourenv,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
954 cwd=self.tooloutdir,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
955 stderr=tout,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
956 stdout=tout,
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
957 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
958 tout.close()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
959 return p.returncode
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
960
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
961
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
962 def main():
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
963 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
964 This is a Galaxy wrapper.
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
965 It expects to be called by a special purpose tool.xml
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
966
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
967 """
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
968 parser = argparse.ArgumentParser()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
969 a = parser.add_argument
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
970 a("--script_path", default=None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
971 a("--history_test", default=None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
972 a("--cl_prefix", default=None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
973 a("--sysexe", default=None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
974 a("--packages", default=None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
975 a("--tool_name", default="newtool")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
976 a("--tool_dir", default=None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
977 a("--input_files", default=[], action="append")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
978 a("--output_files", default=[], action="append")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
979 a("--user_email", default="Unknown")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
980 a("--bad_user", default=None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
981 a("--make_Tool", default="runonly")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
982 a("--help_text", default=None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
983 a("--tool_desc", default=None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
984 a("--tool_version", default=None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
985 a("--citations", default=None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
986 a("--command_override", default=None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
987 a("--test_override", default=None)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
988 a("--additional_parameters", action="append", default=[])
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
989 a("--edit_additional_parameters", action="store_true", default=False)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
990 a("--parampass", default="positional")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
991 a("--tfout", default="./tfout")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
992 a("--new_tool", default="new_tool")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
993 a("--galaxy_url", default="http://localhost:8080")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
994 a("--toolshed_url", default="http://localhost:9009")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
995 # make sure this is identical to tool_sheds_conf.xml
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
996 # localhost != 127.0.0.1 so validation fails
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
997 a("--toolshed_api_key", default="fakekey")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
998 a("--galaxy_api_key", default="fakekey")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
999 a("--galaxy_root", default="/galaxy-central")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1000 a("--galaxy_venv", default="/galaxy_venv")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1001 args = parser.parse_args()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1002 assert not args.bad_user, (
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1003 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy \
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1004 admin adds %s to "admin_users" in the galaxy.yml Galaxy configuration file'
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1005 % (args.bad_user, args.bad_user)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1006 )
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1007 assert args.tool_name, "## Tool Factory expects a tool name - eg --tool_name=DESeq"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1008 assert (
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1009 args.sysexe or args.packages
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1010 ), "## Tool Factory wrapper expects an interpreter \
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1011 or an executable package in --sysexe or --packages"
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1012 args.input_files = [x.replace('"', "").replace("'", "") for x in args.input_files]
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1013 # remove quotes we need to deal with spaces in CL params
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1014 for i, x in enumerate(args.additional_parameters):
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1015 args.additional_parameters[i] = args.additional_parameters[i].replace('"', "")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1016 r = ScriptRunner(args)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1017 r.writeShedyml()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1018 r.makeTool()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1019 if args.make_Tool == "generate":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1020 retcode = r.run()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1021 r.moveRunOutputs()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1022 r.makeToolTar()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1023 else:
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1024 retcode = r.planemo_test(genoutputs=True) # this fails :( - see PR
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1025 r.moveRunOutputs()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1026 r.makeToolTar()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1027 retcode = r.planemo_test(genoutputs=False)
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1028 r.moveRunOutputs()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1029 r.makeToolTar()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1030 print(f"second planemo_test returned {retcode}")
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1031 if args.make_Tool == "gentestinstall":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1032 r.shedLoad()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1033 r.eph_galaxy_load()
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1034
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1035
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1036 if __name__ == "__main__":
2050b2475ae5 Uploaded
fubar
parents:
diff changeset
1037 main()