-
Notifications
You must be signed in to change notification settings - Fork 32
/
pp_utils.py
79 lines (58 loc) · 2.29 KB
/
pp_utils.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
import time
import tkMessageBox
class StopWatch:
global_enable=False
def __init__(self):
self.enable=False
def on(self):
self.enable=True
def off(self):
self.enable=False
def start(self):
if StopWatch.global_enable and self.enable: self.sstart=time.clock()
def split(self,text):
if StopWatch.global_enable and self.enable:
self.end=time.clock()
print text + " " + str(self.end-self.sstart) + " secs"
self.sstart=time.clock()
def stop(self,text):
if StopWatch.global_enable and self.enable:
self.end=time.clock()
print text + " " + str(self.end-self.sstart) + " secs"
class Monitor:
# 0 - errors only
# 1 - errors and warnings
# 2 - everything
global_enable=0
log_path=""
ofile=None
start_time= time.time()
warnings=0
fatals=0
def __init__(self):
if Monitor.ofile==None:
bufsize=0
Monitor.ofile=open(Monitor.log_path+"/pp_log.log","w",bufsize)
self.enable=False
def on(self):
self.enable=True
def off(self):
self.enable=False
def err(self,caller,text):
print "%.2f" % (time.time()-Monitor.start_time), " ERROR: ",caller.__class__.__name__," ", text
Monitor.ofile.write (" ERROR: " + caller.__class__.__name__ + ": " + text + "\n")
tkMessageBox.showwarning(
caller.__class__.__name__ ,
text
)
def warn(self,caller,text):
if Monitor.global_enable >0 and self.enable:
print "%.2f" % (time.time()-Monitor.start_time), " WARNING: ",caller.__class__.__name__," ", text
Monitor.ofile.write (" WARNING: " + caller.__class__.__name__ + ": " + text + "\n")
def log(self,caller,text):
if Monitor.global_enable >1 and self.enable:
print "%.2f" % (time.time()-Monitor.start_time), " ",caller.__class__.__name__," ", text
Monitor.ofile.write (str(time.time()-Monitor.start_time) + " " + caller.__class__.__name__ +": " + text+"\n")
def finish(self):
Monitor.ofile.close()
pass