-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsr_parse.py
executable file
·98 lines (86 loc) · 1.78 KB
/
fsr_parse.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
#!/usr/bin/python
# 2010 Psyjo
import sys
import re
import operator
import os
import signal
import getopt
vmap = {}
smap = []
oldmap = []
valuePattern = re.compile(".*: *([0-9]+) .*: *([0-9]+) .*")
linePattern = re.compile('^extents')
running = 1
def exitHandler():
global running
print 'Signal 15'
running = 0
signal.signal(15, exitHandler)
def genSmap():
global oldmap
global smap
smap = sorted(sorted(vmap.iteritems(), reverse=True), key=operator.itemgetter(1), reverse=True)
def dspl():
global oldmap
global smap
genSmap()
newmap = map(operator.itemgetter(0), smap)
if oldmap == newmap:
os.system('tput cup 0 0')
else:
os.system('clear')
oldmap = newmap
cnt = 0
for k, v in smap:
cnt += 1
if cnt > 50:
break
print k, '\t', v
def usage():
print 'usage:\n', sys.argv[0], '[-h|--help] [-p|--print] [-s|--skip-summary]'
try:
opts, args = getopt.getopt(sys.argv[1:], "hps", ["print", "help", "skip-summary"])
except getopt.GetoptError, err:
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
help = False
printout = False
summary = True
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-p", "--print"):
printout = True
elif o in ("-s", "--skip-summary"):
summary = False
else:
assert False, "unhandled option"
while running == 1:
line = sys.stdin.readline()
if len(line) == 0:
break
else:
# if printout:
# print line,
if linePattern.search(line):
m = valuePattern.match(line)
value = float(m.group(1) + '.' + m.group(2))
if value in vmap:
vmap[value] += 1
else:
vmap[value] = 1
else:
continue
if printout:
dspl()
if summary:
os.system('clear')
print '=' * 47
print '=' * 20, ' sum ', '=' * 20
print '=' * 47
genSmap()
for k, v in smap:
print k, '\t', v