2 # This CGI script presents the results of the build_farm build
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2010
5 # Copyright (C) Matthieu Patou <mat@matws.net> 2010
7 # Based on the original web/build.pl:
9 # Copyright (C) Andrew Tridgell <tridge@samba.org> 2001-2005
10 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2001
11 # Copyright (C) Vance Lankhaar <vance@samba.org> 2002-2005
12 # Copyright (C) Martin Pool <mbp@samba.org> 2001
13 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2009
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 3 of the License, or
18 # (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 """Buildfarm web frontend."""
31 # TODO: Allow filtering of the "Recent builds" list to show
32 # e.g. only broken builds or only builds that you care about.
34 from collections import defaultdict
37 from buildfarm import (
41 from buildfarm.build import (
48 from pygments import highlight
49 from pygments.lexers.text import DiffLexer
50 from pygments.formatters import HtmlFormatter
55 webdir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "web"))
57 GITWEB_BASE = "http://gitweb.samba.org"
58 HISTORY_HORIZON = 1000
60 # this is automatically filled in
63 def select(name, values, default=None):
64 yield "<select name='%s'>" % name
65 for key in sorted(values):
67 yield "<option selected value='%s'>%s</option>" % (key, values[key])
69 yield "<option value='%s'>%s</option>" % (key, values[key])
73 def get_param(form, param):
74 """get a param from the request, after sanitizing it"""
78 result = [s.replace(" ", "_") for s in form.getlist(param)]
81 if re.match("[^a-zA-Z0-9\-\_\.]", entry):
82 raise Exception("Parameter %s is invalid" % param)
87 def html_build_status(status):
88 def span(classname, contents):
89 return "<span class=\"%s\">%s</span>" % (classname, contents)
91 def span_status(stage):
92 if stage.name == "CC_CHECKER":
94 return span("status checker", "ok")
96 return span("status checker", stage.result)
98 if stage.result is None:
99 return span("status unknown", "?")
100 elif stage.result == 0:
101 return span("status passed", "ok")
103 return span("status failed", stage.result)
106 if "panic" in status.other_failures:
107 ostatus.append(span("status panic", "PANIC"))
108 if "disk full" in status.other_failures:
109 ostatus.append(span("status failed", "disk full"))
110 if "timeout" in status.other_failures:
111 ostatus.append(span("status failed", "timeout"))
112 if "inconsistent test result" in status.other_failures:
113 ostatus.append(span("status failed", "unexpected return code"))
114 bstatus = "/".join([span_status(s) for s in status.stages])
117 ret += "(%s)" % ",".join(ostatus)
123 def build_uri(myself, build):
124 return "%s/build/%s" % (myself, build.log_checksum())
127 def build_link(myself, build):
128 return "<a href='%s'>%s</a>" % (build_uri(myself, build), html_build_status(build.status()))
131 def tree_uri(myself, tree):
132 return "%s/tree/%s" % (myself, tree.name)
135 def tree_link(myself, tree):
136 """return a link to a particular tree"""
137 return "<a href='%s' title='View recent builds for %s'>%s:%s</a>" % (tree_uri(myself, tree), tree.name, tree.name, tree.branch)
140 def host_uri(myself, host):
141 return "%s/host/%s" % (myself, host)
143 def host_link(myself, host):
144 return "<a href='%s'>%s</a>" % (host_uri(myself, host), host)
147 def revision_uri(myself, revision, tree):
148 return "%s?function=diff;tree=%s;revision=%s" % (myself, tree, revision)
151 def revision_link(myself, revision, tree):
152 """return a link to a particular revision"""
155 return "<a href='%s' title='View Diff for %s'>%s</a>" % (
156 revision_uri(myself, revision, tree), revision, revision[:7])
159 def subunit_to_buildfarm_result(subunit_result):
160 if subunit_result == "success":
162 elif subunit_result == "error":
164 elif subunit_result == "skip":
166 elif subunit_result == "failure":
168 elif subunit_result == "xfail":
170 elif subunit_result == "uxsuccess":
176 def format_subunit_reason(reason):
177 reason = re.sub("^\[\n+(.*?)\n+\]$", "\\1", reason)
178 return "<div class=\"reason\">%s</div>" % reason
181 class LogPrettyPrinter(object):
186 def _pretty_print(self, m):
188 actionName = m.group(2)
190 # handle pretty-printing of static-analysis tools
191 if actionName == 'cc_checker':
192 output = print_log_cc_checker(output)
195 return "".join(make_collapsible_html('action', actionName, output, self.indice, status))
197 # log is already CGI-escaped, so handle '>' in test name by handling >
198 def _format_stage(self, m):
200 return "".join(make_collapsible_html('test', m.group(1), m.group(2), self.indice, m.group(3)))
202 def _format_skip_testsuite(self, m):
204 return "".join(make_collapsible_html('test', m.group(1), '', self.indice, 'skipped'))
206 def _format_pretestsuite(self, m):
208 return m.group(1)+"".join(make_collapsible_html('pretest', 'Pretest infos', m.group(2), self.indice, 'ok'))+"\n"+m.group(3)
210 def _format_testsuite(self, m):
211 testName = m.group(1)
213 status = subunit_to_buildfarm_result(m.group(3))
215 errorReason = format_subunit_reason(m.group(4))
219 if m.group(3) in ("error", "failure"):
220 self.test_links.append([testName, 'lnk-test-%d' %self.indice])
221 return "".join(make_collapsible_html('test', testName, content+errorReason, self.indice, status))
223 def _format_test(self, m):
225 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))))
227 def pretty_print(self, log):
228 # do some pretty printing for the actions
229 pattern = re.compile("(Running action\s+([\w\-]+)$(?:\s^.*$)*?\sACTION\ (PASSED|FAILED):\ ([\w\-]+)$)", re.M)
230 log = pattern.sub(self._pretty_print, log)
234 --==--==--==--==--==--==--==--==--==--==--.*?
235 Running\ test\ ([\w\-=,_:\ /.&;]+).*?
236 --==--==--==--==--==--==--==--==--==--==--
238 ==========================================.*?
239 TEST\ (FAILED|PASSED|SKIPPED):.*?
240 ==========================================\s+
241 """, self._format_stage, log)
243 pattern = re.compile("(Running action test).*$\s((?:^.*$\s)*?)^((?:skip-)?testsuite: )", re.M)
244 log = pattern.sub(self._format_pretestsuite, log)
246 log = re.sub("skip-testsuite: ([\w\-=,_:\ /.&; \(\)]+).*?",
247 self._format_skip_testsuite, log)
250 pattern = re.compile("^testsuite: (.+)$\s((?:^.*$\s)*?)testsuite-(\w+): .*?(?:(\[$\s(?:^.*$\s)*?^\]$)|$)", re.M)
251 log = pattern.sub(self._format_testsuite, log)
253 ^test: ([\w\-=,_:\ /.&; \(\)]+).*?
255 (success|xfail|failure|skip|uxsuccess): [\w\-=,_:\ /.&; \(\)]+( \[.*?\])?.*?
256 """, self._format_test, log)
258 for tst in self.test_links:
259 buf = "%s\n<A href='#%s'>%s</A>" % (buf, tst[1], tst[0])
263 divhtml = "".join(make_collapsible_html('testlinks', 'Shortcut to failed tests', buf, self.indice, ""))
264 log = re.sub("Running action\s+test", divhtml, log)
265 return "<pre>%s</pre>" % log
268 def print_log_pretty(log):
269 return LogPrettyPrinter().pretty_print(log)
272 def print_log_cc_checker(input):
273 # generate pretty-printed html for static analysis tools
276 # for now, we only handle the IBM Checker's output style
277 if not re.search("^BEAM_VERSION", input):
286 for line in input.splitlines():
287 # for each line, check if the line is a new entry,
288 # otherwise, store the line under the current entry.
290 if line.startswith("-- "):
293 output += "".join(make_collapsible_html('cc_checker', title, content, id, status))
297 # clear maintenance vars
298 (inEntry, content) = (True, "")
301 m = re.match("^-- ((ERROR|WARNING|MISTAKE).*?)\s+>>>([a-zA-Z0-9]+_(\w+)_[a-zA-Z0-9]+)", line)
303 # then store the result
304 (title, status, id) = ("%s %s" % (m.group(1), m.group(4)), m.group(2), m.group(3))
305 elif line.startswith("CC_CHECKER STATUS"):
307 output += "".join(make_collapsible_html('cc_checker', title, content, id, status))
312 # not a new entry, so part of the current entry's output
313 content += "%s\n" % line
317 # This function does approximately the same as the following, following
318 # commented-out regular expression except that the regex doesn't quite
319 # handle IBM Checker's newlines quite right.
321 # --\ ((ERROR|WARNING|MISTAKE).*?)\s+
325 # }{make_collapsible_html('cc_checker', "$1 $4", $5, $3, $2)}exgs
329 def make_collapsible_html(type, title, output, id, status=""):
330 """generate html for a collapsible section
332 :param type: the logical type of it. e.g. "test" or "action"
333 :param title: the title to be displayed
335 if status.lower() in ("", "failed"):
336 icon = '/icon_hide_16.png'
338 icon = '/icon_unhide_16.png'
340 # trim leading and trailing whitespace
341 output = output.strip()
343 # note that we may be inside a <pre>, so we don't put any extra whitespace
345 yield "<div class='%s unit %s' id='%s-%s'>" % (type, status, type, id)
346 yield "<a name='lnk-%s-%s' href=\"javascript:handle('%s');\">" % (type, id, id)
347 yield "<img id='img-%s' name='img-%s' alt='%s' src='%s' />" % (id, id, status, icon)
348 yield "<div class='%s title'>%s</div></a>" % (type, title)
349 yield "<div class='%s status %s'>%s</div>" % (type, status, status)
350 yield "<div class='%s output' id='output-%s'>" % (type, id)
352 yield "<pre>%s</pre>" % (output,)
356 def web_paths(t, paths):
357 """change the given source paths into links"""
361 ret += " <a href=\"%s/?p=%s;a=history;f=%s%s;h=%s;hb=%s\">%s</a>" % (GITWEB_BASE, t.repo, t.subdir, path, t.branch, t.branch, path)
364 raise Exception("Unknown scm %s" % t.scm)
367 def history_row_text(entry, tree, changes):
368 """show one row of history table"""
369 msg = cgi.escape(entry.message)
370 t = time.asctime(time.gmtime(entry.date))
371 age = util.dhm_time(time.time()-entry.date)
373 yield "Author: %s\n" % entry.author
375 yield "Revision: %s\n" % entry.revision
376 (added, modified, removed) = changes
377 yield "Modified: %s\n" % modified
378 yield "Added: %s\n" % added
379 yield "Removed: %s\n" % removed
380 yield "\n\n%s\n\n\n" % msg
383 class BuildFarmPage(object):
385 def __init__(self, buildfarm):
386 self.buildfarm = buildfarm
388 def red_age(self, age):
389 """show an age as a string"""
390 if age > self.buildfarm.OLDAGE:
391 return "<span class='old'>%s</span>" % util.dhm_time(age)
392 return util.dhm_time(age)
394 def tree_link(self, myself, treename):
396 return tree_link(myself, self.buildfarm.trees[treename])
400 def render(self, output_type):
401 raise NotImplementedError(self.render)
404 class ViewBuildPage(BuildFarmPage):
406 def show_oldrevs(self, myself, build, host, compiler, limit):
407 """show the available old revisions, if any"""
410 old_builds = self.buildfarm.builds.get_old_builds(tree, host, compiler)
415 yield "<h2>Older builds:</h2>\n"
417 yield "<table class='real'>\n"
418 yield "<thead><tr><th>Revision</th><th>Status</th><th>Age</th></tr></thead>\n"
422 for old_build in old_builds:
423 if limit >= 0 and nb >= limit:
426 yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n" % (
427 revision_link(myself, old_build.revision, tree),
428 build_link(myself, old_build),
429 util.dhm_time(old_build.age))
431 yield "</tbody></table>\n"
433 yield "<p><a href='%s/limit/-1'>Show all previous build list</a>\n" % (build_uri(myself, build))
435 def render(self, myself, build, plain_logs=False, limit=10):
436 """view one build in detail"""
448 except LogFileMissing:
457 log = cgi.escape(log)
459 m = re.search("(.*)", log)
462 m = re.search("CFLAGS=(.*)", log)
465 m = re.search("configure options: (.*)", log)
469 err = cgi.escape(err)
470 yield '<h2>Host information:</h2>'
472 host_web_file = "../web/%s.html" % build.host
473 if os.path.exists(host_web_file):
474 yield util.FileLoad(host_web_file)
476 yield "<table class='real'>\n"
477 yield "<tr><td>Host:</td><td><a href='%s?function=View+Host;host=%s;tree=%s;"\
478 "compiler=%s#'>%s</a> - %s</td></tr>\n" %\
479 (myself, build.host, build.tree, build.compiler, build.host, self.buildfarm.hostdb[build.host].platform.encode("utf-8"))
480 if uname is not None:
481 yield "<tr><td>Uname:</td><td>%s</td></tr>\n" % uname
482 yield "<tr><td>Tree:</td><td>%s</td></tr>\n" % self.tree_link(myself, build.tree)
483 yield "<tr><td>Build Revision:</td><td>%s</td></tr>\n" % revision_link(myself, build.revision, build.tree)
484 yield "<tr><td>Build age:</td><td><div class='age'>%s</div></td></tr>\n" % self.red_age(build.age)
485 yield "<tr><td>Status:</td><td>%s</td></tr>\n" % build_link(myself, build)
486 yield "<tr><td>Compiler:</td><td>%s</td></tr>\n" % build.compiler
487 if cflags is not None:
488 yield "<tr><td>CFLAGS:</td><td>%s</td></tr>\n" % cflags
489 if config is not None:
490 yield "<tr><td>configure options:</td><td>%s</td></tr>\n" % config
493 yield "".join(self.show_oldrevs(myself, build, build.host, build.compiler, limit))
495 # check the head of the output for our magic string
498 rev_var = ";revision=%s" % build.revision
500 yield "<div id='log'>"
502 yield "<p><a href='%s/+subunit'>Subunit output</a>" % build_uri(myself, build)
504 previous_build = self.buildfarm.builds.get_previous_build(build.tree, build.host, build.compiler, build.revision)
505 except NoSuchBuildError:
508 yield ", <a href='%s/+subunit-diff/%s'>diff against previous</a>" % (
509 build_uri(myself, build), previous_build.log_checksum())
511 yield "<p><a href='%s/+stdout'>Standard output (as plain text)</a>, " % build_uri(myself, build)
512 yield "<a href='%s/+stderr'>Standard error (as plain text)</a>" % build_uri(myself, build)
516 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s"\
517 ";compiler=%s%s;plain=true' title='Switch to bland, non-javascript,"\
518 " unstyled view'>Plain View</a></p>" % (myself, build.host, build.tree, build.compiler, rev_var)
520 yield "<div id='actionList'>"
521 # These can be pretty wide -- perhaps we need to
522 # allow them to wrap in some way?
524 yield "<h2>No error log available</h2>\n"
526 yield "<h2>Error log:</h2>"
527 yield "".join(make_collapsible_html('action', "Error Output", "\n%s" % err, "stderr-0", "errorlog"))
530 yield "<h2>No build log available</h2>"
532 yield "<h2>Build log:</h2>\n"
533 yield print_log_pretty(log)
535 yield "<p><small>Some of the above icons derived from the <a href='http://www.gnome.org'>Gnome Project</a>'s stock icons.</small></p>"
538 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s;"\
539 "compiler=%s%s' title='Switch to colourful, javascript-enabled, styled"\
540 " view'>Enhanced View</a></p>" % (myself, build.host, build.tree, build.compiler, rev_var)
542 yield "<h2>No error log available</h2>"
544 yield '<h2>Error log:</h2>\n'
545 yield '<div id="errorLog"><pre>%s</pre></div>' % err
547 yield '<h2>No build log available</h2>'
549 yield '<h2>Build log:</h2>\n'
550 yield '<div id="buildLog"><pre>%s</pre></div>' % log
555 class ViewRecentBuildsPage(BuildFarmPage):
557 def render(self, myself, tree, sort_by=None):
558 """Draw the "recent builds" view"""
561 def build_platform(build):
562 host = self.buildfarm.hostdb[build.host]
563 return host.platform.encode("utf-8")
565 def build_platform_safe(build):
567 host = self.buildfarm.hostdb[build.host]
568 except hostdb.NoSuchHost:
571 return host.platform.encode("utf-8")
574 "revision": lambda a, b: cmp(a.revision, b.revision),
575 "age": lambda a, b: cmp(a.age, b.age),
576 "host": lambda a, b: cmp(a.host, b.host),
577 "platform": lambda a, b: cmp(build_platform_safe(a), build_platform_safe(b)),
578 "compiler": lambda a, b: cmp(a.compiler, b.compiler),
579 "status": lambda a, b: cmp(a.status(), b.status()),
585 if sort_by not in cmp_funcs:
586 yield "not a valid sort mechanism: %r" % sort_by
589 all_builds = list(self.buildfarm.get_tree_builds(tree))
591 all_builds.sort(cmp_funcs[sort_by])
593 t = self.buildfarm.trees[tree]
595 sorturl = "%s?tree=%s;function=Recent+Builds" % (myself, tree)
597 yield "<div id='recent-builds' class='build-section'>"
598 yield "<h2>Recent builds of %s (%s branch %s)</h2>" % (tree, t.scm, t.branch)
599 yield "<table class='real'>"
602 yield "<th><a href='%s;sortby=age' title='Sort by build age'>Age</a></th>" % sorturl
603 yield "<th><a href='%s;sortby=revision' title='Sort by build revision'>Revision</a></th>" % sorturl
604 yield "<th>Tree</th>"
605 yield "<th><a href='%s;sortby=platform' title='Sort by platform'>Platform</a></th>" % sorturl
606 yield "<th><a href='%s;sortby=host' title='Sort by host'>Host</a></th>" % sorturl
607 yield "<th><a href='%s;sortby=compiler' title='Sort by compiler'>Compiler</a></th>" % sorturl
608 yield "<th><a href='%s;sortby=status' title='Sort by status'>Status</a></th>" % sorturl
611 for build in all_builds:
613 build_platform_name = build_platform(build)
615 yield "<td>%s</td>" % util.dhm_time(build.age)
616 yield "<td>%s</td>" % revision_link(myself, build.revision, build.tree)
617 yield "<td>%s</td>" % build.tree
618 yield "<td>%s</td>" % build_platform_name
619 yield "<td>%s</td>" % host_link(myself, build.host)
620 yield "<td>%s</td>" % build.compiler
621 yield "<td>%s</td>" % build_link(myself, build)
623 except hostdb.NoSuchHost:
625 yield "</tbody></table>"
629 class ViewHostPage(BuildFarmPage):
631 def _render_build_list_header(self, host):
632 yield "<div class='host summary'>"
633 yield "<a id='host' name='host'/>"
634 yield "<h3>%s - %s</h3>" % (host.name, host.platform.encode("utf-8"))
635 yield "<table class='real'>"
636 yield "<thead><tr><th>Target</th><th>Build<br/>Revision</th><th>Build<br />Age</th><th>Status<br />config/build<br />install/test</th><th>Warnings</th></tr></thead>"
639 def _render_build_html(self, myself, build):
640 warnings = build.err_count()
642 yield "<td><span class='tree'>" + self.tree_link(myself, build.tree) +"</span>/" + build.compiler + "</td>"
643 yield "<td>" + revision_link(myself, build.revision, build.tree) + "</td>"
644 yield "<td><div class='age'>" + self.red_age(build.age) + "</div></td>"
645 yield "<td><div class='status'>%s</div></td>" % build_link(myself, build)
646 yield "<td>%s</td>" % warnings
649 def render_html(self, myself, *requested_hosts):
650 yield "<div class='build-section' id='build-summary'>"
651 yield '<h2>Host summary:</h2>'
652 for hostname in requested_hosts:
654 host = self.buildfarm.hostdb[hostname]
655 except hostdb.NoSuchHost:
657 builds = list(self.buildfarm.get_host_builds(hostname))
659 yield "".join(self._render_build_list_header(host))
661 yield "".join(self._render_build_html(myself, build))
662 yield "</tbody></table>"
665 deadhosts.append(hostname)
668 yield "".join(self.draw_dead_hosts(*deadhosts))
670 def render_text(self, myself, *requested_hosts):
671 """print the host's table of information"""
672 yield "Host summary:\n"
674 for host in requested_hosts:
675 # make sure we have some data from it
677 self.buildfarm.hostdb[host]
678 except hostdb.NoSuchHost:
681 builds = list(self.buildfarm.get_host_builds(host))
683 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
684 "Tree", "Compiler", "Build Age", "Status", "Warnings")
686 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
687 build.tree, build.compiler,
688 util.dhm_time(build.age),
689 str(build.status()), build.err_count())
692 def draw_dead_hosts(self, *deadhosts):
693 """Draw the "dead hosts" table"""
695 # don't output anything if there are no dead hosts
696 if len(deadhosts) == 0:
699 yield "<div class='build-section' id='dead-hosts'>"
700 yield "<h2>Dead Hosts:</h2>"
701 yield "<table class='real'>"
702 yield "<thead><tr><th>Host</th><th>OS</th><th>Min Age</th></tr></thead>"
705 for host in deadhosts:
706 last_build = self.buildfarm.host_last_build(host)
707 age = time.time() - last_build
709 platform = self.buildfarm.hostdb[host].platform.encode("utf-8")
710 except hostdb.NoSuchHost:
712 yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" %\
713 (host, platform, util.dhm_time(age))
715 yield "</tbody></table>"
719 class ViewSummaryPage(BuildFarmPage):
721 def _get_counts(self):
722 broken_count = defaultdict(lambda: 0)
723 panic_count = defaultdict(lambda: 0)
724 host_count = defaultdict(lambda: 0)
726 # set up a variable to store the broken builds table's code, so we can
727 # output when we want
730 builds = self.buildfarm.get_last_builds()
733 host_count[build.tree]+=1
734 status = build.status()
737 broken_count[build.tree]+=1
738 if "panic" in status.other_failures:
739 panic_count[build.tree]+=1
740 return (host_count, broken_count, panic_count)
742 def render_text(self, myself):
743 (host_count, broken_count, panic_count) = self._get_counts()
744 # for the text report, include the current time
745 yield "Build status as of %s\n\n" % time.asctime()
747 yield "Build counts:\n"
748 yield "%-12s %-6s %-6s %-6s\n" % ("Tree", "Total", "Broken", "Panic")
750 for tree in sorted(self.buildfarm.trees.keys()):
751 yield "%-12s %-6s %-6s %-6s\n" % (tree, host_count[tree],
752 broken_count[tree], panic_count[tree])
755 def render_html(self, myself):
756 """view build summary"""
758 (host_count, broken_count, panic_count) = self._get_counts()
760 yield "<div id='build-counts' class='build-section'>"
761 yield "<h2>Build counts:</h2>"
762 yield "<table class='real'>"
763 yield "<thead><tr><th>Tree</th><th>Total</th><th>Broken</th><th>Panic</th><th>Test coverage</th></tr></thead>"
766 for tree in sorted(self.buildfarm.trees.keys()):
768 yield "<td>%s</td>" % self.tree_link(myself, tree)
769 yield "<td>%s</td>" % host_count[tree]
770 yield "<td>%s</td>" % broken_count[tree]
771 if panic_count[tree]:
772 yield "<td class='panic'>"
775 yield "%d</td>" % panic_count[tree]
778 lcov_status = self.buildfarm.lcov_status(tree)
779 except NoSuchBuildError:
782 if lcov_status is not None:
783 yield "<td><a href=\"/lcov/data/%s/%s\">%s %%</a></td>" % (
784 self.buildfarm.LCOVHOST, tree, lcov_status)
789 unused_fns = self.buildfarm.unused_fns(tree)
790 except NoSuchBuildError:
793 if unused_fns is not None:
794 yield "<td><a href=\"/lcov/data/%s/%s/%s\">Unused Functions</a></td>" % (
795 self.buildfarm.LCOVHOST, tree, unused_fns)
800 yield "</tbody></table>"
804 class HistoryPage(BuildFarmPage):
806 def history_row_html(self, myself, entry, tree, changes):
807 """show one row of history table"""
808 msg = cgi.escape(entry.message)
809 t = time.asctime(time.gmtime(entry.date))
810 age = util.dhm_time(time.time()-entry.date)
812 t = t.replace(" ", " ")
815 <div class=\"history_row\">
816 <div class=\"datetime\">
817 <span class=\"date\">%s</span><br />
818 <span class=\"age\">%s ago</span>""" % (t, age)
820 yield " - <span class=\"revision\">%s</span><br/>" % entry.revision
821 revision_url = "revision=%s" % entry.revision
823 revision_url = "author=%s" % entry.author
826 <span class=\"html\"><a href=\"%s?function=diff;tree=%s;date=%s;%s\">show diffs</a></span>
828 <span class=\"text\"><a href=\"%s?function=text_diff;tree=%s;date=%s;%s\">download diffs</a></span>
830 <div class=\"history_log_message\">
834 <div class=\"author\">
835 <span class=\"label\">Author: </span>%s
836 </div>""" % (myself, tree.name, entry.date, revision_url,
837 myself, tree.name, entry.date, revision_url,
840 (added, modified, removed) = changes
843 yield "<div class=\"files\"><span class=\"label\">Modified: </span>"
844 yield web_paths(tree, modified)
848 yield "<div class=\"files\"><span class=\"label\">Added: </span>"
849 yield web_paths(tree, added)
853 yield "<div class=\"files\"><span class=\"label\">Removed: </span>"
854 yield web_paths(tree, removed)
857 builds = list(self.buildfarm.get_revision_builds(tree.name, entry.revision))
859 yield "<div class=\"builds\">\n"
860 yield "<span class=\"label\">Builds: </span>\n"
862 yield "%s(%s) " % (build_link(myself, build), host_link(myself, build.host))
867 class DiffPage(HistoryPage):
869 def render(self, myself, tree, revision):
871 t = self.buildfarm.trees[tree]
873 yield "Unknown tree %s" % tree
875 branch = t.get_branch()
876 (entry, diff) = branch.diff(revision)
877 # get information about the current diff
878 title = "GIT Diff in %s:%s for revision %s" % (
879 tree, t.branch, revision)
880 yield "<h2>%s</h2>" % title
881 changes = branch.changes_summary(revision)
882 yield "".join(self.history_row_html(myself, entry, t, changes))
883 diff = highlight(diff, DiffLexer(), HtmlFormatter())
884 yield "<pre>%s</pre>\n" % diff.encode("utf-8")
887 class RecentCheckinsPage(HistoryPage):
891 def render(self, myself, tree, author=None):
892 t = self.buildfarm.trees[tree]
894 authors = {"ALL": "ALL"}
895 branch = t.get_branch()
896 re_author = re.compile("^(.*) <(.*)>$")
897 for entry in branch.log(limit=HISTORY_HORIZON):
898 m = re_author.match(entry.author)
899 authors[m.group(2)] = m.group(1)
900 if author in (None, "ALL", m.group(2)):
901 interesting.append(entry)
903 yield "<h2>Recent checkins for %s (%s branch %s)</h2>\n" % (
904 tree, t.scm, t.branch)
905 yield "<form method='GET'>"
906 yield "Select Author: "
907 yield "".join(select(name="author", values=authors, default=author))
908 yield "<input type='submit' name='sub_function' value='Refresh'/>"
909 yield "<input type='hidden' name='tree' value='%s'/>" % tree
910 yield "<input type='hidden' name='function', value='Recent Checkins'/>"
913 for entry in interesting[:self.limit]:
914 changes = branch.changes_summary(entry.revision)
915 yield "".join(self.history_row_html(myself, entry, t, changes))
919 class BuildFarmApp(object):
921 def __init__(self, buildfarm):
922 self.buildfarm = buildfarm
924 def main_menu(self, tree, host, compiler):
927 yield "<form method='GET'>\n"
928 yield "<div id='build-menu'>\n"
930 for h in self.buildfarm.hostdb.hosts():
931 host_dict[h.name] = "%s -- %s" % (h.platform.encode("utf-8"), h.name)
932 yield "".join(select("host", host_dict, default=host))
934 for t in self.buildfarm.trees.values():
935 tree_dict[t.name] = "%s:%s" % (t.name, t.branch)
936 yield "".join(select("tree", tree_dict, default=tree))
937 yield "".join(select("compiler", dict(zip(self.buildfarm.compilers, self.buildfarm.compilers)), default=compiler))
939 yield "<input type='submit' name='function' value='View Build'/>\n"
940 yield "<input type='submit' name='function' value='View Host'/>\n"
941 yield "<input type='submit' name='function' value='Recent Checkins'/>\n"
942 yield "<input type='submit' name='function' value='Summary'/>\n"
943 yield "<input type='submit' name='function' value='Recent Builds'/>\n"
947 def html_page(self, form, lines):
950 yield " <title>samba.org build farm</title>\n"
951 yield " <script language='javascript' src='/build_farm.js'></script>\n"
952 yield " <meta name='keywords' contents='Samba SMB CIFS Build Farm'/>\n"
953 yield " <meta name='description' contents='Home of the Samba Build Farm, the automated testing facility.'/>\n"
954 yield " <meta name='robots' contents='noindex'/>"
955 yield " <link rel='stylesheet' href='/build_farm.css' type='text/css' media='all'/>"
956 yield " <link rel='stylesheet' href='http://www.samba.org/samba/style/common.css' type='text/css' media='all'/>"
957 yield " <link rel='shortcut icon' href='http://www.samba.org/samba/images/favicon.ico'/>"
961 yield util.FileLoad(os.path.join(webdir, "header2.html"))
963 tree = get_param(form, "tree")
964 host = get_param(form, "host")
965 compiler = get_param(form, "compiler")
966 yield "".join(self.main_menu(tree, host, compiler))
967 yield util.FileLoad(os.path.join(webdir, "header3.html"))
969 yield util.FileLoad(os.path.join(webdir, "footer.html"))
973 def __call__(self, environ, start_response):
974 form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
975 fn_name = get_param(form, 'function') or ''
976 myself = wsgiref.util.application_uri(environ)
978 if fn_name == 'text_diff':
979 start_response('200 OK', [('Content-type', 'application/x-diff')])
980 tree = get_param(form, 'tree')
981 t = self.buildfarm.trees[tree]
982 branch = t.get_branch()
983 revision = get_param(form, 'revision')
984 (entry, diff) = branch.diff(revision)
985 changes = branch.changes_summary(revision)
986 yield "".join(history_row_text(entry, tree, changes))
988 elif fn_name == 'Text_Summary':
989 start_response('200 OK', [('Content-type', 'text/plain')])
990 page = ViewSummaryPage(self.buildfarm)
991 yield "".join(page.render_text(myself))
993 start_response('200 OK', [
994 ('Content-type', 'text/html; charset=utf-8')])
996 tree = get_param(form, "tree")
997 host = get_param(form, "host")
998 compiler = get_param(form, "compiler")
1000 if fn_name == "View_Build":
1001 plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
1002 revision = get_param(form, "revision")
1003 checksum = get_param(form, "checksum")
1005 build = self.buildfarm.get_build(tree, host,
1006 compiler, revision, checksum=checksum)
1007 except NoSuchBuildError:
1008 yield "No such build: %s on %s with %s, rev %r, checksum %r" % (
1009 tree, host, compiler, revision, checksum)
1011 page = ViewBuildPage(self.buildfarm)
1012 plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
1013 yield "".join(self.html_page(form, page.render(myself, build, plain_logs)))
1014 elif fn_name == "View_Host":
1015 page = ViewHostPage(self.buildfarm)
1016 yield "".join(self.html_page(form, page.render_html(myself, get_param(form, 'host'))))
1017 elif fn_name == "Recent_Builds":
1018 page = ViewRecentBuildsPage(self.buildfarm)
1019 yield "".join(self.html_page(form, page.render(myself, get_param(form, "tree"), get_param(form, "sortby") or "age")))
1020 elif fn_name == "Recent_Checkins":
1022 author = get_param(form, 'author')
1023 page = RecentCheckinsPage(self.buildfarm)
1024 yield "".join(self.html_page(form, page.render(myself, tree, author)))
1025 elif fn_name == "diff":
1026 revision = get_param(form, 'revision')
1027 page = DiffPage(self.buildfarm)
1028 yield "".join(self.html_page(form, page.render(myself, tree, revision)))
1029 elif fn_name == "Summary":
1030 page = ViewSummaryPage(self.buildfarm)
1031 yield "".join(self.html_page(form, page.render_html(myself)))
1033 yield "Unknown function %s" % fn_name
1035 fn = wsgiref.util.shift_path_info(environ)
1037 tree = wsgiref.util.shift_path_info(environ)
1038 subfn = wsgiref.util.shift_path_info(environ)
1039 if subfn in ("", None, "+recent"):
1040 start_response('200 OK', [
1041 ('Content-type', 'text/html; charset=utf-8')])
1042 page = ViewRecentBuildsPage(self.buildfarm)
1043 yield "".join(self.html_page(form, page.render(myself, tree, get_param(form, 'sortby') or 'age')))
1044 elif subfn == "+recent-ids":
1045 start_response('200 OK', [
1046 ('Content-type', 'text/plain; charset=utf-8')])
1047 yield "".join([x.log_checksum()+"\n" for x in self.buildfarm.get_tree_builds(tree) if x.has_log()])
1049 start_response('200 OK', [
1050 ('Content-type', 'text/html; charset=utf-8')])
1051 yield "Unknown subfn %s" % subfn
1053 start_response('200 OK', [
1054 ('Content-type', 'text/html; charset=utf-8')])
1055 page = ViewHostPage(self.buildfarm)
1056 yield "".join(self.html_page(form, page.render_html(myself, wsgiref.util.shift_path_info(environ))))
1058 build_checksum = wsgiref.util.shift_path_info(environ)
1060 build = self.buildfarm.builds.get_by_checksum(build_checksum)
1061 except NoSuchBuildError:
1062 start_response('404 Page Not Found', [
1063 ('Content-Type', 'text/html; charset=utf8')])
1064 yield "No build with checksum %s found" % build_checksum
1066 page = ViewBuildPage(self.buildfarm)
1067 subfn = wsgiref.util.shift_path_info(environ)
1068 if subfn == "+plain":
1069 start_response('200 OK', [
1070 ('Content-type', 'text/html; charset=utf-8')])
1071 yield "".join(page.render(myself, build, True))
1072 elif subfn == "+subunit":
1073 start_response('200 OK', [
1074 ('Content-type', 'text/x-subunit; charset=utf-8'),
1075 ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.subunit"' % (build.tree, build.host, build.compiler, build.revision))])
1077 yield build.read_subunit().read()
1078 except NoTestOutput:
1079 yield "There was no test output"
1080 elif subfn == "+stdout":
1081 start_response('200 OK', [
1082 ('Content-type', 'text/plain; charset=utf-8'),
1083 ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.log"' % (build.tree, build.host, build.compiler, build.revision))])
1084 yield build.read_log().read()
1085 elif subfn == "+stderr":
1086 start_response('200 OK', [
1087 ('Content-type', 'text/plain; charset=utf-8'),
1088 ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.err"' % (build.tree, build.host, build.compiler, build.revision))])
1089 yield build.read_err().read()
1090 elif subfn == "+subunit-diff":
1091 start_response('200 OK', [
1092 ('Content-type', 'text/plain; charset=utf-8')])
1093 subunit_this = build.read_subunit().readlines()
1094 other_build_checksum = wsgiref.util.shift_path_info(environ)
1095 other_build = self.buildfarm.builds.get_by_checksum(other_build_checksum)
1096 subunit_other = other_build.read_subunit().readlines()
1098 yield "".join(difflib.unified_diff(subunit_other, subunit_this))
1100 elif subfn in ("", "limit", None):
1101 if subfn == "limit":
1103 limit = int(wsgiref.util.shift_path_info(environ))
1108 start_response('200 OK', [
1109 ('Content-type', 'text/html; charset=utf-8')])
1110 yield "".join(self.html_page(form, page.render(myself, build, False, limit)))
1111 elif fn in ("", None):
1112 start_response('200 OK', [
1113 ('Content-type', 'text/html; charset=utf-8')])
1114 page = ViewSummaryPage(self.buildfarm)
1115 yield "".join(self.html_page(form, page.render_html(myself)))
1117 start_response('404 Page Not Found', [
1118 ('Content-type', 'text/html; charset=utf-8')])
1119 yield "Unknown function %s" % fn
1122 if __name__ == '__main__':
1124 parser = optparse.OptionParser("[options]")
1125 parser.add_option("--port", help="Port to listen on [localhost:8000]",
1126 default="localhost:8000", type=str)
1127 opts, args = parser.parse_args()
1128 from buildfarm import BuildFarm
1129 buildfarm = BuildFarm()
1130 buildApp = BuildFarmApp(buildfarm)
1131 from wsgiref.simple_server import make_server
1135 def standaloneApp(environ, start_response):
1136 if environ['PATH_INFO']:
1137 m = re.match("^/([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)?", environ['PATH_INFO'])
1139 static_file = os.path.join(webdir, m.group(1)+m.group(2))
1140 if os.path.exists(static_file):
1141 type = mimetypes.types_map[m.group(2)]
1142 start_response('200 OK', [('Content-type', type)])
1143 data = open(static_file, 'rb').read()
1146 yield "".join(buildApp(environ, start_response))
1148 (address, port) = opts.port.rsplit(":", 1)
1150 address = "localhost"
1152 httpd = make_server(address, int(port), standaloneApp)
1153 print "Serving on %s:%d..." % (address, int(port))
1154 httpd.serve_forever()