-
Notifications
You must be signed in to change notification settings - Fork 1
/
Spec1992Data.py
126 lines (95 loc) · 3.49 KB
/
Spec1992Data.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from SpecDataBase import *
import SpecDataElem
import Table
from ordereddict import OrderedDict
import re
import urllib
import BeautifulSoup
import utils
import pdb
class Spec1992Data(SpecDataBase):
"A class that parses and holds spec1992 data"
def __init__(self, soup, elem=SpecDataElem):
self.__hdrMap = {'By:' : 'test_sponsor',
'Model Number' : 'hw_model',
'Number of CPUs': 'hw_nchips'
}
SpecDataBase.__init__(self, soup, elem=elem)
def htmlTables(self, soup):
tabs = [soup.h2]
return tabs
def parseTable(self, tab):
table = Table.Table(str(tab.text), self.getElem()().attrs())
line = tab.findNext("pre").findNext("a")
linecnt = 0
while line:
saveData = self.getElem()()
error = False
link = str(line['href'])
print "found link=" + link
html = urllib.urlopen(link).read()
soup = BeautifulSoup.BeautifulSoup(html)
saveData.update("link", link)
error = self.__parseDetails__(saveData, soup)
linecnt += 1
if error:
print "Warning: skipping line due to error"
else:
table.addEntry(saveData)
line = line.findNext("a")
#if linecnt >= 5:
# break
return table
def __parseDetails__(self, saveData, soup):
error = False
perf = soup.pre.findNext("pre")
tab = re.split("\n", str(perf.text))
# remove the first 4 lines (header garbage)
tab.pop(0)
tab.pop(0)
tab.pop(0)
tab.pop(0)
# write test results
for test in tab:
results = test.split()
saveData.update(results[0], results[4])
# save summary results
summary = re.split(":", str(perf.findNext("dd").text))
if len(summary) > 1:
saveData.update(summary[0].strip(), summary[1].strip())
summary = re.split(":", str(perf.findNext("dd").findNext("dd").text))
if len(summary) > 1:
saveData.update(summary[0].strip(), summary[1].strip())
info = perf.findNext("pre").findNext("pre").dd
#pdb.set_trace()
#write dd attributes
while info:
attrs = re.split(":", str(info.text))
if len(attrs) > 1:
attr = attrs[0].strip()
val = attrs[1].strip()
if info.dd:
attrNext = re.split(":", str(info.dd.text))[0]
try:
val = re.sub(attrNext, "", val)
except:
print "skipping ", attrNext
if not attr in saveData.tests():
#print "saving ", attr
saveData.update(attr, val)
info = info.dd
# write dt attributes
info = perf.findNext("pre").findNext("pre").dt
while info:
attrs = re.split(":", str(info.text))
if len(attrs) > 1:
attr = attrs[0].strip()
val = attrs[1].strip()
if info.dt:
attrNext = re.split(":", str(info.dt.text))[0]
val = re.sub(attrNext, "", val)
if not attr in saveData.tests():
#print "saving ", attr
saveData.update(attr, val)
info = info.dt
return error