genhtml can switch between pages
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 7 Dec 2010 23:28:35 +0000 (00:28 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 7 Dec 2010 23:28:35 +0000 (00:28 +0100)
gw-tests/genhtml/Makefile
gw-tests/genhtml/genhtml.py

index 17e0f2b..8463982 100644 (file)
@@ -1,2 +1,7 @@
+all: test results
+
 test:
        ./wvtestrun ./wvtest.py genhtml-test.py
+
+results:
+       $(MAKE) -C .. html
index 83995bc..3bc059c 100755 (executable)
@@ -9,11 +9,19 @@ class DimValue:
     def __init__(self, dim, value):
        self.dim = dim
        self.value = value
+    def __str__(self):
+        return str(self.value)
     def __repr__(self):
        return repr(self.value)
     def htmlLabel(self):
        return self.dim.htmlLabel(self.value)
 
+class DimValues(list):
+    def replace(self, val):
+        for i in xrange(len(self)):
+            if self[i].dim == val.dim:
+                self[i] = val
+
 class Dimension(dict):
     def __init__(self, atype, name=None):
        self.type = atype
@@ -92,16 +100,16 @@ class Test:
     def __init__(self, path):
        self.path = path
     def printThumbLink(self, file):
-        print self.path
-       for img in dircache.listdir(self.path+'/thumb'):
-           print >>file, "<a href='%s/%s'><img src='%s/thumb/%s'></a>" % \
-               (urllib.quote(self.path), img, urllib.quote(self.path), img)
+        thumb = self.path+'/thumb'
+        for img in dircache.listdir(thumb):
+            print >>file, "<a href='%s/%s'><img src='%s/thumb/%s'></a>" % \
+                  (urllib.quote(self.path), img, urllib.quote(self.path), img)
 
 def iterDimValues(dimensions):
     idx = [0 for i in xrange(len(dimensions))]
     done=False
     while not done:
-       values=[]
+       values=DimValues()
        for i in xrange(len(dimensions)):
            values.append(dimensions[i].values()[idx[i]])
        yield values
@@ -157,7 +165,6 @@ class Tests(dict):
     def generateHtml(self):
        for pair in self.iterDimensionPairs():
            remDims = [d for d in self.iterRemainingDimensions(pair)]
-            print pair, remDims
            for vals in iterDimValues(remDims):
                page = Page(pair, remDims, vals, self)
                page.generate()
@@ -174,11 +181,13 @@ class Page:
        self.dimOther = dimOther
        self.valsOther = valsOther
        self.tests = tests
-    def getName(self):
-       return "%s-vs-%s-%s.html"%(self.dimy.type, self.dimx.type, "-".join([v.value for v in self.valsOther]))
+    def getName(self, dimy=None, dimx=None, valsOther=None):
+       return "%s-vs-%s-for-%s.html"%(dimx or self.dimy.type,
+                                       dimy or self.dimx.type,
+                                       "-".join([v.value for v in valsOther or self.valsOther]))
     def generate(self):
        html = open(self.getName(), "w")
-       title = "CAN gateway timing analysis" + ", ".join([v.dim.name+" "+v.value for v in self.valsOther])
+       title = "CAN gateway timing analysis" 
        print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
 <head>
@@ -193,15 +202,21 @@ th, td { border: 1px solid lightgray; padding: 4px;}
 <body>
 <h1>%s</h1>"""  % (title, title)
        for d in self.dimOther:
-           pass
-#             print >>html, "View for %s: " % str(ps.pageclass.name)
-#             for v in ps.values:
-#                 print >>html, "<a href='%s-%s.html'>%s</a> | "%(ps.values.type, urllib.quote(v), v)
-#             print >>html, "<br>"
-#             try:
-#                 print >>html, d.htmlPreamble()
-#             except Exception:
-#                 pass
+            print >>html, "%s: " % d
+            links = []
+            for v in d.values():
+                if v in self.valsOther:
+                    links.append(str(v))
+                else:
+                    vv = DimValues(self.valsOther)
+                    vv.replace(v)
+                    links.append("<a href='%s'>%s</a>"%(urllib.quote(self.getName(valsOther=vv)), str(v)))
+            print >>html, " | ".join(links)
+            print >>html, "<br>"
+            try:
+                print >>html, d.htmlPreamble()
+            except Exception:
+                pass
 
        print >>html, "<table><thead><tr><td> </td>"
        for x in self.dimx:
@@ -214,9 +229,15 @@ th, td { border: 1px solid lightgray; padding: 4px;}
                print >>html, "<td>"
                idx = [x,y]
                idx.extend(self.valsOther)
-               test = tests.getTest(idx)
-               test.printThumbLink(html)
-               print >>html, "</td>"
+                try:
+                    test = tests.getTest(idx)
+                    try:
+                        test.printThumbLink(html)
+                    except OSError:
+                        print >>html, "No thumbnail :-("
+                except KeyError:
+                    print >>html, "N/A"
+                print >>html, "</td>"
            print >>html, "</tr>"
        print >> html, """
 </table>
@@ -227,6 +248,7 @@ th, td { border: 1px solid lightgray; padding: 4px;}
 
 if __name__ == "__main__":
     os.chdir(sys.argv[1])
+    os.system("rm *.html")
     tests = Tests("./", DimensionHostKern(), DimensionKern(), DimensionTraffic(), DimensionTest())
     tests.generateHtml()
     sys.exit(0)