Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/galaxy/tool_util/parser/stdio.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 class StdioErrorLevel: | |
2 """ | |
3 These determine stdio-based error levels from matching on regular expressions | |
4 and exit codes. They are meant to be used comparatively, such as showing | |
5 that warning < fatal. This is really meant to just be an enum. | |
6 """ | |
7 NO_ERROR = 0 | |
8 LOG = 1 | |
9 QC = 1.1 | |
10 WARNING = 2 | |
11 FATAL = 3 | |
12 FATAL_OOM = 4 | |
13 MAX = 4 | |
14 descs = { | |
15 NO_ERROR: 'No error', | |
16 LOG: 'Log', | |
17 QC: 'QC', | |
18 WARNING: 'Warning', | |
19 FATAL: 'Fatal error', | |
20 FATAL_OOM: 'Out of memory error', | |
21 } | |
22 | |
23 @staticmethod | |
24 def desc(error_level): | |
25 err_msg = "Unknown error" | |
26 if error_level > 0 and error_level <= StdioErrorLevel.MAX: | |
27 err_msg = StdioErrorLevel.descs[error_level] | |
28 return err_msg | |
29 | |
30 | |
31 class ToolStdioExitCode: | |
32 """ | |
33 This is a container for the <stdio> element's <exit_code> subelement. | |
34 The exit_code element has a range of exit codes and the error level. | |
35 """ | |
36 | |
37 def __init__(self, as_dict=None): | |
38 as_dict = as_dict or {} | |
39 self.range_start = as_dict.get("range_start", float("-inf")) | |
40 self.range_end = as_dict.get("range_end", float("inf")) | |
41 self.error_level = as_dict.get("error_level", StdioErrorLevel.FATAL) | |
42 self.desc = as_dict.get("desc", "") | |
43 | |
44 def to_dict(self): | |
45 return { | |
46 "class": "ToolStdioExitCode", | |
47 "range_start": self.range_start, | |
48 "range_end": self.range_end, | |
49 "error_level": self.error_level, | |
50 "desc": self.desc, | |
51 } | |
52 | |
53 | |
54 class ToolStdioRegex: | |
55 """ | |
56 This is a container for the <stdio> element's regex subelement. | |
57 The regex subelement has a "match" attribute, a "sources" | |
58 attribute that contains "output" and/or "error", and a "level" | |
59 attribute that contains "warning" or "fatal". | |
60 """ | |
61 | |
62 def __init__(self, as_dict=None): | |
63 as_dict = as_dict or {} | |
64 self.match = as_dict.get("match", "") | |
65 self.stdout_match = as_dict.get("stdout_match", False) | |
66 self.stderr_match = as_dict.get("stderr_match", False) | |
67 self.error_level = as_dict.get("error_level", StdioErrorLevel.FATAL) | |
68 self.desc = as_dict.get("desc", "") | |
69 | |
70 def to_dict(self): | |
71 return { | |
72 "class": "ToolStdioRegex", | |
73 "match": self.match, | |
74 "stdout_match": self.stdout_match, | |
75 "stderr_match": self.stderr_match, | |
76 "error_level": self.error_level, | |
77 "desc": self.desc, | |
78 } | |
79 | |
80 | |
81 def error_on_exit_code(out_of_memory_exit_code=None): | |
82 exit_codes = [] | |
83 | |
84 if out_of_memory_exit_code: | |
85 exit_code_oom = ToolStdioExitCode() | |
86 exit_code_oom.range_start = int(out_of_memory_exit_code) | |
87 exit_code_oom.range_end = int(out_of_memory_exit_code) | |
88 _set_oom(exit_code_oom) | |
89 exit_codes.append(exit_code_oom) | |
90 | |
91 exit_code_lower = ToolStdioExitCode() | |
92 exit_code_lower.range_start = float("-inf") | |
93 exit_code_lower.range_end = -1 | |
94 _set_fatal(exit_code_lower) | |
95 exit_codes.append(exit_code_lower) | |
96 exit_code_high = ToolStdioExitCode() | |
97 exit_code_high.range_start = 1 | |
98 exit_code_high.range_end = float("inf") | |
99 _set_fatal(exit_code_high) | |
100 exit_codes.append(exit_code_high) | |
101 return exit_codes, [] | |
102 | |
103 | |
104 def aggressive_error_checks(): | |
105 exit_codes, _ = error_on_exit_code() | |
106 # these regexes are processed as case insensitive by default | |
107 regexes = [ | |
108 _oom_regex("MemoryError"), | |
109 _oom_regex("std::bad_alloc"), | |
110 _oom_regex("java.lang.OutOfMemoryError"), | |
111 _oom_regex("Out of memory"), | |
112 _error_regex("exception:"), | |
113 _error_regex("error:") | |
114 ] | |
115 return exit_codes, regexes | |
116 | |
117 | |
118 def _oom_regex(match): | |
119 regex = ToolStdioRegex() | |
120 _set_oom(regex) | |
121 regex.match = match | |
122 regex.stdout_match = True | |
123 regex.stderr_match = True | |
124 return regex | |
125 | |
126 | |
127 def _error_regex(match): | |
128 regex = ToolStdioRegex() | |
129 _set_fatal(regex) | |
130 regex.match = match | |
131 regex.stdout_match = True | |
132 regex.stderr_match = True | |
133 return regex | |
134 | |
135 | |
136 def _set_oom(obj): | |
137 obj.error_level = StdioErrorLevel.FATAL_OOM | |
138 | |
139 | |
140 def _set_fatal(obj): | |
141 obj.error_level = StdioErrorLevel.FATAL |