-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.py
123 lines (99 loc) · 4.2 KB
/
error.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# ESA (C) 2000-2021
#
# This file is part of ESA's XMM-Newton Scientific Analysis System (SAS).
#
# SAS is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SAS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SAS. If not, see <http://www.gnu.org/licenses/>.
#
# error.py
#
"""error.py
The class Error is an interface to the SAS task saserrstr
Instances of class Error, can have the following parameters:
client : The task that produces the error
msgLayer : The task layer where the error is originated.
See below for the keys in dict msgLayer.
msgLevel : The importance level of the message. See below for the keys in dict msgLevel.
code : The code of the message: warning, error, fatal.
msg : The error message itself.
outMessage : The output message.
Below several possible use cases of class Error for different arguments:
Error( client=name, msgLayer='AppMsg', msgLevel='SilentMsg', msg='Message from the SAS (silent)' ).message()
Error( client=name, msgLayer='AppMsg', msgLevel='SparseMsg', msg='Message from the SAS (sparse)' ).message()
Error( client=name, msgLayer='AppMsg', msgLevel='VerboseMsg', msg='Message from the SAS (verbose)' ).message()
Error( client=name, msgLayer='AppMsg', msgLevel='NoisyMsg', msg='Message from the SAS (noisy)' ).message()
print('-------------------------------------------------------------')
Error( client=name, code='warningCode', msg='Warning message' ).warning()
Error( client=name, code='errorCode', msg='Error message' ).error()
Error( client=name, code='fatalCode', msg='Fatal message' ).fatal()
"""
# Standard library imports
import sys, subprocess
# Third party imports
# Local application imports
class Error:
"""Error Class definitions"""
msgLayerValues = {
'UIMsg' : '1',
'MetaMsg' : '2',
'AppMsg' : '3',
'AppLibMsg' : '4',
'LibMsg' : '5',
'CoreMsg' : '6',
'KernelMsg' : '7',
}
msgLevelValues = {
'SilentMsg' : '0',
'SparseMsg' : '1',
'VerboseMsg' : '2',
'NoisyMsg' : '3',
}
def __init__(self, client=None, msgLayer=None, msgLevel=None, code=None, msg=None, outMessage=None):
self.client = client
if msgLayer:
self.msgLayer = self.msgLayerValues[msgLayer]
if msgLevel:
self.msgLevel = self.msgLevelValues[msgLevel]
self.code = code
self.msg = msg
self.outMessage = outMessage
def message(self):
opt = '-m'
outMessage = ['saserrstr' , opt , self.client, self.msgLayer , self.msgLevel , self.msg ]
# Spawn 'outMessage' command to the shell through 'saserrstr'
returncode = subprocess.call(outMessage)
if(returncode):
self.code = "InternalError"
self.msg = "SAS::error::warning failed"
self.fatal()
def warning(self):
opt = '-w'
outMessage = ['saserrstr', opt, self.client, self.code, self.msg ]
# Spawn 'outMessage' command to the shell through 'saserrstr'
returncode = subprocess.call(outMessage)
if(returncode):
self.code = "InternalError"
self.msg = "SAS::error::warning failed"
self.fatal()
def error(self):
opt = '-e'
outMessage = ['saserrstr', opt, self.client, self.code, self.msg ]
# Spawn 'outMessage' command to the shell through 'saserrstr'
returncode = subprocess.call(outMessage)
sys.exit(1)
def fatal(self):
opt = '-f'
outMessage = ['saserrstr', opt, self.client, self.code, self.msg ]
# Spawn 'outMessage' command to the shell through 'saserrstr'
returncode = subprocess.call(outMessage)
sys.exit(1)