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":
174 def format_subunit_reason(reason):
175 reason = re.sub("^\[\n+(.*?)\n+\]$", "\\1", reason)
176 return "<div class=\"reason\">%s</div>" % reason
179 class LogPrettyPrinter(object):
184 def _pretty_print(self, m):
186 actionName = m.group(2)
188 # handle pretty-printing of static-analysis tools
189 if actionName == 'cc_checker':
190 output = print_log_cc_checker(output)
193 return "".join(make_collapsible_html('action', actionName, output, self.indice, status))
195 # log is already CGI-escaped, so handle '>' in test name by handling >
196 def _format_stage(self, m):
198 return "".join(make_collapsible_html('test', m.group(1), m.group(2), self.indice, m.group(3)))
200 def _format_skip_testsuite(self, m):
202 return "".join(make_collapsible_html('test', m.group(1), '', self.indice, 'skipped'))
204 def _format_testsuite(self, m):
205 testName = m.group(1)
207 status = subunit_to_buildfarm_result(m.group(3))
209 errorReason = format_subunit_reason(m.group(4))
213 return "".join(make_collapsible_html('test', testName, content+errorReason, self.indice, status))
215 def _format_test(self, m):
217 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))))
219 def pretty_print(self, log):
220 # do some pretty printing for the actions
221 pattern = re.compile("(Running action\s+([\w\-]+)$(?:\s^.*$)*?\sACTION\ (PASSED|FAILED):\ ([\w\-]+)$)", re.M)
222 log = pattern.sub(self._pretty_print, log)
225 --==--==--==--==--==--==--==--==--==--==--.*?
226 Running\ test\ ([\w\-=,_:\ /.&;]+).*?
227 --==--==--==--==--==--==--==--==--==--==--
229 ==========================================.*?
230 TEST\ (FAILED|PASSED|SKIPPED):.*?
231 ==========================================\s+
232 """, self._format_stage, log)
234 log = re.sub("skip-testsuite: ([\w\-=,_:\ /.&; \(\)]+).*?",
235 self._format_skip_testsuite, log)
237 pattern = re.compile("^testsuite: (.+)$\s((?:^.*$\s)*?)testsuite-(\w+): .*?(?:(\[$\s(?:^.*$\s)*?^\]$)|$)", re.M)
238 log = pattern.sub(self._format_testsuite, log)
240 ^test: ([\w\-=,_:\ /.&; \(\)]+).*?
242 (success|xfail|failure|skip): [\w\-=,_:\ /.&; \(\)]+( \[.*?\])?.*?
243 """, self._format_test, log)
245 return "<pre>%s</pre>" % log
248 def print_log_pretty(log):
249 return LogPrettyPrinter().pretty_print(log)
252 def print_log_cc_checker(input):
253 # generate pretty-printed html for static analysis tools
256 # for now, we only handle the IBM Checker's output style
257 if not re.search("^BEAM_VERSION", input):
266 for line in input.splitlines():
267 # for each line, check if the line is a new entry,
268 # otherwise, store the line under the current entry.
270 if line.startswith("-- "):
273 output += "".join(make_collapsible_html('cc_checker', title, content, id, status))
277 # clear maintenance vars
278 (inEntry, content) = (True, "")
281 m = re.match("^-- ((ERROR|WARNING|MISTAKE).*?)\s+>>>([a-zA-Z0-9]+_(\w+)_[a-zA-Z0-9]+)", line)
283 # then store the result
284 (title, status, id) = ("%s %s" % (m.group(1), m.group(4)), m.group(2), m.group(3))
285 elif line.startswith("CC_CHECKER STATUS"):
287 output += "".join(make_collapsible_html('cc_checker', title, content, id, status))
292 # not a new entry, so part of the current entry's output
293 content += "%s\n" % line
297 # This function does approximately the same as the following, following
298 # commented-out regular expression except that the regex doesn't quite
299 # handle IBM Checker's newlines quite right.
301 # --\ ((ERROR|WARNING|MISTAKE).*?)\s+
305 # }{make_collapsible_html('cc_checker', "$1 $4", $5, $3, $2)}exgs
309 def make_collapsible_html(type, title, output, id, status=""):
310 """generate html for a collapsible section
312 :param type: the logical type of it. e.g. "test" or "action"
313 :param title: the title to be displayed
315 if status.lower() in ("", "failed"):
316 icon = '/icon_hide_16.png'
318 icon = '/icon_unhide_16.png'
320 # trim leading and trailing whitespace
321 output = output.strip()
323 # note that we may be inside a <pre>, so we don't put any extra whitespace
325 yield "<div class='%s unit %s' id='%s-%s'>" % (type, status, type, id)
326 yield "<a href=\"javascript:handle('%s');\">" % id
327 yield "<img id='img-%s' name='img-%s' alt='%s' src='%s' />" % (id, id, status, icon)
328 yield "<div class='%s title'>%s</div></a>" % (type, title)
329 yield "<div class='%s status %s'>%s</div>" % (type, status, status)
330 yield "<div class='%s output' id='output-%s'>" % (type, id)
332 yield "<pre>%s</pre>" % (output,)
336 def web_paths(t, paths):
337 """change the given source paths into links"""
341 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)
344 raise Exception("Unknown scm %s" % t.scm)
347 def history_row_text(entry, tree, changes):
348 """show one row of history table"""
349 msg = cgi.escape(entry.message)
350 t = time.asctime(time.gmtime(entry.date))
351 age = util.dhm_time(time.time()-entry.date)
353 yield "Author: %s\n" % entry.author
355 yield "Revision: %s\n" % entry.revision
356 (added, modified, removed) = changes
357 yield "Modified: %s\n" % modified
358 yield "Added: %s\n" % added
359 yield "Removed: %s\n" % removed
360 yield "\n\n%s\n\n\n" % msg
363 class BuildFarmPage(object):
365 def __init__(self, buildfarm):
366 self.buildfarm = buildfarm
368 def red_age(self, age):
369 """show an age as a string"""
370 if age > self.buildfarm.OLDAGE:
371 return "<span class='old'>%s</span>" % util.dhm_time(age)
372 return util.dhm_time(age)
374 def tree_link(self, myself, treename):
376 return tree_link(myself, self.buildfarm.trees[treename])
380 def render(self, output_type):
381 raise NotImplementedError(self.render)
384 class ViewBuildPage(BuildFarmPage):
386 def show_oldrevs(self, myself, tree, host, compiler):
387 """show the available old revisions, if any"""
388 old_builds = self.buildfarm.builds.get_old_builds(tree, host, compiler)
393 yield "<h2>Older builds:</h2>\n"
395 yield "<table class='real'>\n"
396 yield "<thead><tr><th>Revision</th><th>Status</th><th>Age</th></tr></thead>\n"
399 for old_build in old_builds:
400 yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n" % (
401 revision_link(myself, old_build.revision, tree),
402 build_link(myself, old_build),
403 util.dhm_time(old_build.age))
405 yield "</tbody></table>\n"
407 def render(self, myself, build, plain_logs=False):
408 """view one build in detail"""
420 except LogFileMissing:
429 log = cgi.escape(log)
431 m = re.search("(.*)", log)
434 m = re.search("CFLAGS=(.*)", log)
437 m = re.search("configure options: (.*)", log)
441 err = cgi.escape(err)
442 yield '<h2>Host information:</h2>'
444 host_web_file = "../web/%s.html" % build.host
445 if os.path.exists(host_web_file):
446 yield util.FileLoad(host_web_file)
448 yield "<table class='real'>\n"
449 yield "<tr><td>Host:</td><td><a href='%s?function=View+Host;host=%s;tree=%s;"\
450 "compiler=%s#'>%s</a> - %s</td></tr>\n" %\
451 (myself, build.host, build.tree, build.compiler, build.host, self.buildfarm.hostdb[build.host].platform.encode("utf-8"))
452 if uname is not None:
453 yield "<tr><td>Uname:</td><td>%s</td></tr>\n" % uname
454 yield "<tr><td>Tree:</td><td>%s</td></tr>\n" % self.tree_link(myself, build.tree)
455 yield "<tr><td>Build Revision:</td><td>%s</td></tr>\n" % revision_link(myself, build.revision, build.tree)
456 yield "<tr><td>Build age:</td><td><div class='age'>%s</div></td></tr>\n" % self.red_age(build.age)
457 yield "<tr><td>Status:</td><td>%s</td></tr>\n" % build_link(myself, build)
458 yield "<tr><td>Compiler:</td><td>%s</td></tr>\n" % build.compiler
459 if cflags is not None:
460 yield "<tr><td>CFLAGS:</td><td>%s</td></tr>\n" % cflags
461 if config is not None:
462 yield "<tr><td>configure options:</td><td>%s</td></tr>\n" % config
465 yield "".join(self.show_oldrevs(myself, build.tree, build.host, build.compiler))
467 # check the head of the output for our magic string
470 rev_var = ";revision=%s" % build.revision
472 yield "<div id='log'>"
474 yield "<p><a href='%s/+subunit'>Subunit output</a>" % build_uri(myself, build)
476 previous_build = self.buildfarm.builds.get_previous_build(build.tree, build.host, build.compiler, build.revision)
477 except NoSuchBuildError:
480 yield ", <a href='%s/+subunit-diff/%s'>diff against previous</a>" % (
481 build_uri(myself, build), previous_build.log_checksum())
483 yield "<p><a href='%s/+stdout'>Standard output (as plain text)</a>, " % build_uri(myself, build)
484 yield "<a href='%s/+stderr'>Standard error (as plain text)</a>" % build_uri(myself, build)
488 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s"\
489 ";compiler=%s%s;plain=true' title='Switch to bland, non-javascript,"\
490 " unstyled view'>Plain View</a></p>" % (myself, build.host, build.tree, build.compiler, rev_var)
492 yield "<div id='actionList'>"
493 # These can be pretty wide -- perhaps we need to
494 # allow them to wrap in some way?
496 yield "<h2>No error log available</h2>\n"
498 yield "<h2>Error log:</h2>"
499 yield "".join(make_collapsible_html('action', "Error Output", "\n%s" % err, "stderr-0", "errorlog"))
502 yield "<h2>No build log available</h2>"
504 yield "<h2>Build log:</h2>\n"
505 yield print_log_pretty(log)
507 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>"
510 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s;"\
511 "compiler=%s%s' title='Switch to colourful, javascript-enabled, styled"\
512 " view'>Enhanced View</a></p>" % (myself, build.host, build.tree, build.compiler, rev_var)
514 yield "<h2>No error log available</h2>"
516 yield '<h2>Error log:</h2>\n'
517 yield '<div id="errorLog"><pre>%s</pre></div>' % err
519 yield '<h2>No build log available</h2>'
521 yield '<h2>Build log:</h2>\n'
522 yield '<div id="buildLog"><pre>%s</pre></div>' % log
527 class ViewRecentBuildsPage(BuildFarmPage):
529 def render(self, myself, tree, sort_by=None):
530 """Draw the "recent builds" view"""
533 def build_platform(build):
535 host = self.buildfarm.hostdb[build.host]
536 except hostdb.NoSuchHost:
539 return host.platform.encode("utf-8")
542 "revision": lambda a, b: cmp(a.revision, b.revision),
543 "age": lambda a, b: cmp(a.age, b.age),
544 "host": lambda a, b: cmp(a.host, b.host),
545 "platform": lambda a, b: cmp(build_platform(a), build_platform(b)),
546 "compiler": lambda a, b: cmp(a.compiler, b.compiler),
547 "status": lambda a, b: cmp(a.status(), b.status()),
553 if sort_by not in cmp_funcs:
554 yield "not a valid sort mechanism: %r" % sort_by
557 all_builds = list(self.buildfarm.get_tree_builds(tree))
559 all_builds.sort(cmp_funcs[sort_by])
561 t = self.buildfarm.trees[tree]
563 sorturl = "%s?tree=%s;function=Recent+Builds" % (myself, tree)
565 yield "<div id='recent-builds' class='build-section'>"
566 yield "<h2>Recent builds of %s (%s branch %s)</h2>" % (tree, t.scm, t.branch)
567 yield "<table class='real'>"
570 yield "<th><a href='%s;sortby=age' title='Sort by build age'>Age</a></th>" % sorturl
571 yield "<th><a href='%s;sortby=revision' title='Sort by build revision'>Revision</a></th>" % sorturl
572 yield "<th>Tree</th>"
573 yield "<th><a href='%s;sortby=platform' title='Sort by platform'>Platform</a></th>" % sorturl
574 yield "<th><a href='%s;sortby=host' title='Sort by host'>Host</a></th>" % sorturl
575 yield "<th><a href='%s;sortby=compiler' title='Sort by compiler'>Compiler</a></th>" % sorturl
576 yield "<th><a href='%s;sortby=status' title='Sort by status'>Status</a></th>" % sorturl
579 for build in all_builds:
581 yield "<td>%s</td>" % util.dhm_time(build.age)
582 yield "<td>%s</td>" % revision_link(myself, build.revision, build.tree)
583 yield "<td>%s</td>" % build.tree
584 yield "<td>%s</td>" % build_platform(build)
585 yield "<td>%s</td>" % host_link(myself, build.host)
586 yield "<td>%s</td>" % build.compiler
587 yield "<td>%s</td>" % build_link(myself, build)
589 yield "</tbody></table>"
593 class ViewHostPage(BuildFarmPage):
595 def _render_build_list_header(self, host):
596 yield "<div class='host summary'>"
597 yield "<a id='host' name='host'/>"
598 yield "<h3>%s - %s</h3>" % (host.name, host.platform.encode("utf-8"))
599 yield "<table class='real'>"
600 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>"
603 def _render_build_html(self, myself, build):
604 warnings = build.err_count()
606 yield "<td><span class='tree'>" + self.tree_link(myself, build.tree) +"</span>/" + build.compiler + "</td>"
607 yield "<td>" + revision_link(myself, build.revision, build.tree) + "</td>"
608 yield "<td><div class='age'>" + self.red_age(build.age) + "</div></td>"
609 yield "<td><div class='status'>%s</div></td>" % build_link(myself, build)
610 yield "<td>%s</td>" % warnings
613 def render_html(self, myself, *requested_hosts):
614 yield "<div class='build-section' id='build-summary'>"
615 yield '<h2>Host summary:</h2>'
616 for hostname in requested_hosts:
618 host = self.buildfarm.hostdb[hostname]
619 except hostdb.NoSuchHost:
620 deadhosts.append(hostname)
622 builds = list(self.buildfarm.get_host_builds(hostname))
624 yield "".join(self._render_build_list_header(host))
626 yield "".join(self._render_build_html(myself, build))
627 yield "</tbody></table>"
630 deadhosts.append(hostname)
633 yield "".join(self.draw_dead_hosts(*deadhosts))
635 def render_text(self, myself, *requested_hosts):
636 """print the host's table of information"""
637 yield "Host summary:\n"
639 for host in requested_hosts:
640 # make sure we have some data from it
642 self.buildfarm.hostdb[host]
643 except hostdb.NoSuchHost:
646 builds = list(self.buildfarm.get_host_builds(host))
648 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
649 "Tree", "Compiler", "Build Age", "Status", "Warnings")
651 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
652 build.tree, build.compiler,
653 util.dhm_time(build.age),
654 str(build.status()), build.err_count())
657 def draw_dead_hosts(self, *deadhosts):
658 """Draw the "dead hosts" table"""
660 # don't output anything if there are no dead hosts
661 if len(deadhosts) == 0:
664 yield "<div class='build-section' id='dead-hosts'>"
665 yield "<h2>Dead Hosts:</h2>"
666 yield "<table class='real'>"
667 yield "<thead><tr><th>Host</th><th>OS</th><th>Min Age</th></tr></thead>"
670 for host in deadhosts:
671 last_build = self.buildfarm.host_last_build(host)
672 age = time.time() - last_build
674 platform = self.buildfarm.hostdb[host].platform.encode("utf-8")
675 except hostdb.NoSuchHost:
677 yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" %\
678 (host, platform, util.dhm_time(age))
680 yield "</tbody></table>"
684 class ViewSummaryPage(BuildFarmPage):
686 def _get_counts(self):
687 broken_count = defaultdict(lambda: 0)
688 panic_count = defaultdict(lambda: 0)
689 host_count = defaultdict(lambda: 0)
691 # set up a variable to store the broken builds table's code, so we can
692 # output when we want
695 builds = self.buildfarm.get_last_builds()
698 host_count[build.tree]+=1
699 status = build.status()
702 broken_count[build.tree]+=1
703 if "panic" in status.other_failures:
704 panic_count[build.tree]+=1
705 return (host_count, broken_count, panic_count)
707 def render_text(self, myself):
708 (host_count, broken_count, panic_count) = self._get_counts()
709 # for the text report, include the current time
710 yield "Build status as of %s\n\n" % time.asctime()
712 yield "Build counts:\n"
713 yield "%-12s %-6s %-6s %-6s\n" % ("Tree", "Total", "Broken", "Panic")
715 for tree in sorted(self.buildfarm.trees.keys()):
716 yield "%-12s %-6s %-6s %-6s\n" % (tree, host_count[tree],
717 broken_count[tree], panic_count[tree])
720 def render_html(self, myself):
721 """view build summary"""
723 (host_count, broken_count, panic_count) = self._get_counts()
725 yield "<div id='build-counts' class='build-section'>"
726 yield "<h2>Build counts:</h2>"
727 yield "<table class='real'>"
728 yield "<thead><tr><th>Tree</th><th>Total</th><th>Broken</th><th>Panic</th><th>Test coverage</th></tr></thead>"
731 for tree in sorted(self.buildfarm.trees.keys()):
733 yield "<td>%s</td>" % self.tree_link(myself, tree)
734 yield "<td>%s</td>" % host_count[tree]
735 yield "<td>%s</td>" % broken_count[tree]
736 if panic_count[tree]:
737 yield "<td class='panic'>"
740 yield "%d</td>" % panic_count[tree]
742 lcov_status = self.buildfarm.lcov_status(tree)
743 except NoSuchBuildError:
746 if lcov_status is not None:
747 yield "<td><a href=\"/lcov/data/%s/%s\">%s %%</a></td>" % (
748 self.buildfarm.LCOVHOST, tree, lcov_status)
753 yield "</tbody></table>"
757 class HistoryPage(BuildFarmPage):
759 def history_row_html(self, myself, entry, tree, changes):
760 """show one row of history table"""
761 msg = cgi.escape(entry.message)
762 t = time.asctime(time.gmtime(entry.date))
763 age = util.dhm_time(time.time()-entry.date)
765 t = t.replace(" ", " ")
768 <div class=\"history_row\">
769 <div class=\"datetime\">
770 <span class=\"date\">%s</span><br />
771 <span class=\"age\">%s ago</span>""" % (t, age)
773 yield " - <span class=\"revision\">%s</span><br/>" % entry.revision
774 revision_url = "revision=%s" % entry.revision
776 revision_url = "author=%s" % entry.author
779 <span class=\"html\"><a href=\"%s?function=diff;tree=%s;date=%s;%s\">show diffs</a></span>
781 <span class=\"text\"><a href=\"%s?function=text_diff;tree=%s;date=%s;%s\">download diffs</a></span>
783 <div class=\"history_log_message\">
787 <div class=\"author\">
788 <span class=\"label\">Author: </span>%s
789 </div>""" % (myself, tree.name, entry.date, revision_url,
790 myself, tree.name, entry.date, revision_url,
793 (added, modified, removed) = changes
796 yield "<div class=\"files\"><span class=\"label\">Modified: </span>"
797 yield web_paths(tree, modified)
801 yield "<div class=\"files\"><span class=\"label\">Added: </span>"
802 yield web_paths(tree, added)
806 yield "<div class=\"files\"><span class=\"label\">Removed: </span>"
807 yield web_paths(tree, removed)
810 builds = list(self.buildfarm.get_revision_builds(tree.name, entry.revision))
812 yield "<div class=\"builds\">\n"
813 yield "<span class=\"label\">Builds: </span>\n"
815 yield "%s(%s) " % (build_link(myself, build), host_link(myself, build.host))
820 class DiffPage(HistoryPage):
822 def render(self, myself, tree, revision):
824 t = self.buildfarm.trees[tree]
826 yield "Unknown tree %s" % tree
828 branch = t.get_branch()
829 (entry, diff) = branch.diff(revision)
830 # get information about the current diff
831 title = "GIT Diff in %s:%s for revision %s" % (
832 tree, t.branch, revision)
833 yield "<h2>%s</h2>" % title
834 changes = branch.changes_summary(revision)
835 yield "".join(self.history_row_html(myself, entry, t, changes))
836 diff = highlight(diff, DiffLexer(), HtmlFormatter())
837 yield "<pre>%s</pre>\n" % diff.encode("utf-8")
840 class RecentCheckinsPage(HistoryPage):
844 def render(self, myself, tree, author=None):
845 t = self.buildfarm.trees[tree]
847 authors = {"ALL": "ALL"}
848 branch = t.get_branch()
849 re_author = re.compile("^(.*) <(.*)>$")
850 for entry in branch.log(limit=HISTORY_HORIZON):
851 m = re_author.match(entry.author)
852 authors[m.group(2)] = m.group(1)
853 if author in (None, "ALL", m.group(2)):
854 interesting.append(entry)
856 yield "<h2>Recent checkins for %s (%s branch %s)</h2>\n" % (
857 tree, t.scm, t.branch)
858 yield "<form method='GET'>"
859 yield "Select Author: "
860 yield "".join(select(name="author", values=authors, default=author))
861 yield "<input type='submit' name='sub_function' value='Refresh'/>"
862 yield "<input type='hidden' name='tree' value='%s'/>" % tree
863 yield "<input type='hidden' name='function', value='Recent Checkins'/>"
866 for entry in interesting[:self.limit]:
867 changes = branch.changes_summary(entry.revision)
868 yield "".join(self.history_row_html(myself, entry, t, changes))
872 class BuildFarmApp(object):
874 def __init__(self, buildfarm):
875 self.buildfarm = buildfarm
877 def main_menu(self, tree, host, compiler):
880 yield "<form method='GET'>\n"
881 yield "<div id='build-menu'>\n"
883 for h in self.buildfarm.hostdb.hosts():
884 host_dict[h.name] = "%s -- %s" % (h.platform.encode("utf-8"), h.name)
885 yield "".join(select("host", host_dict, default=host))
887 for t in self.buildfarm.trees.values():
888 tree_dict[t.name] = "%s:%s" % (t.name, t.branch)
889 yield "".join(select("tree", tree_dict, default=tree))
890 yield "".join(select("compiler", dict(zip(self.buildfarm.compilers, self.buildfarm.compilers)), default=compiler))
892 yield "<input type='submit' name='function' value='View Build'/>\n"
893 yield "<input type='submit' name='function' value='View Host'/>\n"
894 yield "<input type='submit' name='function' value='Recent Checkins'/>\n"
895 yield "<input type='submit' name='function' value='Summary'/>\n"
896 yield "<input type='submit' name='function' value='Recent Builds'/>\n"
900 def html_page(self, form, lines):
903 yield " <title>samba.org build farm</title>\n"
904 yield " <script language='javascript' src='/build_farm.js'></script>\n"
905 yield " <meta name='keywords' contents='Samba SMB CIFS Build Farm'/>\n"
906 yield " <meta name='description' contents='Home of the Samba Build Farm, the automated testing facility.'/>\n"
907 yield " <meta name='robots' contents='noindex'/>"
908 yield " <link rel='stylesheet' href='/build_farm.css' type='text/css' media='all'/>"
909 yield " <link rel='stylesheet' href='http://www.samba.org/samba/style/common.css' type='text/css' media='all'/>"
910 yield " <link rel='shortcut icon' href='http://www.samba.org/samba/images/favicon.ico'/>"
914 yield util.FileLoad(os.path.join(webdir, "header2.html"))
916 tree = get_param(form, "tree")
917 host = get_param(form, "host")
918 compiler = get_param(form, "compiler")
919 yield "".join(self.main_menu(tree, host, compiler))
920 yield util.FileLoad(os.path.join(webdir, "header3.html"))
922 yield util.FileLoad(os.path.join(webdir, "footer.html"))
926 def __call__(self, environ, start_response):
927 form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
928 fn_name = get_param(form, 'function') or ''
929 myself = wsgiref.util.application_uri(environ)
931 if fn_name == 'text_diff':
932 start_response('200 OK', [('Content-type', 'application/x-diff')])
933 tree = get_param(form, 'tree')
934 t = self.buildfarm.trees[tree]
935 branch = t.get_branch()
936 revision = get_param(form, 'revision')
937 (entry, diff) = branch.diff(revision)
938 changes = branch.changes_summary(revision)
939 yield "".join(history_row_text(entry, tree, changes))
941 elif fn_name == 'Text_Summary':
942 start_response('200 OK', [('Content-type', 'text/plain')])
943 page = ViewSummaryPage(self.buildfarm)
944 yield "".join(page.render_text(myself))
946 start_response('200 OK', [
947 ('Content-type', 'text/html; charset=utf-8')])
949 tree = get_param(form, "tree")
950 host = get_param(form, "host")
951 compiler = get_param(form, "compiler")
953 if fn_name == "View_Build":
954 plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
955 revision = get_param(form, "revision")
956 checksum = get_param(form, "checksum")
958 build = self.buildfarm.get_build(tree, host,
959 compiler, revision, checksum=checksum)
960 except NoSuchBuildError:
961 yield "No such build: %s on %s with %s, rev %r, checksum %r" % (
962 tree, host, compiler, revision, checksum)
964 page = ViewBuildPage(self.buildfarm)
965 plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
966 yield "".join(self.html_page(form, page.render(myself, build, plain_logs)))
967 elif fn_name == "View_Host":
968 page = ViewHostPage(self.buildfarm)
969 yield "".join(self.html_page(form, page.render_html(myself, get_param(form, 'host'))))
970 elif fn_name == "Recent_Builds":
971 page = ViewRecentBuildsPage(self.buildfarm)
972 yield "".join(self.html_page(form, page.render(myself, get_param(form, "tree"), get_param(form, "sortby") or "age")))
973 elif fn_name == "Recent_Checkins":
975 author = get_param(form, 'author')
976 page = RecentCheckinsPage(self.buildfarm)
977 yield "".join(self.html_page(form, page.render(myself, tree, author)))
978 elif fn_name == "diff":
979 revision = get_param(form, 'revision')
980 page = DiffPage(self.buildfarm)
981 yield "".join(self.html_page(form, page.render(myself, tree, revision)))
982 elif fn_name == "Summary":
983 page = ViewSummaryPage(self.buildfarm)
984 yield "".join(self.html_page(form, page.render_html(myself)))
986 yield "Unknown function %s" % fn_name
988 fn = wsgiref.util.shift_path_info(environ)
990 tree = wsgiref.util.shift_path_info(environ)
991 subfn = wsgiref.util.shift_path_info(environ)
992 if subfn in ("", None, "+recent"):
993 start_response('200 OK', [
994 ('Content-type', 'text/html; charset=utf-8')])
995 page = ViewRecentBuildsPage(self.buildfarm)
996 yield "".join(self.html_page(form, page.render(myself, tree, get_param(form, 'sortby') or 'age')))
997 elif subfn == "+recent-ids":
998 start_response('200 OK', [
999 ('Content-type', 'text/plain; charset=utf-8')])
1000 yield "".join([x.log_checksum()+"\n" for x in self.buildfarm.get_tree_builds(tree) if x.has_log()])
1002 start_response('200 OK', [
1003 ('Content-type', 'text/html; charset=utf-8')])
1004 yield "Unknown subfn %s" % subfn
1006 start_response('200 OK', [
1007 ('Content-type', 'text/html; charset=utf-8')])
1008 page = ViewHostPage(self.buildfarm)
1009 yield "".join(self.html_page(form, page.render_html(myself, wsgiref.util.shift_path_info(environ))))
1011 build_checksum = wsgiref.util.shift_path_info(environ)
1012 build = self.buildfarm.builds.get_by_checksum(build_checksum)
1013 page = ViewBuildPage(self.buildfarm)
1014 subfn = wsgiref.util.shift_path_info(environ)
1015 if subfn == "+plain":
1016 start_response('200 OK', [
1017 ('Content-type', 'text/html; charset=utf-8')])
1018 yield "".join(page.render(myself, build, True))
1019 elif subfn == "+subunit":
1020 start_response('200 OK', [
1021 ('Content-type', 'text/x-subunit; charset=utf-8'),
1022 ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.subunit"' % (build.tree, build.host, build.compiler, build.revision))])
1024 yield build.read_subunit().read()
1025 except NoTestOutput:
1026 yield "There was no test output"
1027 elif subfn == "+stdout":
1028 start_response('200 OK', [
1029 ('Content-type', 'text/plain; charset=utf-8'),
1030 ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.log"' % (build.tree, build.host, build.compiler, build.revision))])
1031 yield build.read_log().read()
1032 elif subfn == "+stderr":
1033 start_response('200 OK', [
1034 ('Content-type', 'text/plain; charset=utf-8'),
1035 ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.err"' % (build.tree, build.host, build.compiler, build.revision))])
1036 yield build.read_err().read()
1037 elif subfn == "+subunit-diff":
1038 start_response('200 OK', [
1039 ('Content-type', 'text/plain; charset=utf-8')])
1040 subunit_this = build.read_subunit().readlines()
1041 other_build_checksum = wsgiref.util.shift_path_info(environ)
1042 other_build = self.buildfarm.builds.get_by_checksum(other_build_checksum)
1043 subunit_other = other_build.read_subunit().readlines()
1045 yield "".join(difflib.unified_diff(subunit_other, subunit_this))
1047 elif subfn in ("", None):
1048 start_response('200 OK', [
1049 ('Content-type', 'text/html; charset=utf-8')])
1050 yield "".join(self.html_page(form, page.render(myself, build, False)))
1051 elif fn in ("", None):
1052 start_response('200 OK', [
1053 ('Content-type', 'text/html; charset=utf-8')])
1054 page = ViewSummaryPage(self.buildfarm)
1055 yield "".join(self.html_page(form, page.render_html(myself)))
1057 start_response('404 Page Not Found', [
1058 ('Content-type', 'text/html; charset=utf-8')])
1059 yield "Unknown function %s" % fn
1062 if __name__ == '__main__':
1064 parser = optparse.OptionParser("[options]")
1065 parser.add_option("--port", help="Port to listen on [localhost:8000]",
1066 default="localhost:8000", type=str)
1067 opts, args = parser.parse_args()
1068 from buildfarm import BuildFarm
1069 buildfarm = BuildFarm()
1070 buildApp = BuildFarmApp(buildfarm)
1071 from wsgiref.simple_server import make_server
1075 def standaloneApp(environ, start_response):
1076 if environ['PATH_INFO']:
1077 m = re.match("^/([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)?", environ['PATH_INFO'])
1079 static_file = os.path.join(webdir, m.group(1)+m.group(2))
1080 if os.path.exists(static_file):
1081 type = mimetypes.types_map[m.group(2)]
1082 start_response('200 OK', [('Content-type', type)])
1083 data = open(static_file, 'rb').read()
1086 yield "".join(buildApp(environ, start_response))
1088 (address, port) = opts.port.rsplit(":", 1)
1090 address = "localhost"
1092 httpd = make_server(address, int(port), standaloneApp)
1093 print "Serving on %s:%d..." % (address, int(port))
1094 httpd.serve_forever()