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_testsuite(self, m):
207 testName = m.group(1)
209 status = subunit_to_buildfarm_result(m.group(3))
211 errorReason = format_subunit_reason(m.group(4))
215 return "".join(make_collapsible_html('test', testName, content+errorReason, self.indice, status))
217 def _format_test(self, m):
219 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))))
221 def pretty_print(self, log):
222 # do some pretty printing for the actions
223 pattern = re.compile("(Running action\s+([\w\-]+)$(?:\s^.*$)*?\sACTION\ (PASSED|FAILED):\ ([\w\-]+)$)", re.M)
224 log = pattern.sub(self._pretty_print, log)
227 --==--==--==--==--==--==--==--==--==--==--.*?
228 Running\ test\ ([\w\-=,_:\ /.&;]+).*?
229 --==--==--==--==--==--==--==--==--==--==--
231 ==========================================.*?
232 TEST\ (FAILED|PASSED|SKIPPED):.*?
233 ==========================================\s+
234 """, self._format_stage, log)
236 log = re.sub("skip-testsuite: ([\w\-=,_:\ /.&; \(\)]+).*?",
237 self._format_skip_testsuite, log)
239 pattern = re.compile("^testsuite: (.+)$\s((?:^.*$\s)*?)testsuite-(\w+): .*?(?:(\[$\s(?:^.*$\s)*?^\]$)|$)", re.M)
240 log = pattern.sub(self._format_testsuite, log)
242 ^test: ([\w\-=,_:\ /.&; \(\)]+).*?
244 (success|xfail|failure|skip|uxsuccess): [\w\-=,_:\ /.&; \(\)]+( \[.*?\])?.*?
245 """, self._format_test, log)
247 return "<pre>%s</pre>" % log
250 def print_log_pretty(log):
251 return LogPrettyPrinter().pretty_print(log)
254 def print_log_cc_checker(input):
255 # generate pretty-printed html for static analysis tools
258 # for now, we only handle the IBM Checker's output style
259 if not re.search("^BEAM_VERSION", input):
268 for line in input.splitlines():
269 # for each line, check if the line is a new entry,
270 # otherwise, store the line under the current entry.
272 if line.startswith("-- "):
275 output += "".join(make_collapsible_html('cc_checker', title, content, id, status))
279 # clear maintenance vars
280 (inEntry, content) = (True, "")
283 m = re.match("^-- ((ERROR|WARNING|MISTAKE).*?)\s+>>>([a-zA-Z0-9]+_(\w+)_[a-zA-Z0-9]+)", line)
285 # then store the result
286 (title, status, id) = ("%s %s" % (m.group(1), m.group(4)), m.group(2), m.group(3))
287 elif line.startswith("CC_CHECKER STATUS"):
289 output += "".join(make_collapsible_html('cc_checker', title, content, id, status))
294 # not a new entry, so part of the current entry's output
295 content += "%s\n" % line
299 # This function does approximately the same as the following, following
300 # commented-out regular expression except that the regex doesn't quite
301 # handle IBM Checker's newlines quite right.
303 # --\ ((ERROR|WARNING|MISTAKE).*?)\s+
307 # }{make_collapsible_html('cc_checker', "$1 $4", $5, $3, $2)}exgs
311 def make_collapsible_html(type, title, output, id, status=""):
312 """generate html for a collapsible section
314 :param type: the logical type of it. e.g. "test" or "action"
315 :param title: the title to be displayed
317 if status.lower() in ("", "failed"):
318 icon = '/icon_hide_16.png'
320 icon = '/icon_unhide_16.png'
322 # trim leading and trailing whitespace
323 output = output.strip()
325 # note that we may be inside a <pre>, so we don't put any extra whitespace
327 yield "<div class='%s unit %s' id='%s-%s'>" % (type, status, type, id)
328 yield "<a href=\"javascript:handle('%s');\">" % id
329 yield "<img id='img-%s' name='img-%s' alt='%s' src='%s' />" % (id, id, status, icon)
330 yield "<div class='%s title'>%s</div></a>" % (type, title)
331 yield "<div class='%s status %s'>%s</div>" % (type, status, status)
332 yield "<div class='%s output' id='output-%s'>" % (type, id)
334 yield "<pre>%s</pre>" % (output,)
338 def web_paths(t, paths):
339 """change the given source paths into links"""
343 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)
346 raise Exception("Unknown scm %s" % t.scm)
349 def history_row_text(entry, tree, changes):
350 """show one row of history table"""
351 msg = cgi.escape(entry.message)
352 t = time.asctime(time.gmtime(entry.date))
353 age = util.dhm_time(time.time()-entry.date)
355 yield "Author: %s\n" % entry.author
357 yield "Revision: %s\n" % entry.revision
358 (added, modified, removed) = changes
359 yield "Modified: %s\n" % modified
360 yield "Added: %s\n" % added
361 yield "Removed: %s\n" % removed
362 yield "\n\n%s\n\n\n" % msg
365 class BuildFarmPage(object):
367 def __init__(self, buildfarm):
368 self.buildfarm = buildfarm
370 def red_age(self, age):
371 """show an age as a string"""
372 if age > self.buildfarm.OLDAGE:
373 return "<span class='old'>%s</span>" % util.dhm_time(age)
374 return util.dhm_time(age)
376 def tree_link(self, myself, treename):
378 return tree_link(myself, self.buildfarm.trees[treename])
382 def render(self, output_type):
383 raise NotImplementedError(self.render)
386 class ViewBuildPage(BuildFarmPage):
388 def show_oldrevs(self, myself, build, host, compiler, limit):
389 """show the available old revisions, if any"""
392 old_builds = self.buildfarm.builds.get_old_builds(tree, host, compiler)
397 yield "<h2>Older builds:</h2>\n"
399 yield "<table class='real'>\n"
400 yield "<thead><tr><th>Revision</th><th>Status</th><th>Age</th></tr></thead>\n"
404 for old_build in old_builds:
405 if limit >= 0 and nb >= limit:
408 yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n" % (
409 revision_link(myself, old_build.revision, tree),
410 build_link(myself, old_build),
411 util.dhm_time(old_build.age))
413 yield "</tbody></table>\n"
415 yield "<p><a href='%s/limit/-1'>Show all previous build list</a>\n" % (build_uri(myself, build))
417 def render(self, myself, build, plain_logs=False, limit=10):
418 """view one build in detail"""
430 except LogFileMissing:
439 log = cgi.escape(log)
441 m = re.search("(.*)", log)
444 m = re.search("CFLAGS=(.*)", log)
447 m = re.search("configure options: (.*)", log)
451 err = cgi.escape(err)
452 yield '<h2>Host information:</h2>'
454 host_web_file = "../web/%s.html" % build.host
455 if os.path.exists(host_web_file):
456 yield util.FileLoad(host_web_file)
458 yield "<table class='real'>\n"
459 yield "<tr><td>Host:</td><td><a href='%s?function=View+Host;host=%s;tree=%s;"\
460 "compiler=%s#'>%s</a> - %s</td></tr>\n" %\
461 (myself, build.host, build.tree, build.compiler, build.host, self.buildfarm.hostdb[build.host].platform.encode("utf-8"))
462 if uname is not None:
463 yield "<tr><td>Uname:</td><td>%s</td></tr>\n" % uname
464 yield "<tr><td>Tree:</td><td>%s</td></tr>\n" % self.tree_link(myself, build.tree)
465 yield "<tr><td>Build Revision:</td><td>%s</td></tr>\n" % revision_link(myself, build.revision, build.tree)
466 yield "<tr><td>Build age:</td><td><div class='age'>%s</div></td></tr>\n" % self.red_age(build.age)
467 yield "<tr><td>Status:</td><td>%s</td></tr>\n" % build_link(myself, build)
468 yield "<tr><td>Compiler:</td><td>%s</td></tr>\n" % build.compiler
469 if cflags is not None:
470 yield "<tr><td>CFLAGS:</td><td>%s</td></tr>\n" % cflags
471 if config is not None:
472 yield "<tr><td>configure options:</td><td>%s</td></tr>\n" % config
475 yield "".join(self.show_oldrevs(myself, build, build.host, build.compiler, limit))
477 # check the head of the output for our magic string
480 rev_var = ";revision=%s" % build.revision
482 yield "<div id='log'>"
484 yield "<p><a href='%s/+subunit'>Subunit output</a>" % build_uri(myself, build)
486 previous_build = self.buildfarm.builds.get_previous_build(build.tree, build.host, build.compiler, build.revision)
487 except NoSuchBuildError:
490 yield ", <a href='%s/+subunit-diff/%s'>diff against previous</a>" % (
491 build_uri(myself, build), previous_build.log_checksum())
493 yield "<p><a href='%s/+stdout'>Standard output (as plain text)</a>, " % build_uri(myself, build)
494 yield "<a href='%s/+stderr'>Standard error (as plain text)</a>" % build_uri(myself, build)
498 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s"\
499 ";compiler=%s%s;plain=true' title='Switch to bland, non-javascript,"\
500 " unstyled view'>Plain View</a></p>" % (myself, build.host, build.tree, build.compiler, rev_var)
502 yield "<div id='actionList'>"
503 # These can be pretty wide -- perhaps we need to
504 # allow them to wrap in some way?
506 yield "<h2>No error log available</h2>\n"
508 yield "<h2>Error log:</h2>"
509 yield "".join(make_collapsible_html('action', "Error Output", "\n%s" % err, "stderr-0", "errorlog"))
512 yield "<h2>No build log available</h2>"
514 yield "<h2>Build log:</h2>\n"
515 yield print_log_pretty(log)
517 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>"
520 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s;"\
521 "compiler=%s%s' title='Switch to colourful, javascript-enabled, styled"\
522 " view'>Enhanced View</a></p>" % (myself, build.host, build.tree, build.compiler, rev_var)
524 yield "<h2>No error log available</h2>"
526 yield '<h2>Error log:</h2>\n'
527 yield '<div id="errorLog"><pre>%s</pre></div>' % err
529 yield '<h2>No build log available</h2>'
531 yield '<h2>Build log:</h2>\n'
532 yield '<div id="buildLog"><pre>%s</pre></div>' % log
537 class ViewRecentBuildsPage(BuildFarmPage):
539 def render(self, myself, tree, sort_by=None):
540 """Draw the "recent builds" view"""
543 def build_platform(build):
544 host = self.buildfarm.hostdb[build.host]
545 return host.platform.encode("utf-8")
547 def build_platform_safe(build):
549 host = self.buildfarm.hostdb[build.host]
550 except hostdb.NoSuchHost:
553 return host.platform.encode("utf-8")
556 "revision": lambda a, b: cmp(a.revision, b.revision),
557 "age": lambda a, b: cmp(a.age, b.age),
558 "host": lambda a, b: cmp(a.host, b.host),
559 "platform": lambda a, b: cmp(build_platform_safe(a), build_platform_safe(b)),
560 "compiler": lambda a, b: cmp(a.compiler, b.compiler),
561 "status": lambda a, b: cmp(a.status(), b.status()),
567 if sort_by not in cmp_funcs:
568 yield "not a valid sort mechanism: %r" % sort_by
571 all_builds = list(self.buildfarm.get_tree_builds(tree))
573 all_builds.sort(cmp_funcs[sort_by])
575 t = self.buildfarm.trees[tree]
577 sorturl = "%s?tree=%s;function=Recent+Builds" % (myself, tree)
579 yield "<div id='recent-builds' class='build-section'>"
580 yield "<h2>Recent builds of %s (%s branch %s)</h2>" % (tree, t.scm, t.branch)
581 yield "<table class='real'>"
584 yield "<th><a href='%s;sortby=age' title='Sort by build age'>Age</a></th>" % sorturl
585 yield "<th><a href='%s;sortby=revision' title='Sort by build revision'>Revision</a></th>" % sorturl
586 yield "<th>Tree</th>"
587 yield "<th><a href='%s;sortby=platform' title='Sort by platform'>Platform</a></th>" % sorturl
588 yield "<th><a href='%s;sortby=host' title='Sort by host'>Host</a></th>" % sorturl
589 yield "<th><a href='%s;sortby=compiler' title='Sort by compiler'>Compiler</a></th>" % sorturl
590 yield "<th><a href='%s;sortby=status' title='Sort by status'>Status</a></th>" % sorturl
593 for build in all_builds:
595 build_platform_name = build_platform(build)
597 yield "<td>%s</td>" % util.dhm_time(build.age)
598 yield "<td>%s</td>" % revision_link(myself, build.revision, build.tree)
599 yield "<td>%s</td>" % build.tree
600 yield "<td>%s</td>" % build_platform_name
601 yield "<td>%s</td>" % host_link(myself, build.host)
602 yield "<td>%s</td>" % build.compiler
603 yield "<td>%s</td>" % build_link(myself, build)
605 except hostdb.NoSuchHost:
607 yield "</tbody></table>"
611 class ViewHostPage(BuildFarmPage):
613 def _render_build_list_header(self, host):
614 yield "<div class='host summary'>"
615 yield "<a id='host' name='host'/>"
616 yield "<h3>%s - %s</h3>" % (host.name, host.platform.encode("utf-8"))
617 yield "<table class='real'>"
618 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>"
621 def _render_build_html(self, myself, build):
622 warnings = build.err_count()
624 yield "<td><span class='tree'>" + self.tree_link(myself, build.tree) +"</span>/" + build.compiler + "</td>"
625 yield "<td>" + revision_link(myself, build.revision, build.tree) + "</td>"
626 yield "<td><div class='age'>" + self.red_age(build.age) + "</div></td>"
627 yield "<td><div class='status'>%s</div></td>" % build_link(myself, build)
628 yield "<td>%s</td>" % warnings
631 def render_html(self, myself, *requested_hosts):
632 yield "<div class='build-section' id='build-summary'>"
633 yield '<h2>Host summary:</h2>'
634 for hostname in requested_hosts:
636 host = self.buildfarm.hostdb[hostname]
637 except hostdb.NoSuchHost:
639 builds = list(self.buildfarm.get_host_builds(hostname))
641 yield "".join(self._render_build_list_header(host))
643 yield "".join(self._render_build_html(myself, build))
644 yield "</tbody></table>"
647 deadhosts.append(hostname)
650 yield "".join(self.draw_dead_hosts(*deadhosts))
652 def render_text(self, myself, *requested_hosts):
653 """print the host's table of information"""
654 yield "Host summary:\n"
656 for host in requested_hosts:
657 # make sure we have some data from it
659 self.buildfarm.hostdb[host]
660 except hostdb.NoSuchHost:
663 builds = list(self.buildfarm.get_host_builds(host))
665 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
666 "Tree", "Compiler", "Build Age", "Status", "Warnings")
668 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
669 build.tree, build.compiler,
670 util.dhm_time(build.age),
671 str(build.status()), build.err_count())
674 def draw_dead_hosts(self, *deadhosts):
675 """Draw the "dead hosts" table"""
677 # don't output anything if there are no dead hosts
678 if len(deadhosts) == 0:
681 yield "<div class='build-section' id='dead-hosts'>"
682 yield "<h2>Dead Hosts:</h2>"
683 yield "<table class='real'>"
684 yield "<thead><tr><th>Host</th><th>OS</th><th>Min Age</th></tr></thead>"
687 for host in deadhosts:
688 last_build = self.buildfarm.host_last_build(host)
689 age = time.time() - last_build
691 platform = self.buildfarm.hostdb[host].platform.encode("utf-8")
692 except hostdb.NoSuchHost:
694 yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" %\
695 (host, platform, util.dhm_time(age))
697 yield "</tbody></table>"
701 class ViewSummaryPage(BuildFarmPage):
703 def _get_counts(self):
704 broken_count = defaultdict(lambda: 0)
705 panic_count = defaultdict(lambda: 0)
706 host_count = defaultdict(lambda: 0)
708 # set up a variable to store the broken builds table's code, so we can
709 # output when we want
712 builds = self.buildfarm.get_last_builds()
715 host_count[build.tree]+=1
716 status = build.status()
719 broken_count[build.tree]+=1
720 if "panic" in status.other_failures:
721 panic_count[build.tree]+=1
722 return (host_count, broken_count, panic_count)
724 def render_text(self, myself):
725 (host_count, broken_count, panic_count) = self._get_counts()
726 # for the text report, include the current time
727 yield "Build status as of %s\n\n" % time.asctime()
729 yield "Build counts:\n"
730 yield "%-12s %-6s %-6s %-6s\n" % ("Tree", "Total", "Broken", "Panic")
732 for tree in sorted(self.buildfarm.trees.keys()):
733 yield "%-12s %-6s %-6s %-6s\n" % (tree, host_count[tree],
734 broken_count[tree], panic_count[tree])
737 def render_html(self, myself):
738 """view build summary"""
740 (host_count, broken_count, panic_count) = self._get_counts()
742 yield "<div id='build-counts' class='build-section'>"
743 yield "<h2>Build counts:</h2>"
744 yield "<table class='real'>"
745 yield "<thead><tr><th>Tree</th><th>Total</th><th>Broken</th><th>Panic</th><th>Test coverage</th></tr></thead>"
748 for tree in sorted(self.buildfarm.trees.keys()):
750 yield "<td>%s</td>" % self.tree_link(myself, tree)
751 yield "<td>%s</td>" % host_count[tree]
752 yield "<td>%s</td>" % broken_count[tree]
753 if panic_count[tree]:
754 yield "<td class='panic'>"
757 yield "%d</td>" % panic_count[tree]
760 lcov_status = self.buildfarm.lcov_status(tree)
761 except NoSuchBuildError:
764 if lcov_status is not None:
765 yield "<td><a href=\"/lcov/data/%s/%s\">%s %%</a></td>" % (
766 self.buildfarm.LCOVHOST, tree, lcov_status)
771 unused_fns = self.buildfarm.unused_fns(tree)
772 except NoSuchBuildError:
775 if unused_fns is not None:
776 yield "<td><a href=\"/lcov/data/%s/%s/%s\">Unused Functions</a></td>" % (
777 self.buildfarm.LCOVHOST, tree, unused_fns)
782 yield "</tbody></table>"
786 class HistoryPage(BuildFarmPage):
788 def history_row_html(self, myself, entry, tree, changes):
789 """show one row of history table"""
790 msg = cgi.escape(entry.message)
791 t = time.asctime(time.gmtime(entry.date))
792 age = util.dhm_time(time.time()-entry.date)
794 t = t.replace(" ", " ")
797 <div class=\"history_row\">
798 <div class=\"datetime\">
799 <span class=\"date\">%s</span><br />
800 <span class=\"age\">%s ago</span>""" % (t, age)
802 yield " - <span class=\"revision\">%s</span><br/>" % entry.revision
803 revision_url = "revision=%s" % entry.revision
805 revision_url = "author=%s" % entry.author
808 <span class=\"html\"><a href=\"%s?function=diff;tree=%s;date=%s;%s\">show diffs</a></span>
810 <span class=\"text\"><a href=\"%s?function=text_diff;tree=%s;date=%s;%s\">download diffs</a></span>
812 <div class=\"history_log_message\">
816 <div class=\"author\">
817 <span class=\"label\">Author: </span>%s
818 </div>""" % (myself, tree.name, entry.date, revision_url,
819 myself, tree.name, entry.date, revision_url,
822 (added, modified, removed) = changes
825 yield "<div class=\"files\"><span class=\"label\">Modified: </span>"
826 yield web_paths(tree, modified)
830 yield "<div class=\"files\"><span class=\"label\">Added: </span>"
831 yield web_paths(tree, added)
835 yield "<div class=\"files\"><span class=\"label\">Removed: </span>"
836 yield web_paths(tree, removed)
839 builds = list(self.buildfarm.get_revision_builds(tree.name, entry.revision))
841 yield "<div class=\"builds\">\n"
842 yield "<span class=\"label\">Builds: </span>\n"
844 yield "%s(%s) " % (build_link(myself, build), host_link(myself, build.host))
849 class DiffPage(HistoryPage):
851 def render(self, myself, tree, revision):
853 t = self.buildfarm.trees[tree]
855 yield "Unknown tree %s" % tree
857 branch = t.get_branch()
858 (entry, diff) = branch.diff(revision)
859 # get information about the current diff
860 title = "GIT Diff in %s:%s for revision %s" % (
861 tree, t.branch, revision)
862 yield "<h2>%s</h2>" % title
863 changes = branch.changes_summary(revision)
864 yield "".join(self.history_row_html(myself, entry, t, changes))
865 diff = highlight(diff, DiffLexer(), HtmlFormatter())
866 yield "<pre>%s</pre>\n" % diff.encode("utf-8")
869 class RecentCheckinsPage(HistoryPage):
873 def render(self, myself, tree, author=None):
874 t = self.buildfarm.trees[tree]
876 authors = {"ALL": "ALL"}
877 branch = t.get_branch()
878 re_author = re.compile("^(.*) <(.*)>$")
879 for entry in branch.log(limit=HISTORY_HORIZON):
880 m = re_author.match(entry.author)
881 authors[m.group(2)] = m.group(1)
882 if author in (None, "ALL", m.group(2)):
883 interesting.append(entry)
885 yield "<h2>Recent checkins for %s (%s branch %s)</h2>\n" % (
886 tree, t.scm, t.branch)
887 yield "<form method='GET'>"
888 yield "Select Author: "
889 yield "".join(select(name="author", values=authors, default=author))
890 yield "<input type='submit' name='sub_function' value='Refresh'/>"
891 yield "<input type='hidden' name='tree' value='%s'/>" % tree
892 yield "<input type='hidden' name='function', value='Recent Checkins'/>"
895 for entry in interesting[:self.limit]:
896 changes = branch.changes_summary(entry.revision)
897 yield "".join(self.history_row_html(myself, entry, t, changes))
901 class BuildFarmApp(object):
903 def __init__(self, buildfarm):
904 self.buildfarm = buildfarm
906 def main_menu(self, tree, host, compiler):
909 yield "<form method='GET'>\n"
910 yield "<div id='build-menu'>\n"
912 for h in self.buildfarm.hostdb.hosts():
913 host_dict[h.name] = "%s -- %s" % (h.platform.encode("utf-8"), h.name)
914 yield "".join(select("host", host_dict, default=host))
916 for t in self.buildfarm.trees.values():
917 tree_dict[t.name] = "%s:%s" % (t.name, t.branch)
918 yield "".join(select("tree", tree_dict, default=tree))
919 yield "".join(select("compiler", dict(zip(self.buildfarm.compilers, self.buildfarm.compilers)), default=compiler))
921 yield "<input type='submit' name='function' value='View Build'/>\n"
922 yield "<input type='submit' name='function' value='View Host'/>\n"
923 yield "<input type='submit' name='function' value='Recent Checkins'/>\n"
924 yield "<input type='submit' name='function' value='Summary'/>\n"
925 yield "<input type='submit' name='function' value='Recent Builds'/>\n"
929 def html_page(self, form, lines):
932 yield " <title>samba.org build farm</title>\n"
933 yield " <script language='javascript' src='/build_farm.js'></script>\n"
934 yield " <meta name='keywords' contents='Samba SMB CIFS Build Farm'/>\n"
935 yield " <meta name='description' contents='Home of the Samba Build Farm, the automated testing facility.'/>\n"
936 yield " <meta name='robots' contents='noindex'/>"
937 yield " <link rel='stylesheet' href='/build_farm.css' type='text/css' media='all'/>"
938 yield " <link rel='stylesheet' href='http://www.samba.org/samba/style/common.css' type='text/css' media='all'/>"
939 yield " <link rel='shortcut icon' href='http://www.samba.org/samba/images/favicon.ico'/>"
943 yield util.FileLoad(os.path.join(webdir, "header2.html"))
945 tree = get_param(form, "tree")
946 host = get_param(form, "host")
947 compiler = get_param(form, "compiler")
948 yield "".join(self.main_menu(tree, host, compiler))
949 yield util.FileLoad(os.path.join(webdir, "header3.html"))
951 yield util.FileLoad(os.path.join(webdir, "footer.html"))
955 def __call__(self, environ, start_response):
956 form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
957 fn_name = get_param(form, 'function') or ''
958 myself = wsgiref.util.application_uri(environ)
960 if fn_name == 'text_diff':
961 start_response('200 OK', [('Content-type', 'application/x-diff')])
962 tree = get_param(form, 'tree')
963 t = self.buildfarm.trees[tree]
964 branch = t.get_branch()
965 revision = get_param(form, 'revision')
966 (entry, diff) = branch.diff(revision)
967 changes = branch.changes_summary(revision)
968 yield "".join(history_row_text(entry, tree, changes))
970 elif fn_name == 'Text_Summary':
971 start_response('200 OK', [('Content-type', 'text/plain')])
972 page = ViewSummaryPage(self.buildfarm)
973 yield "".join(page.render_text(myself))
975 start_response('200 OK', [
976 ('Content-type', 'text/html; charset=utf-8')])
978 tree = get_param(form, "tree")
979 host = get_param(form, "host")
980 compiler = get_param(form, "compiler")
982 if fn_name == "View_Build":
983 plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
984 revision = get_param(form, "revision")
985 checksum = get_param(form, "checksum")
987 build = self.buildfarm.get_build(tree, host,
988 compiler, revision, checksum=checksum)
989 except NoSuchBuildError:
990 yield "No such build: %s on %s with %s, rev %r, checksum %r" % (
991 tree, host, compiler, revision, checksum)
993 page = ViewBuildPage(self.buildfarm)
994 plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
995 yield "".join(self.html_page(form, page.render(myself, build, plain_logs)))
996 elif fn_name == "View_Host":
997 page = ViewHostPage(self.buildfarm)
998 yield "".join(self.html_page(form, page.render_html(myself, get_param(form, 'host'))))
999 elif fn_name == "Recent_Builds":
1000 page = ViewRecentBuildsPage(self.buildfarm)
1001 yield "".join(self.html_page(form, page.render(myself, get_param(form, "tree"), get_param(form, "sortby") or "age")))
1002 elif fn_name == "Recent_Checkins":
1004 author = get_param(form, 'author')
1005 page = RecentCheckinsPage(self.buildfarm)
1006 yield "".join(self.html_page(form, page.render(myself, tree, author)))
1007 elif fn_name == "diff":
1008 revision = get_param(form, 'revision')
1009 page = DiffPage(self.buildfarm)
1010 yield "".join(self.html_page(form, page.render(myself, tree, revision)))
1011 elif fn_name == "Summary":
1012 page = ViewSummaryPage(self.buildfarm)
1013 yield "".join(self.html_page(form, page.render_html(myself)))
1015 yield "Unknown function %s" % fn_name
1017 fn = wsgiref.util.shift_path_info(environ)
1019 tree = wsgiref.util.shift_path_info(environ)
1020 subfn = wsgiref.util.shift_path_info(environ)
1021 if subfn in ("", None, "+recent"):
1022 start_response('200 OK', [
1023 ('Content-type', 'text/html; charset=utf-8')])
1024 page = ViewRecentBuildsPage(self.buildfarm)
1025 yield "".join(self.html_page(form, page.render(myself, tree, get_param(form, 'sortby') or 'age')))
1026 elif subfn == "+recent-ids":
1027 start_response('200 OK', [
1028 ('Content-type', 'text/plain; charset=utf-8')])
1029 yield "".join([x.log_checksum()+"\n" for x in self.buildfarm.get_tree_builds(tree) if x.has_log()])
1031 start_response('200 OK', [
1032 ('Content-type', 'text/html; charset=utf-8')])
1033 yield "Unknown subfn %s" % subfn
1035 start_response('200 OK', [
1036 ('Content-type', 'text/html; charset=utf-8')])
1037 page = ViewHostPage(self.buildfarm)
1038 yield "".join(self.html_page(form, page.render_html(myself, wsgiref.util.shift_path_info(environ))))
1040 build_checksum = wsgiref.util.shift_path_info(environ)
1042 build = self.buildfarm.builds.get_by_checksum(build_checksum)
1043 except NoSuchBuildError:
1044 start_response('404 Page Not Found', [
1045 ('Content-Type', 'text/html; charset=utf8')])
1046 yield "No build with checksum %s found" % build_checksum
1048 page = ViewBuildPage(self.buildfarm)
1049 subfn = wsgiref.util.shift_path_info(environ)
1050 if subfn == "+plain":
1051 start_response('200 OK', [
1052 ('Content-type', 'text/html; charset=utf-8')])
1053 yield "".join(page.render(myself, build, True))
1054 elif subfn == "+subunit":
1055 start_response('200 OK', [
1056 ('Content-type', 'text/x-subunit; charset=utf-8'),
1057 ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.subunit"' % (build.tree, build.host, build.compiler, build.revision))])
1059 yield build.read_subunit().read()
1060 except NoTestOutput:
1061 yield "There was no test output"
1062 elif subfn == "+stdout":
1063 start_response('200 OK', [
1064 ('Content-type', 'text/plain; charset=utf-8'),
1065 ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.log"' % (build.tree, build.host, build.compiler, build.revision))])
1066 yield build.read_log().read()
1067 elif subfn == "+stderr":
1068 start_response('200 OK', [
1069 ('Content-type', 'text/plain; charset=utf-8'),
1070 ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.err"' % (build.tree, build.host, build.compiler, build.revision))])
1071 yield build.read_err().read()
1072 elif subfn == "+subunit-diff":
1073 start_response('200 OK', [
1074 ('Content-type', 'text/plain; charset=utf-8')])
1075 subunit_this = build.read_subunit().readlines()
1076 other_build_checksum = wsgiref.util.shift_path_info(environ)
1077 other_build = self.buildfarm.builds.get_by_checksum(other_build_checksum)
1078 subunit_other = other_build.read_subunit().readlines()
1080 yield "".join(difflib.unified_diff(subunit_other, subunit_this))
1082 elif subfn in ("", "limit", None):
1083 if subfn == "limit":
1085 limit = int(wsgiref.util.shift_path_info(environ))
1090 start_response('200 OK', [
1091 ('Content-type', 'text/html; charset=utf-8')])
1092 yield "".join(self.html_page(form, page.render(myself, build, False, limit)))
1093 elif fn in ("", None):
1094 start_response('200 OK', [
1095 ('Content-type', 'text/html; charset=utf-8')])
1096 page = ViewSummaryPage(self.buildfarm)
1097 yield "".join(self.html_page(form, page.render_html(myself)))
1099 start_response('404 Page Not Found', [
1100 ('Content-type', 'text/html; charset=utf-8')])
1101 yield "Unknown function %s" % fn
1104 if __name__ == '__main__':
1106 parser = optparse.OptionParser("[options]")
1107 parser.add_option("--port", help="Port to listen on [localhost:8000]",
1108 default="localhost:8000", type=str)
1109 opts, args = parser.parse_args()
1110 from buildfarm import BuildFarm
1111 buildfarm = BuildFarm()
1112 buildApp = BuildFarmApp(buildfarm)
1113 from wsgiref.simple_server import make_server
1117 def standaloneApp(environ, start_response):
1118 if environ['PATH_INFO']:
1119 m = re.match("^/([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)?", environ['PATH_INFO'])
1121 static_file = os.path.join(webdir, m.group(1)+m.group(2))
1122 if os.path.exists(static_file):
1123 type = mimetypes.types_map[m.group(2)]
1124 start_response('200 OK', [('Content-type', type)])
1125 data = open(static_file, 'rb').read()
1128 yield "".join(buildApp(environ, start_response))
1130 (address, port) = opts.port.rsplit(":", 1)
1132 address = "localhost"
1134 httpd = make_server(address, int(port), standaloneApp)
1135 print "Serving on %s:%d..." % (address, int(port))
1136 httpd.serve_forever()