-
Notifications
You must be signed in to change notification settings - Fork 0
/
groerrors.py
60 lines (49 loc) · 2.03 KB
/
groerrors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import logging
logger_GROerror = logging.getLogger('pymemdyn.groerrors')
class GromacsError(BaseException):
pass
class IOGromacsError(GromacsError):
"""
Exception raised with "File input/output error" message
"""
def __init__(self, command, explain):
self.command = command
self.explain = explain
def __str__(self):
return "%s failed with '%s'" % (self.command, self.explain)
class GromacsMessages(object):
"""
Load an error message and split it along as many properties as
possible
"""
# Map the messages with the errors
e = {"File input/output error": IOGromacsError,
"Can not open file": IOGromacsError,
# FIXME: Clearly the following is not IOError
"srun: error: Unable to create job step": IOGromacsError,
"Fatal error:": IOGromacsError,
}
def __init__(self, gro_err="", command="", *args, **kwargs):
"""
Pass the command and the output of that command in "command" and
"gro_err" kwargs. The check for "error" property
"""
self.logger_groerrors = logging.getLogger('pymemdyn.groerrors.GromacsMessages')
self.error = False
self.command = command
self.gro_err = gro_err.decode('utf-8').split("\n")
self.check()
def check(self):
"""
Check if the GROMACS error message has any of the known error
messages. Set the self.error to the value of the error
"""
for line in self.gro_err:
for error in self.e.keys():
if line.startswith(error):
if error == "Fatal error:":
self.logger_groerrors.error("\n\nGROMACS FATAL ERROR:\n")
j = self.gro_err.index('of the License, or (at your option) any later version.')
self.logger_groerrors.error('\n'.join(self.gro_err[j+1:]))
self.logger_groerrors.error("\n\n GROMACS FATAL ERROR\n")
raise self.e[error](self.command, error)