2 # -*- coding: utf-8 -*-
9 def __init__(self, dim, value):
13 return str(self.value)
15 return repr(self.value)
17 return self.dim.htmlLabel(self.value)
19 class DimValues(list):
20 def replace(self, val):
21 for i in xrange(len(self)):
22 if self[i].dim == val.dim:
25 class Dimension(dict):
26 def __init__(self, atype, name=None):
39 def addValue(self, *values):
42 self[value] = DimValue(self, value)
43 def htmlLabel(self, v):
50 class DimensionKern(Dimension):
52 Dimension.__init__(self, 'gwkern', 'GW kernel')
53 def htmlLabel(self, v):
57 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
65 class DimensionHostKern(Dimension):
67 Dimension.__init__(self, 'hostkern', 'Host kernel')
68 def htmlLabel(self, v):
69 if v.find("host-") == 0:
71 # TODO: remove host- prefix
75 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
83 class DimensionTest(Dimension):
85 Dimension.__init__(self, 'test', 'Test')
86 def htmlLabel(self, v):
87 return v+"<br><a href='%s.sh.html'>source</a>"%(urllib.quote(v))
89 class DimensionTraffic(Dimension):
91 Dimension.__init__(self, 'traf', 'Traffic')
92 def htmlLabel(self, v):
97 def isOnPath(cls, path):
98 f = os.path.join(path, '.results')
99 return os.path.isfile(f)
100 def __init__(self, path):
102 def printThumbLink(self, file):
103 thumb = self.path+'/thumb'
104 for img in dircache.listdir(thumb):
105 print >>file, "<a href='%s/%s'><img src='%s/thumb/%s'></a>" % \
106 (urllib.quote(self.path), img, urllib.quote(self.path), img)
108 def iterDimValues(dimensions):
109 idx = [0 for i in xrange(len(dimensions))]
113 for i in xrange(len(dimensions)):
114 values.append(dimensions[i].values()[idx[i]])
117 for i in xrange(len(dimensions)):
119 if idx[i] < len(dimensions[i]):
125 """Represents all tests organized along several dimensions"""
126 def __init__(self, rootpath, *dimensions):
128 self.dimensions = dimensions
130 self.populate(rootpath)
131 def getTest(self, key):
133 for d in self.dimensions:
136 realkey.append(i.value)
137 if len(realkey) != len(self.dimensions):
138 raise KeyError("The coordinates in key do not match dimensions")
139 return self[tuple(realkey)]
141 def addTest(self, test, coordinates):
142 if len(coordinates) != len(self.dimensions):
143 raise KeyError("The number coordinates do not match the number of dimensions: " + str(coordinates))
144 self[tuple(coordinates)] = test
145 for i in xrange(len(coordinates)):
146 self.dimensions[i].addValue(coordinates[i])
148 def populate(self, rootpath):
149 for root, dirs, files in os.walk(rootpath):
150 if (root.find(rootpath) == 0):
151 coordinates = root[len(rootpath):]
153 coordinates = rootpath
154 if Test.isOnPath(root):
155 self.addTest(Test(root), coordinates.split("/"))
156 def iterDimensionPairs(self):
157 for i in xrange(len(self.dimensions)):
158 for j in xrange(i+1, len(self.dimensions)):
159 yield (self.dimensions[i], self.dimensions[j])
160 yield (self.dimensions[j], self.dimensions[i])
161 def iterRemainingDimensions(self, dimensionPair):
162 for d in self.dimensions:
163 if d not in dimensionPair:
165 def generateHtml(self):
166 for pair in self.iterDimensionPairs():
167 remDims = [d for d in self.iterRemainingDimensions(pair)]
168 for vals in iterDimValues(remDims):
169 page = Page(pair, remDims, vals, self)
172 os.remove("index.html")
174 os.symlink(page.getName(), "index.html")
176 #os.system("source-highlight -d --output-dir=. ../*.sh")
179 def __init__(self, dimPair, dimOther, valsOther, tests):
180 self.dimy, self.dimx = dimPair
181 self.dimOther = dimOther
182 self.valsOther = valsOther
184 def getName(self, dimy=None, dimx=None, valsOther=None):
185 return "%s-vs-%s-for-%s.html"%(dimx or self.dimy.type,
186 dimy or self.dimx.type,
187 "-".join([v.value for v in valsOther or self.valsOther]))
189 html = open(self.getName(), "w")
190 title = "CAN gateway timing analysis"
191 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
192 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
194 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
198 table { border-collapse: collapse; }
199 th, td { border: 1px solid lightgray; padding: 4px;}
203 <h1>%s</h1>""" % (title, title)
204 for d in self.dimOther:
205 print >>html, "%s: " % d
208 if v in self.valsOther:
211 vv = DimValues(self.valsOther)
213 links.append("<a href='%s'>%s</a>"%(urllib.quote(self.getName(valsOther=vv)), str(v)))
214 print >>html, " | ".join(links)
217 print >>html, d.htmlPreamble()
221 print >>html, "<table><thead><tr><td> </td>"
223 print >>html, "<th>%s</th>" % x.htmlLabel()
224 print >>html, "</tr></thead>"
226 print >>html, "<tr><th>%s</th>" % y.htmlLabel()
231 idx.extend(self.valsOther)
233 test = tests.getTest(idx)
235 test.printThumbLink(html)
237 print >>html, "No thumbnail :-("
240 print >>html, "</td>"
241 print >>html, "</tr>"
244 <div style="font-size: small; color: gray; margin-top: 1em;">Authors: Michal Sojka, Pavel Píša, Copyright © 2010 Czech Technical University in Prague</div>
249 if __name__ == "__main__":
250 os.chdir(sys.argv[1])
251 os.system("rm *.html")
252 tests = Tests("./", DimensionHostKern(), DimensionKern(), DimensionTraffic(), DimensionTest())