-
Notifications
You must be signed in to change notification settings - Fork 3
/
ErrorHandling.py
40 lines (26 loc) · 1018 Bytes
/
ErrorHandling.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
import json, sys
from pprint import pprint
class ErrorHandling:
def __init__( self ):
self.err = 5
def output( self, error_message ):
out = {
"error": error_message,
"output": "",
"status": "ERROR"
}
err = "ERROR: " + error_message
ret = json.dump( err, sys.stdout )
return ret
def check_file( self, filename ):
from os.path import exists
import os
file_exists = exists( filename )
have_permission = os.access( filename, os.R_OK)
if not file_exists:
error_message = "The input file: " + filename + " does not exist."
return self.output( error_message )
if not have_permission:
error_message = "You do not have permission to read the input file: " + filename + "."
return self.output( error_message )
return True