annotate toolfactory/rgToolFactory2.py @ 0:fc50a3f507ab draft

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