annotate toolfactory/rgToolFactory2.py @ 132:65b5e9acf98a draft

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