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