-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcounter.py
More file actions
executable file
·79 lines (59 loc) · 1.38 KB
/
counter.py
File metadata and controls
executable file
·79 lines (59 loc) · 1.38 KB
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
#!/usr/bin/python
# author: lilong'en(lilongen@163.com)
#
import os
import cgi
import cPickle
class CcvTimes:
_FILE_NAME = ".dts/counter"
_DEFAULT_TIMES = {
"GET_OVERALL" : 0,
"GENERATE" : 0,
"log" : 0,
"diff" : 0,
"file" : 0
}
def __init__(self, type, mode):
self.type = type
self.mode = mode
def increase(self):
ret = -1
rFile = None
wFile = None
try:
times = self._DEFAULT_TIMES
if os.path.exists(self._FILE_NAME):
rFile = open(self._FILE_NAME, "r")
times = cPickle.load(rFile)
wFile = open(self._FILE_NAME, 'w')
times[self.type] = times[self.type] + 1
if self.type == "GENERATE":
times[self.mode] = times[self.mode] + 1
cPickle.dump(times, wFile)
ret = times[self.type]
except Exception:
if not rFile is None:
rFile.close()
if not wFile is None:
wFile.close()
ret = "ERROR_IO_FILE_OPERATE"
return ret
#class end
def main():
print "Content-type: application/json\n\n"
form = cgi.FieldStorage()
ret = "INLEGAL_INVOKE"
if not (form.has_key("type") and form.has_key("mode")):
print "{ret: %s}" % (ret)
return
type = form["type"].value
mode = form["mode"].value
#type = "GET_OVERALL"
#mode = ""
if type == "GET_OVERALL" or type == "GENERATE":
ccvTime = CcvTimes(type, mode)
ret = ccvTime.increase()
else:
ret = "ILLEGAL_COMMNAD"
print "{ret: %s}" % (ret)
main()