Revive lcov reporting
[build-farm.git] / buildfarm / web / __init__.py
index 8c9aad6825f8f156b3637b49d46868193a2319d8..eae7ab04bed736b2d55c2d7f2c245d3192fa1d56 100755 (executable)
@@ -35,10 +35,14 @@ from collections import defaultdict
 import os
 
 from buildfarm import (
-    data,
     hostdb,
     util,
     )
+from buildfarm.build import (
+    LogFileMissing,
+    NoSuchBuildError,
+    NoTestOutput,
+    )
 
 import cgi
 from pygments import highlight
@@ -100,53 +104,56 @@ def html_build_status(status):
 
     ostatus = []
     if "panic" in status.other_failures:
-        return span("status panic", "PANIC")
+        ostatus.append(span("status panic", "PANIC"))
     if "disk full" in status.other_failures:
-        return span("status failed", "disk full")
+        ostatus.append(span("status failed", "disk full"))
     if "timeout" in status.other_failures:
-        return span("status failed", "timeout")
+        ostatus.append(span("status failed", "timeout"))
     if "inconsistent test result" in status.other_failures:
         ostatus.append(span("status failed", "unexpected return code"))
     bstatus = "/".join([span_status(s) for s in status.stages])
-    if bstatus == "":
-        bstatus = "?"
-    return "/".join([bstatus] + ostatus)
+    ret = bstatus
+    if ostatus:
+        ret += "(%s)" % ",".join(ostatus)
+    if ret == "":
+        ret = "?"
+    return ret
+
 
+def build_uri(myself, build):
+    return "%s/build/%s" % (myself, build.log_checksum())
 
-def build_status_html(myself, build):
-    params = {
-        "host": build.host,
-        "tree": build.tree,
-        "compiler": build.compiler,
-        "checksum": build.log_checksum(),
-        }
-    if build.revision:
-        params["revision"] = build.revision
-    return "<a href='%s?function=View+Build;%s'>%s</a>" % (myself, ";".join(["%s=%s" % k for k in params.iteritems()]), html_build_status(build.status()))
 
+def build_link(myself, build):
+    return "<a href='%s'>%s</a>" % (build_uri(myself, build), html_build_status(build.status()))
 
-def build_status_vals(status):
-    """translate a status into a set of int representing status"""
-    status = util.strip_html(status)
 
-    status = status.replace("ok", "0")
-    status = status.replace("-", "0")
-    status = status.replace("?", "0.1")
-    status = status.replace("PANIC", "1")
+def tree_uri(myself, tree):
+    return "%s/tree/%s" % (myself, tree.name)
 
-    return status.split("/")
 
+def tree_link(myself, tree):
+    """return a link to a particular tree"""
+    return "<a href='%s' title='View recent builds for %s'>%s:%s</a>" % (tree_uri(myself, tree), tree.name, tree.name, tree.branch)
+
+
+def host_uri(myself, host):
+    return "%s/host/%s" % (myself, host)
 
 def host_link(myself, host):
-    return "<a href='%s?function=View+Host;host=%s'>%s</a>" % (
-        myself, host, host)
+    return "<a href='%s'>%s</a>" % (host_uri(myself, host), host)
+
+
+def revision_uri(myself, revision, tree):
+    return "%s?function=diff;tree=%s;revision=%s" % (myself, tree, revision)
 
 
 def revision_link(myself, revision, tree):
     """return a link to a particular revision"""
     if revision is None:
         return "unknown"
-    return "<a href='%s?function=diff;tree=%s;revision=%s' title='View Diff for %s'>%s</a>" % (myself, tree, revision, revision, revision[:7])
+    return "<a href='%s' title='View Diff for %s'>%s</a>" % (
+        revision_uri(myself, revision, tree), revision, revision[:7])
 
 
 def subunit_to_buildfarm_result(subunit_result):
@@ -160,9 +167,12 @@ def subunit_to_buildfarm_result(subunit_result):
         return "failed"
     elif subunit_result == "xfail":
         return "xfailed"
