]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - tests/genhtml.py
Quote URLs in hrefs
[can-benchmark.git] / tests / genhtml.py
1 #!/usr/bin/env python
2
3 import os;
4 import dircache;
5 import sys;
6 import urllib
7
8 os.chdir(sys.argv[1])
9
10 class Axis:
11     def __init__(self, atype):
12         self.type = atype
13         self.values = dircache.listdir('by-%s'%atype)
14
15     def __str__(self):
16         if self.type == "kern": return "kernel"
17         elif self.type == "clck": return "CPU clock"
18         elif self.type == "test": return "test"
19         else: raise Exception, "Unknown type"
20
21     def __iter__(self):
22         return iter(self.values)
23
24     def __getitem__(self, key):
25         return self.values[key]
26
27     def getLabel(self, v):
28         if self.type == "clck": return v+" MHz"
29         elif self.type == "test": return "<a href='%s.sh.html'>%s</a>"%(urllib.quote(v), v)
30         else: return v
31
32
33     def labels(self):
34         for v in self.values:
35             yield self.getLabel(v)
36         
37 kernels = Axis('kern')
38 clocks = Axis('clck')
39 tests = Axis('test')
40
41 class PageSet:
42     def __init__(self, values, x, y):
43         self.values = values
44         self.x = x
45         self.y = y
46
47     def getPages(self):
48         for v in self.values:
49             yield Page(self.values.type, str(self.values), v, self.x, self.y)
50
51 class Page:
52     def __init__(self, prefix, name, value, xvals, yvals):
53         self.prefix = prefix
54         self.name = name
55         self.value = value
56         self.xvals = xvals
57         self.yvals = yvals
58                  
59     def generate(self, pagesets):
60         html = open("%s-%s.html"%(self.prefix, self.value), "w")
61         print >> html, """<html>
62 <head>
63 <title>CAN driver benchmark for %s %s</title>
64 <style>
65 img { border: 0; }
66 table { border-collapse: collapse; }
67 td { border: 1px solid lightgray; padding: 4px;}
68 </style>
69 </head>
70 <body>
71 <h1>CAN driver benchmark for %s %s</h1>"""  % (self.name, self.value, self.name, self.value)
72         for ps in pagesets:
73             print >>html, "View only %s: " % str(ps.values)
74             for v in ps.values:
75                 print >>html, "<a href='%s-%s.html'>%s</a> | "%(ps.values.type, urllib.quote(v), v)
76             print >>html, "<br>"
77         print >>html, "<table><thead><tr><td> </td>"
78         for x in self.xvals.labels():
79             print >>html, "<th>%s</th>" % x
80         print >>html, "</tr></thead>"
81         for y in self.yvals:
82             print >>html, "<tr><td>%s</td>" % self.yvals.getLabel(y)
83
84             for x in self.xvals:
85                 print >>html, "<td>"
86                 d="by-%s/%s/%s/%s/" % (self.prefix, self.value, y, x)
87                 dthumb = d+"thumb"
88                 try:
89                     for img in dircache.listdir(dthumb):
90                         print >>html, "<a href='%s/%s'><img src='%s/thumb/%s'></a>" % (urllib.quote(d), img, urllib.quote(d), img)
91                 except OSError:
92                     print "warning: no images in %s?"%dthumb
93                 print >>html, "</td>"
94             print >>html, "</tr>"
95         print >> html, """
96 </table>
97 </body>
98 """
99
100
101 pagesets = [ PageSet(kernels, clocks, tests),
102              PageSet(tests, clocks, kernels),
103              PageSet(clocks, kernels, tests)]
104
105 for ps in pagesets:
106     for p in ps.getPages():
107         p.generate(pagesets)
108
109 try:
110     os.remove("index.html")
111 except OSError: pass
112
113 os.symlink("%s-%s.html"%(kernels.type, kernels[0]), "index.html")
114
115 os.system("source-highlight -d --output-dir=. ../*.sh")
116     
117
118