annotate toolfactory/ToolFactory.py @ 0:f288fab71d8b draft default tip

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