+    elif subunit_result == "uxsuccess":
+        return "uxpassed"
     else:
         return "unknown"
 
+
 def format_subunit_reason(reason):
     reason = re.sub("^\[\n+(.*?)\n+\]$", "\\1", reason)
     return "<div class=\"reason\">%s</div>" % reason
@@ -182,16 +192,16 @@ class LogPrettyPrinter(object):
              output = print_log_cc_checker(output)
 
         self.indice += 1
-        return make_collapsible_html('action', actionName, output, self.indice, status)
+        return "".join(make_collapsible_html('action', actionName, output, self.indice, status))
 
     # log is already CGI-escaped, so handle '>' in test name by handling &gt
     def _format_stage(self, m):
         self.indice += 1
-        return make_collapsible_html('test', m.group(1), m.group(2), self.indice, m.group(3))
+        return "".join(make_collapsible_html('test', m.group(1), m.group(2), self.indice, m.group(3)))
 
     def _format_skip_testsuite(self, m):
         self.indice += 1
-        return make_collapsible_html('test', m.group(1), '', self.indice, 'skipped')
+        return "".join(make_collapsible_html('test', m.group(1), '', self.indice, 'skipped'))
 
     def _format_testsuite(self, m):
         testName = m.group(1)
@@ -202,11 +212,11 @@ class LogPrettyPrinter(object):
         else:
             errorReason = ""
         self.indice += 1
-        return make_collapsible_html('test', testName, content+errorReason, self.indice, status)
+        return "".join(make_collapsible_html('test', testName, content+errorReason, self.indice, status))
 
     def _format_test(self, m):
         self.indice += 1
-        return make_collapsible_html('test', m.group(1), m.group(2)+format_subunit_reason(m.group(4)), self.indice, subunit_to_buildfarm_result(m.group(3)))
+        return "".join(make_collapsible_html('test', m.group(1), m.group(2)+format_subunit_reason(m.group(4)), self.indice, subunit_to_buildfarm_result(m.group(3))))
 
     def pretty_print(self, log):
         # do some pretty printing for the actions
@@ -231,7 +241,7 @@ class LogPrettyPrinter(object):
         log = re.sub("""
               ^test: ([\w\-=,_:\ /.&; \(\)]+).*?
               (.*?)
-              (success|xfail|failure|skip): [\w\-=,_:\ /.&; \(\)]+( \[.*?\])?.*?
+              (success|xfail|failure|skip|uxsuccess): [\w\-=,_:\ /.&; \(\)]+( \[.*?\])?.*?
            """, self._format_test, log)
 
         return "<pre>%s</pre>" % log
@@ -262,7 +272,7 @@ def print_log_cc_checker(input):
         if line.startswith("-- "):
             # got a new entry
             if inEntry:
-                output += make_collapsible_html('cc_checker', title, content, id, status)
+                output += "".join(make_collapsible_html('cc_checker', title, content, id, status))
             else:
                 output += content
 
@@ -276,7 +286,7 @@ def print_log_cc_checker(input):
             (title, status, id) = ("%s %s" % (m.group(1), m.group(4)), m.group(2), m.group(3))
         elif line.startswith("CC_CHECKER STATUS"):
             if inEntry:
-                output += make_collapsible_html('cc_checker', title, content, id, status)
+                output += "".join(make_collapsible_html('cc_checker', title, content, id, status))
 
             inEntry = False
             content = ""
