Skip to content

Commit 8207026

Browse files
committed
New linter for stdio tags.
1 parent d35a9df commit 8207026

File tree

1 file changed

+56
-0
lines changed
  • planemo_ext/galaxy/tools/linters

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
3+
def lint_stdio(tool_xml, lint_ctx):
4+
stdios = tool_xml.findall("./stdio")
5+
if not stdios:
6+
lint_ctx.info("No stdio definition found, tool will determines error from stderr.")
7+
return
8+
9+
if len(stdios) > 1:
10+
lint_ctx.error("More than one stdio tag found, behavior undefined.")
11+
return
12+
13+
stdio = stdios[0]
14+
for child in list(stdio):
15+
if child.tag == "regex":
16+
_lint_regex(child, lint_ctx)
17+
elif child.tag == "exit_code":
18+
_lint_exit_code(child, lint_ctx)
19+
else:
20+
message = "Unknown stdio child tag discovered [%s]. "
21+
message += "Valid options are exit_code and regex."
22+
lint_ctx.warn(message % child.tag)
23+
24+
25+
def _lint_exit_code(child, lint_ctx):
26+
for key, value in child.attrib.iteritems():
27+
if key == "range":
28+
# TODO: validate
29+
pass
30+
elif key == "level":
31+
_lint_level(value, lint_ctx)
32+
elif key == "description":
33+
pass
34+
else:
35+
lint_ctx.warn("Unknown attribute [%s] encountered on exit_code tag." % key)
36+
37+
38+
def _lint_regex(child, lint_ctx):
39+
for key, value in child.attrib.iteritems():
40+
if key == "source":
41+
if value not in ["stderr", "stdout", "both"]:
42+
lint_ctx.error("Unknown error code level encountered [%s]" % value)
43+
elif key == "level":
44+
_lint_level(value, lint_ctx)
45+
elif key == "match":
46+
# TODO: validate
47+
pass
48+
elif key == "description":
49+
pass
50+
else:
51+
lint_ctx.warn("Unknown attribute [%s] encountered on regex tag." % key)
52+
53+
54+
def _lint_level(level_value, lint_ctx):
55+
if level_value not in ["warning", "fatal", "log"]:
56+
lint_ctx.error("Unknown error code level encountered [%s]" % level_value)

0 commit comments

Comments
 (0)