# this is automatically filled in
deadhosts = []
+def select(name, values, default=None):
+ yield "<select name='%s'>" % name
+ for key in sorted(values):
+ if key == default:
+ yield "<option selected value='%s'>%s</option>" % (key, values[key])
+ else:
+ yield "<option value='%s'>%s</option>" % (key, values[key])
+ yield "</select>"
+
+
def get_param(form, param):
"""get a param from the request, after sanitizing it"""
if param not in form:
return result[0]
-def build_link(myself, tree, host, compiler, rev, status):
- if rev:
- opt_rev = ';revision=%s' % rev
- else:
- opt_rev = ''
- return "<a href='%s?function=View+Build;host=%s;tree=%s;compiler=%s%s'>%s</a>" % (
- myself, host, tree, compiler, opt_rev, status)
-
-
def html_build_status(status):
def span(classname, contents):
return "<span class=\"%s\">%s</span>" % (classname, contents)
else:
return span("status failed", stage.result)
- ostatus = ""
+ ostatus = []
if "panic" in status.other_failures:
- ostatus += "/"+span("status panic", "PANIC")
+ return span("status panic", "PANIC")
if "disk full" in status.other_failures:
- ostatus += "/"+span("status failed", "disk full")
+ return span("status failed", "disk full")
if "timeout" in status.other_failures:
- ostatus += "/"+span("status failed", "timeout")
+ return span("status failed", "timeout")
if "inconsistent test result" in status.other_failures:
- ostatus += "/"+span("status failed", "unexpected return code")
+ ostatus.append(span("status failed", "unexpected return code"))
bstatus = "/".join([span_status(s) for s in status.stages])
if bstatus == "":
bstatus = "?"
- return bstatus + ostatus
+ return "/".join([bstatus] + ostatus)
def build_status_html(myself, build):
- status = html_build_status(build.status())
- return build_link(myself, build.tree, build.host, build.compiler, build.revision, status)
+ 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_status_vals(status):
return status.split("/")
+def host_link(myself, host):
+ return "<a href='%s?function=View+Host;host=%s'>%s</a>" % (
+ myself, host, host)
+
+
def revision_link(myself, revision, tree):
"""return a link to a particular revision"""
-
if revision is None:
return "unknown"
-
- revision = revision.lstrip()
- rev_short = revision
- if len(revision) == 40:
- rev_short = re.sub("(^.{7}).*", "\\1(git)", rev_short)
-
- return "<a href='%s?function=diff;tree=%s;revision=%s' title='View Diff for %s'>%s</a>" % (myself, tree, revision, revision, rev_short)
+ return "<a href='%s?function=diff;tree=%s;revision=%s' title='View Diff for %s'>%s</a>" % (myself, tree, revision, revision, revision[:7])
def subunit_to_buildfarm_result(subunit_result):
return ret
-def diff_pretty(diff):
- """pretty up a diff -u"""
- return highlight(diff, DiffLexer(), HtmlFormatter())
-
-
def web_paths(t, paths):
"""change the given source paths into links"""
if t.scm == "git":
raise Exception("Unknown scm %s" % t.scm)
-def history_row_html(myself, entry, tree, changes):
- """show one row of history table"""
- msg = cgi.escape(entry.message)
- t = time.asctime(time.gmtime(entry.date))
- age = util.dhm_time(time.time()-entry.date)
-
- t = t.replace(" ", " ")
-
- yield """
-<div class=\"history_row\">
- <div class=\"datetime\">
- <span class=\"date\">%s</span><br />
- <span class=\"age\">%s ago</span>""" % (t, age)
- if entry.revision:
- yield " - <span class=\"revision\">%s</span><br/>" % entry.revision
- revision_url = "revision=%s" % entry.revision
- else:
- revision_url = "author=%s" % entry.author
- yield """ </div>
- <div class=\"diff\">
- <span class=\"html\"><a href=\"%s?function=diff;tree=%s;date=%s;%s\">show diffs</a></span>
- <br />
- <span class=\"text\"><a href=\"%s?function=text_diff;tree=%s;date=%s;%s\">download diffs</a></span>
- <br />
- <div class=\"history_log_message\">
- <pre>%s</pre>
- </div>
- </div>
- <div class=\"author\">
- <span class=\"label\">Author: </span>%s
- </div>""" % (myself, tree.name, entry.date, revision_url,
- myself, tree.name, entry.date, revision_url,
- msg, entry.author)
-
- (added, modified, removed) = changes
-
- if modified:
- yield "<div class=\"files\"><span class=\"label\">Modified: </span>"
- yield web_paths(tree, modified)
- yield "</div>\n"
-
- if added:
- yield "<div class=\"files\"><span class=\"label\">Added: </span>"
- yield web_paths(tree, added)
- yield "</div>\n"
-
- if removed:
- yield "<div class=\"files\"><span class=\"label\">Removed: </span>"
- yield web_paths(tree, removed)
- yield "</div>\n"
-
- yield "</div>\n"
-
-
def history_row_text(entry, tree, changes):
"""show one row of history table"""
msg = cgi.escape(entry.message)
yield "\n\n%s\n\n\n" % msg
-def show_diff(diff, text_html):
- if text_html == "html":
- diff = cgi.escape(diff)
- diff = diff_pretty(diff)
- return "<pre>%s</pre>\n" % diff
- else:
- return "%s\n" % diff
-
-
class BuildFarmPage(object):
def __init__(self, buildfarm):
def show_oldrevs(self, myself, tree, host, compiler):
"""show the available old revisions, if any"""
- old_rev_builds = self.buildfarm.builds.get_old_revs(tree, host, compiler)
+ old_builds = self.buildfarm.builds.get_old_builds(tree, host, compiler)
- if len(old_rev_builds) == 0:
+ if not old_builds:
return
yield "<h2>Older builds:</h2>\n"
yield "<table class='real'>\n"
- yield "<thead><tr><th>Revision</th><th>Status</th></tr></thead>\n"
+ yield "<thead><tr><th>Revision</th><th>Status</th><th>Age</th></tr></thead>\n"
yield "<tbody>\n"
- for build in old_rev_builds:
- yield "<tr><td>%s</td><td>%s</td></tr>\n" % (
+ for build in old_builds:
+ yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n" % (
revision_link(myself, build.revision, tree),
- build_status_html(myself, build))
+ build_status_html(myself, build), util.dhm_time(build.age))
yield "</tbody></table>\n"
- def render(self, myself, tree, host, compiler, rev, plain_logs=False):
+ def render(self, myself, tree, host, compiler, rev, checksum=None,
+ plain_logs=False):
"""view one build in detail"""
- uname = ""
- cflags = ""
- config = ""
+ uname = None
+ cflags = None
+ config = None
try:
- build = self.buildfarm.get_build(tree, host, compiler, rev)
+ build = self.buildfarm.get_build(tree, host, compiler, rev,
+ checksum=checksum)
except data.NoSuchBuildError:
- yield "No such build: %s on %s with %s, rev %s" % (tree, host, compiler, rev)
+ yield "No such build: %s on %s with %s, rev %r, checksum %r" % (
+ tree, host, compiler, rev, checksum)
return
try:
- (revision, revision_time) = build.revision_details()
- except data.MissingRevisionInfo:
- revision = None
-
- status = build_status_html(myself, build)
-
- if rev:
- assert re.match("^[0-9a-fA-F]*$", rev)
-
- f = build.read_log()
- try:
- log = f.read()
- finally:
- f.close()
+ f = build.read_log()
+ try:
+ log = f.read()
+ finally:
+ f.close()
+ except data.LogFileMissing:
+ log = None
f = build.read_err()
try:
err = f.read()
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"))
- yield "<tr><td>Uname:</td><td>%s</td></tr>\n" % uname
+ 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, revision, tree)
+ yield "<tr><td>Build Revision:</td><td>%s</td></tr>\n" % revision_link(myself, build.revision, 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" % status
+ 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>CFLAGS:</td><td>%s</td></tr>\n" % cflags
- yield "<tr><td>configure options:</td><td>%s</td></tr>\n" % config
+ 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 "<h2>Error log:</h2>"
yield make_collapsible_html('action', "Error Output", "\n%s" % err, "stderr-0", "errorlog")
- if log == "":
+ if log is None:
yield "<h2>No build log available</h2>"
else:
yield "<h2>Build log:</h2>\n"
class ViewRecentBuildsPage(BuildFarmPage):
- def render(self, myself, tree, sort_by):
+ def render(self, myself, tree, sort_by=None):
"""Draw the "recent builds" view"""
all_builds = []
- cmp_funcs = {
- "revision": lambda a, b: cmp(a[7], b[7]),
- "age": lambda a, b: cmp(a[0], b[0]),
- "host": lambda a, b: cmp(a[2], b[2]),
- "platform": lambda a, b: cmp(a[1], b[1]),
- "compiler": lambda a, b: cmp(a[3], b[3]),
- "status": lambda a, b: cmp(a[6], b[6]),
- }
-
- assert tree in self.buildfarm.trees, "not a build tree"
- assert sort_by in cmp_funcs, "not a valid sort"
-
- for build in self.buildfarm.get_tree_builds(tree):
+ def build_platform(build):
try:
host = self.buildfarm.hostdb[build.host]
except hostdb.NoSuchHost:
- # Skip, at least for now.
- continue
- status = build_status_html(myself, build)
- try:
- (revision, revision_time) = build.revision_details()
- except data.MissingRevisionInfo:
- pass
+ return "UNKNOWN"
else:
- all_builds.append([
- build.age,
- host.platform.encode("utf-8"),
- "<a href='%s?function=View+Host;host=%s;tree=%s;compiler=%s#%s'>%s</a>"
- % (myself, host.name,
- tree, build.compiler, host.name,
- host.name),
- build.compiler, tree, status, build.status(),
- revision_link(myself, revision, tree),
- revision_time])
+ return host.platform.encode("utf-8")
+
+ cmp_funcs = {
+ "revision": lambda a, b: cmp(a.revision, b.revision),
+ "age": lambda a, b: cmp(a.age, b.age),
+ "host": lambda a, b: cmp(a.host, b.host),
+ "platform": lambda a, b: cmp(build_platform(a), build_platform(b)),
+ "compiler": lambda a, b: cmp(a.compiler, b.compiler),
+ "status": lambda a, b: cmp(a.status(), b.status()),
+ }
+
+ if sort_by is None:
+ sort_by = "age"
+
+ if sort_by not in cmp_funcs:
+ yield "not a valid sort mechanism: %r" % sort_by
+ return
+
+ all_builds = list(self.buildfarm.get_tree_builds(tree))
all_builds.sort(cmp_funcs[sort_by])
for build in all_builds:
yield "<tr>"
- yield "<td>%s</td>" % util.dhm_time(build[0])
- yield "<td>%s</td>" % build[7]
- yield "<td>%s</td>" % build[4]
- yield "<td>%s</td>" % build[1]
- yield "<td>%s</td>" % build[2]
- yield "<td>%s</td>" % build[3]
- yield "<td>%s</td>" % build[5]
+ yield "<td>%s</td>" % util.dhm_time(build.age)
+ yield "<td>%s</td>" % revision_link(myself, build.revision, build.tree)
+ yield "<td>%s</td>" % build.tree
+ 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 "</tr>"
yield "</tbody></table>"
yield "</div>"
yield "<tbody>"
def _render_build_html(self, myself, build):
- try:
- (revision, revision_time) = build.revision_details()
- except data.MissingRevisionInfo:
- revision = None
warnings = build.err_count()
- status = build_status_html(myself, build)
yield "<tr>"
yield "<td><span class='tree'>" + self.tree_link(myself, build.tree) +"</span>/" + build.compiler + "</td>"
- yield "<td>" + revision_link(myself, revision, build.tree) + "</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>" % status
+ yield "<td><div class='status'>%s</div></td>" % build_status_html(myself, build)
yield "<td>%s</td>" % warnings
yield "</tr>"
yield "</div>"
-class DiffPage(BuildFarmPage):
+class HistoryPage(BuildFarmPage):
+
+ def history_row_html(self, myself, entry, tree, changes):
+ """show one row of history table"""
+ msg = cgi.escape(entry.message)
+ t = time.asctime(time.gmtime(entry.date))
+ age = util.dhm_time(time.time()-entry.date)
+
+ t = t.replace(" ", " ")
+
+ yield """
+ <div class=\"history_row\">
+ <div class=\"datetime\">
+ <span class=\"date\">%s</span><br />
+ <span class=\"age\">%s ago</span>""" % (t, age)
+ if entry.revision:
+ yield " - <span class=\"revision\">%s</span><br/>" % entry.revision
+ revision_url = "revision=%s" % entry.revision
+ else:
+ revision_url = "author=%s" % entry.author
+ yield """ </div>
+ <div class=\"diff\">
+ <span class=\"html\"><a href=\"%s?function=diff;tree=%s;date=%s;%s\">show diffs</a></span>
+ <br />
+ <span class=\"text\"><a href=\"%s?function=text_diff;tree=%s;date=%s;%s\">download diffs</a></span>
+ <br />
+ <div class=\"history_log_message\">
+ <pre>%s</pre>
+ </div>
+ </div>
+ <div class=\"author\">
+ <span class=\"label\">Author: </span>%s
+ </div>""" % (myself, tree.name, entry.date, revision_url,
+ myself, tree.name, entry.date, revision_url,
+ msg, entry.author)
+
+ (added, modified, removed) = changes
+
+ if modified:
+ yield "<div class=\"files\"><span class=\"label\">Modified: </span>"
+ yield web_paths(tree, modified)
+ yield "</div>\n"
+
+ if added:
+ yield "<div class=\"files\"><span class=\"label\">Added: </span>"
+ yield web_paths(tree, added)
+ yield "</div>\n"
+
+ if removed:
+ yield "<div class=\"files\"><span class=\"label\">Removed: </span>"
+ 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"
+
+ yield "</div>\n"
+
+
+class DiffPage(HistoryPage):
def render(self, myself, tree, revision):
t = self.buildfarm.trees[tree]
tree, t.branch, revision)
yield "<h2>%s</h2>" % title
changes = branch.changes_summary(revision)
- yield "".join(history_row_html(myself, entry, t, changes))
- yield show_diff(diff, "html")
+ yield "".join(self.history_row_html(myself, entry, t, changes))
+ diff = highlight(diff, DiffLexer(), HtmlFormatter())
+ yield "<pre>%s</pre>\n" % diff.encode("utf-8")
-class RecentCheckinsPage(BuildFarmPage):
+class RecentCheckinsPage(HistoryPage):
limit = 40
tree, t.scm, t.branch)
yield "<form method='GET'>"
yield "Select Author: "
- yield "<select name='author'>"
- for email in sorted(authors):
- yield "<option value='%s'>%s</option>" % (email, authors[email])
- yield "</select>"
+ yield "".join(select(name="author", values=authors, default=author))
yield "<input type='submit' name='sub_function' value='Refresh'/>"
yield "<input type='hidden' name='tree' value='%s'/>" % tree
yield "<input type='hidden' name='function', value='Recent Checkins'/>"
for entry in interesting[:self.limit]:
changes = branch.changes_summary(entry.revision)
- yield "".join(history_row_html(myself, entry, t, changes))
+ yield "".join(self.history_row_html(myself, entry, t, changes))
yield "\n"
def __init__(self, buildfarm):
self.buildfarm = buildfarm
- def main_menu(self):
+ def main_menu(self, tree, host, compiler):
"""main page"""
yield "<form method='GET'>\n"
yield "<div id='build-menu'>\n"
- yield "<select name='host'>\n"
- for host in self.buildfarm.hostdb.hosts():
- yield "<option value='%s'>%s -- %s</option>\n" % (
- host.name, host.platform.encode("utf-8"), host.name)
- yield "</select>\n"
- yield "<select name='tree'>\n"
- for tree, t in self.buildfarm.trees.iteritems():
- yield "<option value='%s'>%s:%s</option>\n" % (tree, tree, t.branch)
- yield "</select>\n"
- yield "<select name='compiler'>\n"
- for compiler in self.buildfarm.compilers:
- yield "<option>%s</option>\n" % compiler
- yield "</select>\n"
+ host_dict = {}
+ for h in self.buildfarm.hostdb.hosts():
+ host_dict[h.name] = "%s -- %s" % (h.platform.encode("utf-8"), h.name)
+ yield "".join(select("host", host_dict, default=host))
+ tree_dict = {}
+ for t in self.buildfarm.trees.values():
+ tree_dict[t.name] = "%s:%s" % (t.name, t.branch)
+ yield "".join(select("tree", tree_dict, default=tree))
+ yield "".join(select("compiler", dict(zip(self.buildfarm.compilers, self.buildfarm.compilers)), default=compiler))
yield "<br/>\n"
yield "<input type='submit' name='function' value='View Build'/>\n"
yield "<input type='submit' name='function' value='View Host'/>\n"
(entry, diff) = branch.diff(revision)
changes = branch.changes_summary(revision)
yield "".join(history_row_text(entry, tree, changes))
- yield show_diff(diff, "text")
+ yield "%s\n" % diff
elif fn_name == 'Text_Summary':
start_response('200 OK', [('Content-type', 'text/plain')])
page = ViewSummaryPage(self.buildfarm)
yield "<body>"
yield util.FileLoad(os.path.join(webdir, "header2.html"))
- yield "".join(self.main_menu())
+ 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"))
- tree = get_param(form, "tree")
- host = get_param(form, "host")
- compiler = get_param(form, "compiler")
+ revision = get_param(form, "revision")
+ checksum = get_param(form, "checksum")
page = ViewBuildPage(self.buildfarm)
- yield "".join(page.render(myself, tree, host, compiler, get_param(form, "revision"), plain_logs))
+ yield "".join(page.render(myself, tree, host, compiler, revision, checksum, plain_logs))
elif fn_name == "View_Host":
page = ViewHostPage(self.buildfarm)
yield "".join(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 "revision"))
+ yield "".join(page.render(myself, get_param(form, "tree"), get_param(form, "sortby") or "age"))
elif fn_name == "Recent_Checkins":
# validate the tree
- tree = get_param(form, "tree")
author = get_param(form, 'author')
page = RecentCheckinsPage(self.buildfarm)
yield "".join(page.render(myself, tree, author))
elif fn_name == "diff":
- tree = get_param(form, "tree")
revision = get_param(form, 'revision')
page = DiffPage(self.buildfarm)
yield "".join(page.render(myself, tree, revision))
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 'revision'))
+ 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]))
if __name__ == '__main__':
import optparse
parser = optparse.OptionParser("[options]")
- parser.add_option("--cachedirname", help="Cache directory name", type=str)
parser.add_option("--port", help="Port to listen on [localhost:8000]", default="localhost:8000", type=str)
opts, args = parser.parse_args()
- buildfarm = CachingBuildFarm(cachedirname=opts.cachedirname)
+ from buildfarm.sqldb import StormCachingBuildFarm
+ buildfarm = StormCachingBuildFarm()
buildApp = BuildFarmApp(buildfarm)
from wsgiref.simple_server import make_server
import mimetypes