annotate toolfactory/ToolFactory.py @ 4:2a46da701dde draft

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