2 # -*- coding: utf-8 -*-
9 def __init__(self, dim, value):
13 return repr(self.value)
15 return self.dim.htmlLabel(self.value)
17 class Dimension(dict):
18 def __init__(self, atype, name=None):
31 def addValue(self, *values):
34 self[value] = DimValue(self, value)
35 def htmlLabel(self, v):
42 class DimensionKern(Dimension):
44 Dimension.__init__(self, 'gwkern', 'GW kernel')
45 def htmlLabel(self, v):
49 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
57 class DimensionHostKern(Dimension):
59 Dimension.__init__(self, 'hostkern', 'Host kernel')
60 def htmlLabel(self, v):
61 if v.find("host-") == 0:
63 # TODO: remove host- prefix
67 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
75 class DimensionTest(Dimension):
77 Dimension.__init__(self, 'test', 'Test')
78 def htmlLabel(self, v):
79 return v+"<br><a href='%s.sh.html'>source</a>"%(urllib.quote(v))
81 class DimensionTraffic(Dimension):
83 Dimension.__init__(self, 'traf', 'Traffic')
84 def htmlLabel(self, v):
89 def isOnPath(cls, path):
90 f = os.path.join(path, '.results')
91 return os.path.isfile(f)
92 def __init__(self, path):
94 def printThumbLink(self, file):
96 for img in dircache.listdir(self.path+'/thumb'):
97 print >>file, "<a href='%s/%s'><img src='%s/thumb/%s'></a>" % \
98 (urllib.quote(self.path), img, urllib.quote(self.path), img)
100 def iterDimValues(dimensions):
101 idx = [0 for i in xrange(len(dimensions))]
105 for i in xrange(len(dimensions)):
106 values.append(dimensions[i].values()[idx[i]])
109 for i in xrange(len(dimensions)):
111 if idx[i] < len(dimensions[i]):
117 """Represents all tests organized along several dimensions"""
118 def __init__(self, rootpath, *dimensions):
120 self.dimensions = dimensions
122 self.populate(rootpath)
123 def getTest(self, key):
125 for d in self.dimensions:
128 realkey.append(i.value)
129 if len(realkey) != len(self.dimensions):
130 raise KeyError("The coordinates in key do not match dimensions")
131 return self[tuple(realkey)]
133 def addTest(self, test, coordinates):
134 if len(coordinates) != len(self.dimensions):
135 raise KeyError("The number coordinates do not match the number of dimensions: " + str(coordinates))
136 self[tuple(coordinates)] = test
137 for i in xrange(len(coordinates)):
138 self.dimensions[i].addValue(coordinates[i])
140 def populate(self, rootpath):
141 for root, dirs, files in os.walk(rootpath):
142 if (root.find(rootpath) == 0):
143 coordinates = root[len(rootpath):]
145 coordinates = rootpath
146 if Test.isOnPath(root):
147 self.addTest(Test(root), coordinates.split("/"))
148 def iterDimensionPairs(self):
149 for i in xrange(len(self.dimensions)):
150 for j in xrange(i+1, len(self.dimensions)):
151 yield (self.dimensions[i], self.dimensions[j])
152 yield (self.dimensions[j], self.dimensions[i])
153 def iterRemainingDimensions(self, dimensionPair):
154 for d in self.dimensions:
155 if d not in dimensionPair:
157 def generateHtml(self):
158 for pair in self.iterDimensionPairs():
159 remDims = [d for d in self.iterRemainingDimensions(pair)]
161 for vals in iterDimValues(remDims):
162 page = Page(pair, remDims, vals, self)
165 os.remove("index.html")
167 os.symlink(page.getName(), "index.html")
169 #os.system("source-highlight -d --output-dir=. ../*.sh")
172 def __init__(self, dimPair, dimOther, valsOther, tests):
173 self.dimy, self.dimx = dimPair
174 self.dimOther = dimOther
175 self.valsOther = valsOther
178 return "%s-vs-%s-%s.html"%(self.dimy.type, self.dimx.type, "-".join([v.value for v in self.valsOther]))
180 html = open(self.getName(), "w")
181 title = "CAN gateway timing analysis" + ", ".join([v.dim.name+" "+v.value for v in self.valsOther])
182 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
183 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
185 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
189 table { border-collapse: collapse; }
190 th, td { border: 1px solid lightgray; padding: 4px;}
194 <h1>%s</h1>""" % (title, title)
195 for d in self.dimOther:
197 # print >>html, "View for %s: " % str(ps.pageclass.name)
198 # for v in ps.values:
199 # print >>html, "<a href='%s-%s.html'>%s</a> | "%(ps.values.type, urllib.quote(v), v)
200 # print >>html, "<br>"
202 # print >>html, d.htmlPreamble()
206 print >>html, "<table><thead><tr><td> </td>"
208 print >>html, "<th>%s</th>" % x.htmlLabel()
209 print >>html, "</tr></thead>"
211 print >>html, "<tr><th>%s</th>" % y.htmlLabel()
216 idx.extend(self.valsOther)
217 test = tests.getTest(idx)
218 test.printThumbLink(html)
219 print >>html, "</td>"
220 print >>html, "</tr>"
223 <div style="font-size: small; color: gray; margin-top: 1em;">Authors: Michal Sojka, Pavel Píša, Copyright © 2010 Czech Technical University in Prague</div>
228 if __name__ == "__main__":
229 os.chdir(sys.argv[1])
230 tests = Tests("./", DimensionHostKern(), DimensionKern(), DimensionTraffic(), DimensionTest())