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-2012
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 = "https://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))
220 if m.group(3) in ("error", "failure"):
221 self.test_links.append([testName, 'lnk-test-%d' %self.indice])
222 backlink = "<p><a href='#shortcut2errors'>back to error list</a>"
223 return "".join(make_collapsible_html('test', testName, content+errorReason+backlink, self.indice, status))
225 def _format_test(self, m):
227 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))))
229 def pretty_print(self, log):
230 # do some pretty printing for the actions
231 pattern = re.compile("(Running action\s+([\w\-]+)$(?:\s^.*$)*?\sACTION\ (PASSED|FAILED):\ ([\w\-]+)$)", re.M)
232 log = pattern.sub(self._pretty_print, log)
236 --==--==--==--==--==--==--==--==--==--==--.*?
237 Running\ test\ ([\w\-=,_:\ /.&;]+).*?
238 --==--==--==--==--==--==--==--==--==--==--
240 ==========================================.*?
241 TEST\ (FAILED|PASSED|SKIPPED):.*?
242 ==========================================\s+
243 """, self._format_stage, log)
245 pattern = re.compile("(Running action test).*$\s((?:^.*$\s)*?)^((?:skip-)?testsuite: )", re.M)
246 log = pattern.sub(self._format_pretestsuite, log)
248 log = re.sub("skip-testsuite: ([\w\-=,_:\ /.&; \(\)]+).*?",
249 self._format_skip_testsuite, log)
252 pattern = re.compile("^testsuite: (.+)$\s((?:^.*$\s)*?)testsuite-(\w+): .*?(?:(\[$\s(?:^.*$\s)*?^\]$)|$)", re.M)
253 log = pattern.sub(self._format_testsuite, log)
255 ^test: ([\w\-=,_:\ /.&; \(\)]+).*?
257 (success|xfail|failure|skip|uxsuccess): [\w\-=,_:\ /.&; \(\)]+( \[.*?\])?.*?
258 """, self._format_test, log)
260 for tst in self.test_links:
261 buf = "%s\n<A href='#%s'>%s</A>" % (buf, tst[1], tst[0])
264 divhtml = "".join(make_collapsible_html('testlinks', 'Shortcut to failed tests', "<a name='shortcut2errors'></a>%s" % buf, self.indice, ""))+"\n"
265 log = re.sub("Running action\s+test", divhtml, log)
266 return "<pre>%s</pre>" % log
269 def print_log_pretty(log):
270 return LogPrettyPrinter().pretty_print(log)
273 def print_log_cc_checker(input):
274 # generate pretty-printed html for static analysis tools
277 # for now, we only handle the IBM Checker's output style
278 if not re.search("^BEAM_VERSION", input):
287 for line in input.splitlines():
288 # for each line, check if the line is a new entry,
289 # otherwise, store the line under the current entry.
291 if line.startswith("-- "):
294 output += "".join(make_collapsible_html('cc_checker', title, content, id, status))
298 # clear maintenance vars
299 (inEntry, content) = (True, "")
302 m = re.match("^-- ((ERROR|WARNING|MISTAKE).*?)\s+>>>([a-zA-Z0-9]+_(\w+)_[a-zA-Z0-9]+)", line)
304 # then store the result
305 (title, status, id) = ("%s %s" % (m.group(1), m.group(4)), m.group(2), m.group(3))
306 elif line.startswith("CC_CHECKER STATUS"):
308 output += "".join(make_collapsible_html('cc_checker', title, content, id, status))
313 # not a new entry, so part of the current entry's output
314 content += "%s\n" % line
318 # This function does approximately the same as the following, following
319 # commented-out regular expression except that the regex doesn't quite
320 # handle IBM Checker's newlines quite right.
322 # --\ ((ERROR|WARNING|MISTAKE).*?)\s+
326 # }{make_collapsible_html('cc_checker', "$1 $4", $5, $3, $2)}exgs
330 def make_collapsible_html(type, title, output, id, status=""):
331 """generate html for a collapsible section
333 :param type: the logical type of it. e.g. "test" or "action"
334 :param title: the title to be displayed
336 if status.lower() in ("", "failed"):
337 icon = '/icon_hide_16.png'
339 icon = '/icon_unhide_16.png'
341 # trim leading and trailing whitespace
342 output = output.strip()
344 # note that we may be inside a <pre>, so we don't put any extra whitespace
346 yield "<div class='%s unit %s' id='%s-%s'>" % (type, status, type, id)
347 yield "<a name='lnk-%s-%s' href=\"javascript:handle('%s');\">" % (type, id, id)
348 yield "<img id='img-%s' name='img-%s' alt='%s' src='%s' />" % (id, id, status, icon)
349 yield "<div class='%s title'>%s</div></a>" % (type, title)
350 yield "<div class='%s status %s'>%s</div>" % (type, status, status)
351 yield "<div class='%s output' id='output-%s'>" % (type, id)
353 yield "<pre>%s</pre>" % (output,)
357 def web_paths(t, paths):
358 """change the given source paths into links"""
362 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)
365 raise Exception("Unknown scm %s" % t.scm)
368 def history_row_text(entry, tree, changes):
369 """show one row of history table"""
370 msg = cgi.escape(entry.message)
371 t = time.asctime(time.gmtime(entry.date))
372 age = util.dhm_time(time.time()-entry.date)
374 yield "Author: %s\n" % entry.author
376 yield "Revision: %s\n" % entry.revision
377 (added, modified, removed) = changes
378 yield "Modified: %s\n" % modified
379 yield "Added: %s\n" % added
380 yield "Removed: %s\n" % removed
381 yield "\n\n%s\n\n\n" % msg
384 class BuildFarmPage(object):
386 def __init__(self, buildfarm):
387 self.buildfarm = buildfarm
389 def red_age(self, age):
390 """show an age as a string"""
391 if age > self.buildfarm.OLDAGE:
392 return "<span class='old'>%s</span>" % util.dhm_time(age)
393 return util.dhm_time(age)
395 def tree_link(self, myself, treename):
397 return tree_link(myself, self.buildfarm.trees[treename])
401 def render(self, output_type):
402 raise NotImplementedError(self.render)
405 class ViewBuildPage(BuildFarmPage):
407 def show_oldrevs(self, myself, build, host, compiler, limit=None):
408 """show the available old revisions, if any"""
411 old_builds = self.buildfarm.builds.get_old_builds(tree, host, compiler)
416 yield "<h2>Older builds:</h2>\n"
418 yield "<table class='real'>\n"
419 yield "<thead><tr><th>Revision</th><th>Status</th><th>Age</th></tr></thead>\n"
422 for old_build in old_builds[:limit]:
423 yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n" % (
424 revision_link(myself, old_build.revision, tree),
425 build_link(myself, old_build),
426 util.dhm_time(old_build.age))
428 yield "</tbody></table>\n"
430 yield "<p><a href='%s/limit/-1'>Show all previous build list</a>\n" % (build_uri(myself, build))
432 def render(self, myself, build, plain_logs=False, limit=10):
433 """view one build in detail"""
445 except LogFileMissing:
454 log = cgi.escape(log)
456 m = re.search("(.*)", log)
459 m = re.search("CFLAGS=(.*)", log)
462 m = re.search("configure options: (.*)", log)
466 err = cgi.escape(err)
467 yield '<h2>Host information:</h2>'
469 host_web_file = "../web/%s.html" % build.host
470 if os.path.exists(host_web_file):
471 yield util.FileLoad(host_web_file)
473 yield "<table class='real'>\n"
474 yield "<tr><td>Host:</td><td><a href='%s?function=View+Host;host=%s;tree=%s;"\
475 "compiler=%s#'>%s</a> - %s</td></tr>\n" %\
476 (myself, build.host, build.tree, build.compiler, build.host, self.buildfarm.hostdb[build.host].platform.encode("utf-8"))
477 if uname is not None:
478 yield "<tr><td>Uname:</td><td>%s</td></tr>\n" % uname
479 yield "<tr><td>Tree:</td><td>%s</td></tr>\n" % self.tree_link(myself, build.tree)
480 yield "<tr><td>Build Revision:</td><td>%s</td></tr>\n" % revision_link(myself, build.revision, build.tree)
481 yield "<tr><td>Build age:</td><td><div class='age'>%s</div></td></tr>\n" % self.red_age(build.age)
482 yield "<tr><td>Status:</td><td>%s</td></tr>\n" % build_link(myself, build)
483 yield "<tr><td>Compiler:</td><td>%s</td></tr>\n" % build.compiler
484 if cflags is not None:
485 yield "<tr><td>CFLAGS:</td><td>%s</td></tr>\n" % cflags
486 if config is not None:
487 yield "<tr><td>configure options:</td><td>%s</td></tr>\n" % config
490 yield "".join(self.show_oldrevs(myself, build, build.host, build.compiler, limit))
492 # check the head of the output for our magic string
495 rev_var = ";revision=%s" % build.revision
497 yield "<div id='log'>"
499 yield "<p><a href='%s/+subunit'>Subunit output</a>" % build_uri(myself, build)
501 previous_build = self.buildfarm.builds.get_previous_build(build.tree, build.host, build.compiler, build.revision)
502 except NoSuchBuildError:
505 yield ", <a href='%s/+subunit-diff/%s'>diff against previous</a>" % (
506 build_uri(myself, build), previous_build.log_checksum())
508 yield "<p><a href='%s/+stdout'>Standard output (as plain text)</a>, " % build_uri(myself, build)
509 yield "<a href='%s/+stderr'>Standard error (as plain text)</a>" % build_uri(myself, build)
513 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s"\
514 ";compiler=%s%s;plain=true' title='Switch to bland, non-javascript,"\
515 " unstyled view'>Plain View</a></p>" % (myself, build.host, build.tree, build.compiler, rev_var)
517 yield "<div id='actionList'>"
518 # These can be pretty wide -- perhaps we need to
519 # allow them to wrap in some way?
521 yield "<h2>No error log available</h2>\n"
523 yield "<h2>Error log:</h2>"
524 yield "".join(make_collapsible_html('action', "Error Output", "\n%s" % err, "stderr-0", "errorlog"))
527 yield "<h2>No build log available</h2>"
529 yield "<h2>Build log:</h2>\n"
530 yield print_log_pretty(log)
532 yield "<p><small>Some of the above icons derived from the <a href='https://www.gnome.org'>Gnome Project</a>'s stock icons.</small></p>"
535 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s;"\
536 "compiler=%s%s' title='Switch to colourful, javascript-enabled, styled"\
537 " view'>Enhanced View</a></p>" % (myself, build.host, build.tree, build.compiler, rev_var)
539 yield "<h2>No error log available</h2>"
541 yield '<h2>Error log:</h2>\n'
542 yield '<div id="errorLog"><pre>%s</pre></div>' % err
544 yield '<h2>No build log available</h2>'
546 yield '<h2>Build log:</h2>\n'
547 yield '<div id="buildLog"><pre>%s</pre></div>' % log
552 class ViewRecentBuildsPage(BuildFarmPage):
554 def render(self, myself, tree, sort_by=None):
555 """Draw the "recent builds" view"""
558 def build_platform(build):
559 host = self.buildfarm.hostdb[build.host]
560 return host.platform.encode("utf-8")
562 def build_platform_safe(build):
564 host = self.buildfarm.hostdb[build.host]
565 except hostdb.NoSuchHost:
568 return host.platform.encode("utf-8")
571 "revision": lambda a, b: cmp(a.revision, b.revision),
572 "age": lambda a, b: cmp(a.age, b.age),
573 "host": lambda a, b: cmp(a.host, b.host),
574 "platform": lambda a, b: cmp(build_platform_safe(a), build_platform_safe(b)),
575 "compiler": lambda a, b: cmp(a.compiler, b.compiler),
576 "status": lambda a, b: cmp(a.status(), b.status()),
582 if sort_by not in cmp_funcs:
583 yield "not a valid sort mechanism: %r" % sort_by
586 all_builds = list(self.buildfarm.get_tree_builds(tree))
588 all_builds.sort(cmp_funcs[sort_by])
590 t = self.buildfarm.trees[tree]
592 sorturl = "%s?tree=%s;function=Recent+Builds" % (myself, tree)
594 yield "<div id='recent-builds' class='build-section'>"
595 yield "<h2>Recent builds of %s (%s branch %s)</h2>" % (tree, t.scm, t.branch)
596 yield "<table class='real'>"
599 yield "<th><a href='%s;sortby=age' title='Sort by build age'>Age</a></th>" % sorturl
600 yield "<th><a href='%s;sortby=revision' title='Sort by build revision'>Revision</a></th>" % sorturl
601 yield "<th>Tree</th>"
602 yield "<th><a href='%s;sortby=platform' title='Sort by platform'>Platform</a></th>" % sorturl
603 yield "<th><a href='%s;sortby=host' title='Sort by host'>Host</a></th>" % sorturl
604 yield "<th><a href='%s;sortby=compiler' title='Sort by compiler'>Compiler</a></th>" % sorturl
605 yield "<th><a href='%s;sortby=status' title='Sort by status'>Status</a></th>" % sorturl
608 for build in all_builds:
610 build_platform_name = build_platform(build)
612 yield "<td>%s</td>" % util.dhm_time(build.age)
613 yield "<td>%s</td>" % revision_link(myself, build.revision, build.tree)
614 yield "<td>%s</td>" % build.tree
615 yield "<td>%s</td>" % build_platform_name
616 yield "<td>%s</td>" % host_link(myself, build.host)
617 yield "<td>%s</td>" % build.compiler
618 yield "<td>%s</td>" % build_link(myself, build)
620 except hostdb.NoSuchHost:
622 yield "</tbody></table>"
626 class ViewHostPage(BuildFarmPage):
628 def _render_build_list_header(self, host):
629 yield "<div class='host summary'>"
630 yield "<a id='host' name='host'/>"
631 yield "<h3>%s - %s</h3>" % (host.name, host.platform.encode("utf-8"))
632 yield "<table class='real'>"
633 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>"
636 def _render_build_html(self, myself, build):
637 warnings = build.err_count()
639 yield "<td><span class='tree'>" + self.tree_link(myself, build.tree) +"</span>/" + build.compiler + "</td>"
640 yield "<td>" + revision_link(myself, build.revision, build.tree) + "</td>"
641 yield "<td><div class='age'>" + self.red_age(build.age) + "</div></td>"
642 yield "<td><div class='status'>%s</div></td>" % build_link(myself, build)
643 yield "<td>%s</td>" % warnings
646 def render_html(self, myself, *requested_hosts):
647 yield "<div class='build-section' id='build-summary'>"
648 yield '<h2>Host summary:</h2>'
649 for hostname in requested_hosts:
651 host = self.buildfarm.hostdb[hostname]
652 except hostdb.NoSuchHost:
654 builds = list(self.buildfarm.get_host_builds(hostname))
656 yield "".join(self._render_build_list_header(host))
658 yield "".join(self._render_build_html(myself, build))
659 yield "</tbody></table>"
662 deadhosts.append(hostname)
665 yield "".join(self.draw_dead_hosts(*deadhosts))
667 def render_text(self, myself, *requested_hosts):
668 """print the host's table of information"""
669 yield "Host summary:\n"
671 for host in requested_hosts:
672 # make sure we have some data from it
674 self.buildfarm.hostdb[host]
675 except hostdb.NoSuchHost:
678 builds = list(self.buildfarm.get_host_builds(host))
680 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
681 "Tree", "Compiler", "Build Age", "Status", "Warnings")
683 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
684 build.tree, build.compiler,
685 util.dhm_time(build.age),
686 str(build.status()), build.err_count())
689 def draw_dead_hosts(self, *deadhosts):
690 """Draw the "dead hosts" table"""
692 # don't output anything if there are no dead hosts
693 if len(deadhosts) == 0:
696 yield "<div class='build-section' id='dead-hosts'>"
697 yield "<h2>Dead Hosts:</h2>"
698 yield "<table class='real'>"
699 yield "<thead><tr><th>Host</th><th>OS</th><th>Min Age</th></tr></thead>"
702 for host in deadhosts:
703 last_build = self.buildfarm.host_last_build(host)
704 age = time.time() - last_build
706 platform = self.buildfarm.hostdb[host].platform.encode("utf-8")
707 except hostdb.NoSuchHost:
709 yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" %\
710 (host, platform, util.dhm_time(age))
712 yield "</tbody></table>"
716 class ViewSummaryPage(BuildFarmPage):
718 def _get_counts(self):
719 broken_count = defaultdict(lambda: 0)
720 panic_count = defaultdict(lambda: 0)
721 host_count = defaultdict(lambda: 0)
723 # set up a variable to store the broken builds table's code, so we can
724 # output when we want
727 builds = self.buildfarm.get_last_builds()
730 host_count[build.tree]+=1
731 status = build.status()
734 broken_count[build.tree]+=1
735 if "panic" in status.other_failures:
736 panic_count[build.tree]+=1
737 return (host_count, broken_count, panic_count)
739 def render_text(self, myself):
740 (host_count, broken_count, panic_count) = self._get_counts()
741 # for the text report, include the current time
742 yield "Build status as of %s\n\n" % time.asctime()
744 yield "Build counts:\n"
745 yield "%-12s %-6s %-6s %-6s\n" % ("Tree", "Total", "Broken", "Panic")
747 for tree in sorted(self.buildfarm.trees.keys()):
748 yield "%-12s %-6s %-6s %-6s\n" % (tree, host_count[tree],
749 broken_count[tree], panic_count[tree])
752 def render_html(self, myself):
753 """view build summary"""
755 (host_count, broken_count, panic_count) = self._get_counts()
757 yield "<div id='build-counts' class='build-section'>"
758 yield "<h2>Build counts:</h2>"
759 yield "<table class='real'>"
760 yield "<thead><tr><th>Tree</th><th>Total</th><th>Broken</th><th>Panic</th><th>Test coverage</th></tr></thead>"
763 for tree in sorted(self.buildfarm.trees.keys()):
765 yield "<td>%s</td>" % self.tree_link(myself, tree)
766 yield "<td>%s</td>" % host_count[tree]
767 yield "<td>%s</td>" % broken_count[tree]
768 if panic_count[tree]:
769 yield "<td class='panic'>"
772 yield "%d</td>" % panic_count[tree]
775 lcov_status = self.buildfarm.lcov_status(tree)
776 except NoSuchBuildError:
779 if lcov_status is not None:
780 yield "<td><a href=\"/lcov/data/%s/%s\">%s %%</a></td>" % (
781 self.buildfarm.LCOVHOST, tree, lcov_status)
786 unused_fns = self.buildfarm.unused_fns(tree)
787 except NoSuchBuildError:
790 if unused_fns is not None:
791 yield "<td><a href=\"/lcov/data/%s/%s/%s\">Unused Functions</a></td>" % (
792 self.buildfarm.LCOVHOST, tree, unused_fns)
797 yield "</tbody></table>"
801 class HistoryPage(BuildFarmPage):
803 def history_row_html(self, myself, entry, tree, changes):
804 """show one row of history table"""
805 msg = cgi.escape(entry.message)
806 t = time.asctime(time.gmtime(entry.date))
807 age = util.dhm_time(time.time()-entry.date)
809 t = t.replace(" ", " ")
812 <div class=\"history_row\">
813 <div class=\"datetime\">
814 <span class=\"date\">%s</span><br />
815 <span class=\"age\">%s ago</span>""" % (t, age)
817 yield " - <span class=\"revision\">%s</span><br/>" % entry.revision
818 revision_url = "revision=%s" % entry.revision
820 revision_url = "author=%s" % entry.author
823 <span class=\"html\"><a href=\"%s?function=diff;tree=%s;date=%s;%s\">show diffs</a></span>
825 <span class=\"text\"><a href=\"%s?function=text_diff;tree=%s;date=%s;%s\">download diffs</a></span>
827 <div class=\"history_log_message\">
831 <div class=\"author\">
832 <span class=\"label\">Author: </span>%s
833 </div>""" % (myself, tree.name, entry.date, revision_url,
834 myself, tree.name, entry.date, revision_url,
837 (added, modified, removed) = changes
840 yield "<div class=\"files\"><span class=\"label\">Modified: </span>"
841 yield web_paths(tree, modified)
845 yield "<div class=\"files\"><span class=\"label\">Added: </span>"
846 yield web_paths(tree, added)
850 yield "<div class=\"files\"><span class=\"label\">Removed: </span>"
851 yield web_paths(tree, removed)
854 builds = list(self.buildfarm.get_revision_builds(tree.name, entry.revision))
856 yield "<div class=\"builds\">\n"
857 yield "<span class=\"label\">Builds: </span>\n"
859 yield "%s(%s) " % (build_link(myself, build), host_link(myself, build.host))
864 class DiffPage(HistoryPage):
866 def render(self, myself, tree, revision):
868 t = self.buildfarm.trees[tree]
870 yield "Unknown tree %s" % tree
872 branch = t.get_branch()
873 (entry, diff) = branch.diff(revision)
874 # get information about the current diff
875 title = "GIT Diff in %s:%s for revision %s" % (
876 tree, t.branch, revision)
877 yield "<h2>%s</h2>" % title
878 changes = branch.changes_summary(revision)
879 yield "".join(self.history_row_html(myself, entry, t, changes))
880 diff = highlight(diff, DiffLexer(), HtmlFormatter())
881 yield "<pre>%s</pre>\n" % diff.encode("utf-8")
884 class RecentCheckinsPage(HistoryPage):
888 def render(self, myself, tree, author=None):
889 t = self.buildfarm.trees[tree]
891 authors = {"ALL": "ALL"}
892 branch = t.get_branch()
893 re_author = re.compile("^(.*) <(.*)>$")
894 for entry in branch.log(limit=HISTORY_HORIZON):
895 m = re_author.match(entry.author)
896 authors[m.group(2)] = m.group(1)
897 if author in (None, "ALL", m.group(2)):
898 interesting.append(entry)
900 yield "<h2>Recent checkins for %s (%s branch %s)</h2>\n" % (
901 tree, t.scm, t.branch)
902 yield "<form method='GET'>"
903 yield "Select Author: "
904 yield "".join(select(name="author", values=authors, default=author))
905 yield "<input type='submit' name='sub_function' value='Refresh'/>"
906 yield "<input type='hidden' name='tree' value='%s'/>" % tree
907 yield "<input type='hidden' name='function', value='Recent Checkins'/>"
910 for entry in interesting[:self.limit]:
911 changes = branch.changes_summary(entry.revision)
912 yield "".join(self.history_row_html(myself, entry, t, changes))
916 class BuildFarmApp(object):
918 def __init__(self, buildfarm):
919 self.buildfarm = buildfarm
921 def main_menu(self, tree, host, compiler):
924 yield "<form method='GET'>\n"
925 yield "<div id='build-menu'>\n"
927 for h in self.buildfarm.hostdb.hosts():
928 host_dict[h.name] = "%s -- %s" % (h.platform.encode("utf-8"), h.name)
929 yield "".join(select("host", host_dict, default=host))
931 for t in self.buildfarm.trees.values():
932 tree_dict[t.name] = "%s:%s" % (t.name, t.branch)
933 yield "".join(select("tree", tree_dict, default=tree))
934 yield "".join(select("compiler", dict(zip(self.buildfarm.compilers, self.buildfarm.compilers)), default=compiler))
936 yield "<input type='submit' name='function' value='View Build'/>\n"
937 yield "<input type='submit' name='function' value='View Host'/>\n"
938 yield "<input type='submit' name='function' value='Recent Checkins'/>\n"
939 yield "<input type='submit' name='function' value='Summary'/>\n"
940 yield "<input type='submit' name='function' value='Recent Builds'/>\n"
944 def html_page(self, form, lines):
947 yield " <title>samba.org build farm</title>\n"
948 yield " <script language='javascript' src='/build_farm.js'></script>\n"
949 yield " <meta name='keywords' contents='Samba SMB CIFS Build Farm'/>\n"
950 yield " <meta name='description' contents='Home of the Samba Build Farm, the automated testing facility.'/>\n"
951 yield " <meta name='robots' contents='noindex'/>"
952 yield " <link rel='stylesheet' href='/build_farm.css' type='text/css' media='all'/>"
953 yield " <link rel='stylesheet' href='//www.samba.org/samba/style/common.css' type='text/css' media='all'/>"
954 yield " <link rel='shortcut icon' href='//www.samba.org/samba/images/favicon.ico'/>"
958 yield util.FileLoad(os.path.join(webdir, "header2.html"))
960 tree = get_param(form, "tree")
961 host = get_param(form, "host")
962 compiler = get_param(form, "compiler")
963 yield "".join(self.main_menu(tree, host, compiler))
964 yield util.FileLoad(os.path.join(webdir, "header3.html"))
966 yield util.FileLoad(os.path.join(webdir, "footer.html"))
970 def __call__(self, environ, start_response):
971 form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
972 fn_name = get_param(form, 'function') or ''
973 myself = wsgiref.util.application_uri(environ)
975 if fn_name == 'text_diff':
976 start_response('200 OK', [('Content-type', 'application/x-diff')])
977 tree = get_param(form, 'tree')
978 t = self.buildfarm.trees[tree]
979 branch = t.get_branch()
980 revision = get_param(form, 'revision')
981 (entry, diff) = branch.diff(revision)
982 changes = branch.changes_summary(revision)
983 yield "".join(history_row_text(entry, tree, changes))
985 elif fn_name == 'Text_Summary':
986 start_response('200 OK', [('Content-type', 'text/plain')])
987 page = ViewSummaryPage(self.buildfarm)
988 yield "".join(page.render_text(myself))
990 start_response('200 OK', [
991 ('Content-type', 'text/html; charset=utf-8')])
993 tree = get_param(form, "tree")
994 host = get_param(form, "host")
995 compiler = get_param(form, "compiler")
997 if fn_name == "View_Build":
998 plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
999 revision = get_param(form, "revision")
1000 checksum = get_param(form, "checksum")
1002 build = self.buildfarm.get_build(tree, host,
1003 compiler, revision, checksum=checksum)
1004 except NoSuchBuildError:
1005 yield "No such build: %s on %s with %s, rev %r, checksum %r" % (
1006 tree, host, compiler, revision, checksum)
1008 page = ViewBuildPage(self.buildfarm)
1009 plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
1010 yield "".join(self.html_page(form, page.render(myself, build, plain_logs)))
1011 elif fn_name == "View_Host":
1012 page = ViewHostPage(self.buildfarm)
1013 yield "".join(self.html_page(form, page.render_html(myself, get_param(form, 'host'))))
1014 elif fn_name == "Recent_Builds":
1015 page = ViewRecentBuildsPage(self.buildfarm)
1016 yield "".join(self.html_page(form, page.render(myself, get_param(form, "tree"), get_param(form, "sortby") or "age")))
1017 elif fn_name == "Recent_Checkins":
1019 author = get_param(form, 'author')
1020 page = RecentCheckinsPage(self.buildfarm)
1021 yield "".join(self.html_page(form, page.render(myself, tree, author)))
1022 elif fn_name == "diff":
1023 revision = get_param(form, 'revision')
1024 page = DiffPage(self.buildfarm)
1025 yield "".join(self.html_page(form, page.render(myself, tree, revision)))
1026 elif fn_name == "Summary":
1027 page = ViewSummaryPage(self.buildfarm)
1028 yield "".join(self.html_page(form, page.render_html(myself)))
1030 yield "Unknown function %s" % fn_name
1032 fn = wsgiref.util.shift_path_info(environ)
1034 tree = wsgiref.util.shift_path_info(environ)
1035 subfn = wsgiref.util.shift_path_info(environ)
1036 if subfn in ("", None, "+recent"):
1037 start_response('200 OK', [
1038 ('Content-type', 'text/html; charset=utf-8')])
1039 page = ViewRecentBuildsPage(self.buildfarm)
1040 yield "".join(self.html_page(form, page.render(myself, tree, get_param(form, 'sortby') or 'age')))
1041 elif subfn == "+recent-ids":
1042 start_response('200 OK', [
1043 ('Content-type', 'text/plain; charset=utf-8')])
1044 yield "".join([x.log_checksum()+"\n" for x in self.buildfarm.get_tree_builds(tree) if x.has_log()])
1046 start_response('200 OK', [
1047 ('Content-type', 'text/html; charset=utf-8')])
1048 yield "Unknown subfn %s" % subfn
1050 start_response('200 OK', [
1051 ('Content-type', 'text/html; charset=utf-8')])
1052 page = ViewHostPage(self.buildfarm)
1053 yield "".join(self.html_page(form, page.render_html(myself, wsgiref.util.shift_path_info(environ))))
1055 build_checksum = wsgiref.util.shift_path_info(environ)
1057 build = self.buildfarm.builds.get_by_checksum(build_checksum)
1058 except NoSuchBuildError:
1059 start_response('404 Page Not Found', [
1060 ('Content-Type', 'text/html; charset=utf8')])
1061 yield "No build with checksum %s found" % build_checksum
1063 page = ViewBuildPage(self.buildfarm)
1064 subfn = wsgiref.util.shift_path_info(environ)
1065 if subfn == "+plain":
1066 start_response('200 OK', [
1067 ('Content-type', 'text/html; charset=utf-8')])
1068 yield "".join(page.render(myself, build, True))
1069 elif subfn == "+subunit":
1070 start_response('200 OK', [
1071 ('Content-type', 'text/x-subunit; charset=utf-8'),
1072 ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.subunit"' % (build.tree, build.host, build.compiler, build.revision))])
1074 yield build.read_subunit().read()
1075 except NoTestOutput:
1076 yield "There was no test output"
1077 elif subfn == "+stdout":
1078 start_response('200 OK', [
1079 ('Content-type', 'text/plain; charset=utf-8'),
1080 ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.log"' % (build.tree, build.host, build.compiler, build.revision))])
1081 yield build.read_log().read()
1082 elif subfn == "+stderr":
1083 start_response('200 OK', [
1084 ('Content-type', 'text/plain; charset=utf-8'),
1085 ('Content-Disposition', 'attachment; filename="%s.%s.%s-%s.err"' % (build.tree, build.host, build.compiler, build.revision))])
1086 yield build.read_err().read()
1087 elif subfn == "+subunit-diff":
1088 start_response('200 OK', [
1089 ('Content-type', 'text/plain; charset=utf-8')])
1090 subunit_this = build.read_subunit().readlines()
1091 other_build_checksum = wsgiref.util.shift_path_info(environ)
1092 other_build = self.buildfarm.builds.get_by_checksum(other_build_checksum)
1093 subunit_other = other_build.read_subunit().readlines()
1095 yield "".join(difflib.unified_diff(subunit_other, subunit_this))
1097 elif subfn in ("", "limit", None):
1098 if subfn == "limit":
1100 limit = int(wsgiref.util.shift_path_info(environ))
1105 start_response('200 OK', [
1106 ('Content-type', 'text/html; charset=utf-8')])
1107 yield "".join(self.html_page(form, page.render(myself, build, False, limit)))
1108 elif fn in ("", None):
1109 start_response('200 OK', [
1110 ('Content-type', 'text/html; charset=utf-8')])
1111 page = ViewSummaryPage(self.buildfarm)
1112 yield "".join(self.html_page(form, page.render_html(myself)))
1114 start_response('404 Page Not Found', [
1115 ('Content-type', 'text/html; charset=utf-8')])
1116 yield "Unknown function %s" % fn
1119 if __name__ == '__main__':
1121 parser = optparse.OptionParser("[options]")
1122 parser.add_option("--port", help="Port to listen on [localhost:8000]",
1123 default="localhost:8000", type=str)
1124 opts, args = parser.parse_args()
1125 from buildfarm import BuildFarm
1126 buildfarm = BuildFarm()
1127 buildApp = BuildFarmApp(buildfarm)
1128 from wsgiref.simple_server import make_server
1132 def standaloneApp(environ, start_response):
1133 if environ['PATH_INFO']:
1134 m = re.match("^/([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)?", environ['PATH_INFO'])
1136 static_file = os.path.join(webdir, m.group(1)+m.group(2))
1137 if os.path.exists(static_file):
1138 type = mimetypes.types_map[m.group(2)]
1139 start_response('200 OK', [('Content-type', type)])
1140 data = open(static_file, 'rb').read()
1143 yield "".join(buildApp(environ, start_response))
1145 (address, port) = opts.port.rsplit(":", 1)
1147 address = "localhost"
1149 httpd = make_server(address, int(port), standaloneApp)
1150 print "Serving on %s:%d..." % (address, int(port))
1151 httpd.serve_forever()