@@ -304,27 +314,25 @@ def make_collapsible_html(type, title, output, id, status=""):
     :param type: the logical type of it. e.g. "test" or "action"
     :param title: the title to be displayed
     """
-    if ((status == "" or "failed" == status.lower())):
-        icon = 'icon_hide_16.png'
+    if status.lower() in ("", "failed"):
+        icon = '/icon_hide_16.png'
     else:
-        icon = 'icon_unhide_16.png'
+        icon = '/icon_unhide_16.png'
 
     # trim leading and trailing whitespace
     output = output.strip()
 
     # note that we may be inside a <pre>, so we don't put any extra whitespace
     # in this html
-    ret = "<div class='%s unit %s' id='%s-%s'>" % (type, status, type, id)
-    ret += "<a href=\"javascript:handle('%s');\">" % id
-    ret += "<img id='img-%s' name='img-%s' alt='%s' src='%s' />" %(id, id, status, icon)
-    ret += "<div class='%s title'>%s</div></a>" % (type, title)
-    #ret += " "
-    ret += "<div class='%s status %s'>%s</div>" % (type, status, status)
-    ret += "<div class='%s output' id='output-%s'>" % (type, id)
-    if output and len(output):
-        ret += "<pre>%s</pre>>" % (output)
-    ret += "</div></div>"
-    return ret
+    yield "<div class='%s unit %s' id='%s-%s'>" % (type, status, type, id)
+    yield "<a href=\"javascript:handle('%s');\">" % id
+    yield "<img id='img-%s' name='img-%s' alt='%s' src='%s' />" % (id, id, status, icon)
+    yield "<div class='%s title'>%s</div></a>" % (type, title)
+    yield "<div class='%s status %s'>%s</div>" % (type, status, status)
+    yield "<div class='%s output' id='output-%s'>" % (type, id)
+    if output:
+        yield "<pre>%s</pre>" % (output,)
+    yield "</div></div>"
 
 
 def web_paths(t, paths):
@@ -362,16 +370,14 @@ class BuildFarmPage(object):
     def red_age(self, age):
         """show an age as a string"""
         if age > self.buildfarm.OLDAGE:
-            return "<span clsas='old'>%s</span>" % util.dhm_time(age)
+            return "<span class='old'>%s</span>" % util.dhm_time(age)
         return util.dhm_time(age)
 
-    def tree_link(self, myself, tree):
-        # return a link to a particular tree
-        branch = ""
-        if tree in self.buildfarm.trees:
-            branch = ":%s" % self.buildfarm.trees[tree].branch
-
-        return "<a href='%s?function=Recent+Builds;tree=%s' title='View recent builds for %s'>%s%s</a>" % (myself, tree, tree, tree, branch)
+    def tree_link(self, myself, treename):
+        try:
+            return tree_link(myself, self.buildfarm.trees[treename])
+        except KeyError:
+            return treename
 
     def render(self, output_type):
         raise NotImplementedError(self.render)
@@ -395,32 +401,25 @@ class ViewBuildPage(BuildFarmPage):
         for old_build in old_builds:
             yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n" % (
                 revision_link(myself, old_build.revision, tree),
-                build_status_html(myself, old_build),
+                build_link(myself, old_build),
                 util.dhm_time(old_build.age))
 
         yield "</tbody></table>\n"
 
-    def render(self, myself, tree, host, compiler, rev, checksum=None,
-            plain_logs=False):
+    def render(self, myself, build, plain_logs=False):
         """view one build in detail"""
 
         uname = None
         cflags = None
         config = None
-        try:
-            build = self.buildfarm.get_build(tree, host, compiler, rev,
-                checksum=checksum)
-        except data.NoSuchBuildError:
-            yield "No such build: %s on %s with %s, rev %r, checksum %r" % (
-                tree, host, compiler, rev, checksum)
-            return
+
         try:
             f = build.read_log()
             try:
                 log = f.read()
             finally:
                 f.close()
-        except data.LogFileMissing:
+        except LogFileMissing:
             log = None
         f = build.read_err()
         try:
@@ -441,44 +440,56 @@ class ViewBuildPage(BuildFarmPage):
             if m:
                 config = m.group(1)
 
-        if err:
-            err = cgi.escape(err)
+        err = cgi.escape(err)
         yield '<h2>Host information:</h2>'
 
-        host_web_file = "../web/%s.html" % host
+        host_web_file = "../web/%s.html" % build.host
         if os.path.exists(host_web_file):
             yield util.FileLoad(host_web_file)
 
         yield "<table class='real'>\n"
         yield "<tr><td>Host:</td><td><a href='%s?function=View+Host;host=%s;tree=%s;"\
               "compiler=%s#'>%s</a> - %s</td></tr>\n" %\
-                (myself, host, tree, compiler, host, self.buildfarm.hostdb[host].platform.encode("utf-8"))
+                (myself, build.host, build.tree, build.compiler, build.host, self.buildfarm.hostdb[build.host].platform.encode("utf-8"))
         if uname is not None:
             yield "<tr><td>Uname:</td><td>%s</td></tr>\n" % uname
-        yield "<tr><td>Tree:</td><td>%s</td></tr>\n" % self.tree_link(myself, tree)
-        yield "<tr><td>Build Revision:</td><td>%s</td></tr>\n" % revision_link(myself, build.revision, tree)
+        yield "<tr><td>Tree:</td><td>%s</td></tr>\n" % self.tree_link(myself, build.tree)
+        yield "<tr><td>Build Revision:</td><td>%s</td></tr>\n" % revision_link(myself, build.revision, build.tree)
         yield "<tr><td>Build age:</td><td><div class='age'>%s</div></td></tr>\n" % self.red_age(build.age)
-        yield "<tr><td>Status:</td><td>%s</td></tr>\n" % build_status_html(myself, build)
-        yield "<tr><td>Compiler:</td><td>%s</td></tr>\n" % compiler
+        yield "<tr><td>Status:</td><td>%s</td></tr>\n" % build_link(myself, build)
+        yield "<tr><td>Compiler:</td><td>%s</td></tr>\n" % build.compiler
         if cflags is not None:
             yield "<tr><td>CFLAGS:</td><td>%s</td></tr>\n" % cflags
         if config is not None:
             yield "<tr><td>configure options:</td><td>%s</td></tr>\n" % config
         yield "</table>\n"
 
-        yield "".join(self.show_oldrevs(myself, tree, host, compiler))
+        yield "".join(self.show_oldrevs(myself, build.tree, build.host, build.compiler))
 
         # check the head of the output for our magic string
         rev_var = ""
-        if rev:
-            rev_var = ";revision=%s" % rev
+        if build.revision:
+            rev_var = ";revision=%s" % build.revision
 
         yield "<div id='log'>"
 
+        yield "<p><a href='%s/+subunit'>Subunit output</a>" % build_uri(myself, build)
+        try:
+            previous_build = self.buildfarm.builds.get_previous_build(build.tree, build.host, build.compiler, build.revision)
+        except NoSuchBuildError:
+            pass
+        else:
+            yield ", <a href='%s/+subunit-diff/%s'>diff against previous</a>" % (
+                build_uri(myself, build), previous_build.log_checksum())
+        yield "</p>"
+        yield "<p><a href='%s/+stdout'>Standard output (as plain text)</a>, " % build_uri(myself, build)
+        yield "<a href='%s/+stderr'>Standard error (as plain text)</a>" % build_uri(myself, build)
+        yield "</p>"
+
         if not plain_logs:
             yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s"\
                   ";compiler=%s%s;plain=true' title='Switch to bland, non-javascript,"\
-                  " unstyled view'>Plain View</a></p>" % (myself, host, tree, compiler, rev_var)
+                  " unstyled view'>Plain View</a></p>" % (myself, build.host, build.tree, build.compiler, rev_var)
 
             yield "<div id='actionList'>"
             # These can be pretty wide -- perhaps we need to
@@ -487,7 +498,7 @@ class ViewBuildPage(BuildFarmPage):
                 yield "<h2>No error log available</h2>\n"
             else:
                 yield "<h2>Error log:</h2>"
-                yield make_collapsible_html('action', "Error Output", "\n%s" % err, "stderr-0", "errorlog")
+                yield "".join(make_collapsible_html('action', "Error Output", "\n%s" % err, "stderr-0", "errorlog"))
 
             if log is None:
                 yield "<h2>No build log available</h2>"
@@ -500,7 +511,7 @@ class ViewBuildPage(BuildFarmPage):
         else:
             yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s;"\
                   "compiler=%s%s' title='Switch to colourful, javascript-enabled, styled"\
-                  " view'>Enhanced View</a></p>" % (myself, host, tree, compiler, rev_var)
+                  " view'>Enhanced View</a></p>" % (myself, build.host, build.tree, build.compiler, rev_var)
             if err == "":
                 yield "<h2>No error log available</h2>"
             else:
@@ -575,7 +586,7 @@ class ViewRecentBuildsPage(BuildFarmPage):
             yield "<td>%s</td>" % build_platform(build)
             yield "<td>%s</td>" % host_link(myself, build.host)
             yield "<td>%s</td>" % build.compiler
-            yield "<td>%s</td>" % build_status_html(myself, build)
+            yield "<td>%s</td>" % build_link(myself, build)
             yield "</tr>"
         yield "</tbody></table>"
         yield "</div>"
@@ -597,7 +608,7 @@ class ViewHostPage(BuildFarmPage):
         yield "<td><span class='tree'>" + self.tree_link(myself, build.tree) +"</span>/" + build.compiler + "</td>"
         yield "<td>" + revision_link(myself, build.revision, build.tree) + "</td>"
         yield "<td><div class='age'>" + self.red_age(build.age) + "</div></td>"
-        yield "<td><div class='status'>%s</div></td>" % build_status_html(myself, build)
+        yield "<td><div class='status'>%s</div></td>" % build_link(myself, build)
         yield "<td>%s</td>" % warnings
         yield "</tr>"
 
@@ -696,11 +707,9 @@ class ViewSummaryPage(BuildFarmPage):
         return (host_count, broken_count, panic_count)
 
     def render_text(self, myself):
-
         (host_count, broken_count, panic_count) = self._get_counts()
         # for the text report, include the current time
-        t = time.gmtime()
-        yield "Build status as of %s\n\n" % t
+        yield "Build status as of %s\n\n" % time.asctime()
 
         yield "Build counts:\n"
         yield "%-12s %-6s %-6s %-6s\n" % ("Tree", "Total", "Broken", "Panic")
@@ -708,7 +717,6 @@ class ViewSummaryPage(BuildFarmPage):
         for tree in sorted(self.buildfarm.trees.keys()):
             yield "%-12s %-6s %-6s %-6s\n" % (tree, host_count[tree],
                     broken_count[tree], panic_count[tree])
-
         yield "\n"
 
     def render_html(self, myself):
@@ -732,9 +740,10 @@ class ViewSummaryPage(BuildFarmPage):
             else:
                     yield "<td>"
             yield "%d</td>" % panic_count[tree]
+
             try:
                 lcov_status = self.buildfarm.lcov_status(tree)
-            except data.NoSuchBuildError:
+            except NoSuchBuildError:
                 yield "<td></td>"
             else:
                 if lcov_status is not None:
@@ -742,6 +751,17 @@ class ViewSummaryPage(BuildFarmPage):
                         self.buildfarm.LCOVHOST, tree, lcov_status)
                 else:
                     yield "<td></td>"
+
+            try:
+                unused_fns = self.buildfarm.unused_fns(tree)
+            except NoSuchBuildError:
+                yield "<td></td>"
+            else:
+                if unused_fns is not None:
+                    yield "<td><a href=\"/lcov/data/%s/%s/%s\">Unused Functions</a></td>" % (
+                        self.buildfarm.LCOVHOST, tree, unused_fns)
+                else:
+                    yield "<td></td>"
             yield "</tr>"
 
         yield "</tbody></table>"
@@ -801,20 +821,24 @@ class HistoryPage(BuildFarmPage):
             yield web_paths(tree, removed)
             yield "</div>\n"
 
-        yield "<div class=\"builds\">\n"
-        yield "<span class=\"label\">Builds: </span>\n"
-        for build in self.buildfarm.get_revision_builds(tree.name, entry.revision):
-            yield "%s(%s) " % (build_status_html(myself, build),
-                               host_link(myself, build.host))
-        yield "</div>\n"
-
+        builds = list(self.buildfarm.get_revision_builds(tree.name, entry.revision))
+        if builds:
+            yield "<div class=\"builds\">\n"
+            yield "<span class=\"label\">Builds: </span>\n"
+            for build in builds:
+                yield "%s(%s) " % (build_link(myself, build), host_link(myself, build.host))
+            yield "</div>\n"
         yield "</div>\n"
 
 
 class DiffPage(HistoryPage):
 
     def render(self, myself, tree, revision):
-        t = self.buildfarm.trees[tree]
+        try:
+            t = self.buildfarm.trees[tree]
+        except KeyError:
+            yield "Unknown tree %s" % tree
+            return
         branch = t.get_branch()
         (entry, diff) = branch.diff(revision)
         # get information about the current diff
@@ -840,7 +864,7 @@ class RecentCheckinsPage(HistoryPage):
         for entry in branch.log(limit=HISTORY_HORIZON):
             m = re_author.match(entry.author)
             authors[m.group(2)] = m.group(1)
-            if author in ("ALL", "", m.group(2)):
+            if author in (None, "ALL", m.group(2)):
                 interesting.append(entry)
 
         yield "<h2>Recent checkins for %s (%s branch %s)</h2>\n" % (
@@ -887,6 +911,32 @@ class BuildFarmApp(object):
         yield "</div>\n"
         yield "</form>\n"
 
+    def html_page(self, form, lines):
+        yield "<html>\n"
+        yield "  <head>\n"
+        yield "    <title>samba.org build farm</title>\n"
+        yield "    <script language='javascript' src='/build_farm.js'></script>\n"
+        yield "    <meta name='keywords' contents='Samba SMB CIFS Build Farm'/>\n"
+        yield "    <meta name='description' contents='Home of the Samba Build Farm, the automated testing facility.'/>\n"
+        yield "    <meta name='robots' contents='noindex'/>"
+        yield "    <link rel='stylesheet' href='/build_farm.css' type='text/css' media='all'/>"
+        yield "    <link rel='stylesheet' href='http://www.samba.org/samba/style/common.css' type='text/css' media='all'/>"
+        yield "    <link rel='shortcut icon' href='http://www.samba.org/samba/images/favicon.ico'/>"
+        yield "  </head>"
+        yield "<body>"
+
+        yield util.FileLoad(os.path.join(webdir, "header2.html"))
+
+        tree = get_param(form, "tree")
+        host = get_param(form, "host")
+        compiler = get_param(form, "compiler")
+        yield "".join(self.main_menu(tree, host, compiler))
+        yield util.FileLoad(os.path.join(webdir, "header3.html"))
+        yield "".join(lines)
+        yield util.FileLoad(os.path.join(webdir, "footer.html"))
+        yield "</body>"
+        yield "</html>"
+
     def __call__(self, environ, start_response):
         form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
         fn_name = get_param(form, 'function') or ''
@@ -906,72 +956,131 @@ class BuildFarmApp(object):
             start_response('200 OK', [('Content-type', 'text/plain')])
             page = ViewSummaryPage(self.buildfarm)
             yield "".join(page.render_text(myself))
-        else:
-            start_response('200 OK', [('Content-type', 'text/html')])
-
-            yield "<html>\n"
-            yield "  <head>\n"
-            yield "    <title>samba.org build farm</title>\n"
-            yield "    <script language='javascript' src='/build_farm.js'></script>\n"
-            yield "    <meta name='keywords' contents='Samba SMB CIFS Build Farm'/>\n"
-            yield "    <meta name='description' contents='Home of the Samba Build Farm, the automated testing facility.'/>\n"
-            yield "    <meta name='robots' contents='noindex'/>"
-            yield "    <link rel='stylesheet' href='/build_farm.css' type='text/css' media='all'/>"
-            yield "    <link rel='stylesheet' href='http://master.samba.org/samba/style/common.css' type='text/css' media='all'/>"
-            yield "    <link rel='shortcut icon' href='http://www.samba.org/samba/images/favicon.ico'/>"
-            yield "  </head>"
-            yield "<body>"
-
-            yield util.FileLoad(os.path.join(webdir, "header2.html"))
+        elif fn_name:
+            start_response('200 OK', [
+                ('Content-type', 'text/html; charset=utf-8')])
+
             tree = get_param(form, "tree")
             host = get_param(form, "host")
             compiler = get_param(form, "compiler")
-            yield "".join(self.main_menu(tree, host, compiler))
-            yield util.FileLoad(os.path.join(webdir, "header3.html"))
+
             if fn_name == "View_Build":
                 plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
                 revision = get_param(form, "revision")
                 checksum = get_param(form, "checksum")
-                page = ViewBuildPage(self.buildfarm)
-                yield "".join(page.render(myself, tree, host, compiler, revision, checksum, plain_logs))
+                try:
+                    build = self.buildfarm.get_build(tree, host,
+                        compiler, revision, checksum=checksum)
+                except NoSuchBuildError:
+                    yield "No such build: %s on %s with %s, rev %r, checksum %r" % (
+                        tree, host, compiler, revision, checksum)
+                else:
+                    page = ViewBuildPage(self.buildfarm)
+                    plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
+                    yield "".join(self.html_page(form, page.render(myself, build, plain_logs)))
             elif fn_name == "View_Host":
                 page = ViewHostPage(self.buildfarm)
-                yield "".join(page.render_html(myself, get_param(form, 'host')))
+                yield "".join(self.html_page(form, page.render_html(myself, get_param(form, 'host'))))
             elif fn_name == "Recent_Builds":
                 page = ViewRecentBuildsPage(self.buildfarm)
-                yield "".join(page.render(myself, get_param(form, "tree"), get_param(form, "sortby") or "age"))
+                yield "".join(self.html_page(form, page.render(myself, get_param(form, "tree"), get_param(form, "sortby") or "age")))
             elif fn_name == "Recent_Checkins":
                 # validate the tree
                 author = get_param(form, 'author')
                 page = RecentCheckinsPage(self.buildfarm)
-                yield "".join(page.render(myself, tree, author))
+                yield "".join(self.html_page(form, page.render(myself, tree, author)))
             elif fn_name == "diff":
                 revision = get_param(form, 'revision')
                 page = DiffPage(self.buildfarm)
-                yield "".join(page.render(myself, tree, revision))
-            elif os.getenv("PATH_INFO") not in (None, "", "/"):
-                paths = os.getenv("PATH_INFO").split('/')
-                if paths[1] == "recent":
-                    page = ViewRecentBuildsPage(self.buildfarm)
-                    yield "".join(page.render(myself, paths[2], get_param(form, 'sortby') or 'age'))
-                elif paths[1] == "host":
-                    page = ViewHostPage(self.buildfarm)
-                    yield "".join(page.render_html(myself, paths[2]))
+                yield "".join(self.html_page(form, page.render(myself, tree, revision)))
+            elif fn_name == "Summary":
+                page = ViewSummaryPage(self.buildfarm)
+                yield "".join(self.html_page(form, page.render_html(myself)))
             else:
+                yield "Unknown function %s" % fn_name
+        else:
+            fn = wsgiref.util.shift_path_info(environ)
+            if fn == "tree":
+                tree = wsgiref.util.shift_path_info(environ)
+                subfn = wsgiref.util.shift_path_info(environ)
+                if subfn in ("", None, "+recent"):
+                    start_response('200 OK', [
+                        ('Content-type', 'text/html; charset=utf-8')])
+                    page = ViewRecentBuildsPage(self.buildfarm)
+                    yield "".join(self.html_page(form, page.render(myself, tree, get_param(form, 'sortby') or 'age')))
+                elif subfn == "+recent-ids":
+                    start_response('200 OK', [
+                        ('Content-type', 'text/plain; charset=utf-8')])
+                    yield "".join([x.log_checksum()+"\n" for x in self.buildfarm.get_tree_builds(tree) if x.has_log()])
+                else:
+                    start_response('200 OK', [
+                        ('Content-type', 'text/html; charset=utf-8')])
+                    yield "Unknown subfn %s" % subfn
+            elif fn == "host":
+                start_response('200 OK', [
+                    ('Content-type', 'text/html; charset=utf-8')])
+                page = ViewHostPage(self.buildfarm)
+                yield "".join(self.html_page(form, page.render_html(myself, wsgiref.util.shift_path_info(environ))))
+            elif fn == "build":
+                build_checksum = wsgiref.util.shift_path_info(environ)
+                build = self.buildfarm.builds.get_by_checksum(build_checksum)
+                page = ViewBuildPage(self.buildfarm)
+                subfn = wsgiref.util.shift_path_info(environ)
+                if subfn == "+plain":
+                    start_response('200 OK', [
+                        ('Content-type', 'text/html; charset=utf-8')])
+                    yield "".join(page.render(myself, build, True))
+                elif subfn == "+subunit":
+                    start_response('200 OK', [
+                        ('Content-type', 'text/x-subunit; charset=utf-8'),
+                        ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.subunit"' % (build.tree, build.host, build.compiler, build.revision))])
+                    try:
+                        yield build.read_subunit().read()
+                    except NoTestOutput:
+                        yield "There was no test output"
+                elif subfn == "+stdout":
+                    start_response('200 OK', [
+                        ('Content-type', 'text/plain; charset=utf-8'),
+                        ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.log"' % (build.tree, build.host, build.compiler, build.revision))])
+                    yield build.read_log().read()
+                elif subfn == "+stderr":
+                    start_response('200 OK', [
+                        ('Content-type', 'text/plain; charset=utf-8'),
+                        ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.err"' % (build.tree, build.host, build.compiler, build.revision))])
+                    yield build.read_err().read()
+                elif subfn == "+subunit-diff":
+                    start_response('200 OK', [
+                        ('Content-type', 'text/plain; charset=utf-8')])
+                    subunit_this = build.read_subunit().readlines()
+                    other_build_checksum = wsgiref.util.shift_path_info(environ)
+                    other_build = self.buildfarm.builds.get_by_checksum(other_build_checksum)
+                    subunit_other = other_build.read_subunit().readlines()
+                    import difflib
+                    yield "".join(difflib.unified_diff(subunit_other, subunit_this))
+
+                elif subfn in ("", None):
+                    start_response('200 OK', [
+                        ('Content-type', 'text/html; charset=utf-8')])
+                    yield "".join(self.html_page(form, page.render(myself, build, False)))
+            elif fn in ("", None):
+                start_response('200 OK', [
+                    ('Content-type', 'text/html; charset=utf-8')])
                 page = ViewSummaryPage(self.buildfarm)
-                yield "".join(page.render_html(myself))
-            yield util.FileLoad(os.path.join(webdir, "footer.html"))
-            yield "</body>"
-            yield "</html>"
+                yield "".join(self.html_page(form, page.render_html(myself)))
+            else:
+                start_response('404 Page Not Found', [
+                    ('Content-type', 'text/html; charset=utf-8')])
+                yield "Unknown function %s" % fn
 
 
 if __name__ == '__main__':
     import optparse
     parser = optparse.OptionParser("[options]")
-    parser.add_option("--port", help="Port to listen on [localhost:8000]", default="localhost:8000", type=str)
+    parser.add_option("--port", help="Port to listen on [localhost:8000]",
+        default="localhost:8000", type=str)
     opts, args = parser.parse_args()
-    from buildfarm.sqldb import StormCachingBuildFarm
-    buildfarm = StormCachingBuildFarm()
+    from buildfarm import BuildFarm
+    buildfarm = BuildFarm()
     buildApp = BuildFarmApp(buildfarm)
     from wsgiref.simple_server import make_server
     import mimetypes