-
Notifications
You must be signed in to change notification settings - Fork 35
/
kepmsg.py
executable file
·92 lines (62 loc) · 2.02 KB
/
kepmsg.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
#!/usr/bin/env python
import sys, time, string
# -----------------------------------------------------------
# write message to log file and shell
def log(file,message,verbose):
if (verbose):
# print to shell
print(message)
# print to log file
if (file):
output = open(file,'a')
output.write(message+'\n')
output.close()
# -----------------------------------------------------------
# write error message to log file and shell
def err(file,message,verbose):
if verbose:
log(file,message,verbose)
else:
pass
return 1
# -----------------------------------------------------------
# write warning message to log file and shell
def warn(file,message):
log(file,message,True)
return 0
# -----------------------------------------------------------
# write error message and time to shell and exit
def abort(message,file,verbose):
clock('Abort time is: ',file,verbose)
if verbose:
log(file,message,True)
else:
print(message)
sys.exit(2)
# -----------------------------------------------------------
# write error message to shell and exit
def exit(message):
sys.exit(message)
# -----------------------------------------------------------
# write time to log file and shell
def clock(text,file,verbose):
if (verbose):
message = text + ': ' + time.asctime(time.localtime())
log(file,message,verbose)
# -----------------------------------------------------------
# write message to log file
def file(file,message,verbose):
if (file and verbose):
output = open(file,'a')
output.write(message+'\n')
output.close()
# -----------------------------------------------------------
# test the logfile name is good
def test(file):
newlog = string.join(file.split(),"")
if (len(newlog) == 0): newlog = 'kepler.log'
if (newlog != file):
file = newlog
message = 'WARNING: logfile renamed to '+file+'\n\n'
log(False,message,True)
return file