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 (
44 from pygments import highlight
45 from pygments.lexers.text import DiffLexer
46 from pygments.formatters import HtmlFormatter
51 webdir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "web"))
53 GITWEB_BASE = "http://gitweb.samba.org"
54 HISTORY_HORIZON = 1000
56 # this is automatically filled in
59 def get_param(form, param):
60 """get a param from the request, after sanitizing it"""
64 result = [s.replace(" ", "_") for s in form.getlist(param)]
67 if re.match("[^a-zA-Z0-9\-\_\.]", entry):
68 raise Exception("Parameter %s is invalid" % param)
73 def html_build_status(status):
74 def span(classname, contents):
75 return "<span class=\"%s\">%s</span>" % (classname, contents)
77 def span_status(stage):
78 if stage.name == "CC_CHECKER":
80 return span("status checker", "ok")
82 return span("status checker", stage.result)
84 if stage.result is None:
85 return span("status unknown", "?")
86 elif stage.result == 0:
87 return span("status passed", "ok")
89 return span("status failed", stage.result)
92 if "panic" in status.other_failures:
93 ostatus += "/"+span("status panic", "PANIC")
94 if "disk full" in status.other_failures:
95 ostatus += "/"+span("status failed", "disk full")
96 if "timeout" in status.other_failures:
97 ostatus += "/"+span("status failed", "timeout")
98 if "inconsistent test result" in status.other_failures:
99 ostatus += "/"+span("status failed", "unexpected return code")
100 bstatus = "/".join([span_status(s) for s in status.stages])
103 return bstatus + ostatus
106 def build_status_html(myself, build):
107 return "<a href='%s?function=View+Build;host=%s;tree=%s;compiler=%s;revision=%s;checksum=%s'>%s</a>" % (myself, build.host, build.tree, build.compiler, build.revision, html_build_status(build.status()), build.log_checksum())
110 def build_status_vals(status):
111 """translate a status into a set of int representing status"""
112 status = util.strip_html(status)
114 status = status.replace("ok", "0")
115 status = status.replace("-", "0")
116 status = status.replace("?", "0.1")
117 status = status.replace("PANIC", "1")
119 return status.split("/")
122 def host_link(myself, host):
123 return "<a href='%s?function=View+Host;host=%s'>%s</a>" % (
127 def revision_link(myself, revision, tree):
128 """return a link to a particular revision"""
133 revision = revision.lstrip()
135 if len(revision) == 40:
136 rev_short = re.sub("(^.{7}).*", "\\1(git)", rev_short)
138 return "<a href='%s?function=diff;tree=%s;revision=%s' title='View Diff for %s'>%s</a>" % (myself, tree, revision, revision, rev_short)
141 def subunit_to_buildfarm_result(subunit_result):
142 if subunit_result == "success":
144 elif subunit_result == "error":
146 elif subunit_result == "skip":
148 elif subunit_result == "failure":
150 elif subunit_result == "xfail":
155 def format_subunit_reason(reason):
156 reason = re.sub("^\[\n+(.*?)\n+\]$", "\\1", reason)
157 return "<div class=\"reason\">%s</div>" % reason
160 class LogPrettyPrinter(object):
165 def _pretty_print(self, m):
167 actionName = m.group(2)
169 # handle pretty-printing of static-analysis tools
170 if actionName == 'cc_checker':
171 output = print_log_cc_checker(output)
174 return make_collapsible_html('action', actionName, output, self.indice, status)
176 # log is already CGI-escaped, so handle '>' in test name by handling >
177 def _format_stage(self, m):
179 return make_collapsible_html('test', m.group(1), m.group(2), self.indice, m.group(3))
181 def _format_skip_testsuite(self, m):
183 return make_collapsible_html('test', m.group(1), '', self.indice, 'skipped')
185 def _format_testsuite(self, m):
186 testName = m.group(1)
188 status = subunit_to_buildfarm_result(m.group(3))
190 errorReason = format_subunit_reason(m.group(4))
194 return make_collapsible_html('test', testName, content+errorReason, self.indice, status)
196 def _format_test(self, m):
198 return 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)))
200 def pretty_print(self, log):
201 # do some pretty printing for the actions
202 pattern = re.compile("(Running action\s+([\w\-]+)$(?:\s^.*$)*?\sACTION\ (PASSED|FAILED):\ ([\w\-]+)$)", re.M)
203 log = pattern.sub(self._pretty_print, log)
206 --==--==--==--==--==--==--==--==--==--==--.*?
207 Running\ test\ ([\w\-=,_:\ /.&;]+).*?
208 --==--==--==--==--==--==--==--==--==--==--
210 ==========================================.*?
211 TEST\ (FAILED|PASSED|SKIPPED):.*?
212 ==========================================\s+
213 """, self._format_stage, log)
215 log = re.sub("skip-testsuite: ([\w\-=,_:\ /.&; \(\)]+).*?",
216 self._format_skip_testsuite, log)
218 pattern = re.compile("^testsuite: (.+)$\s((?:^.*$\s)*?)testsuite-(\w+): .*?(?:(\[$\s(?:^.*$\s)*?^\]$)|$)", re.M)
219 log = pattern.sub(self._format_testsuite, log)
221 ^test: ([\w\-=,_:\ /.&; \(\)]+).*?
223 (success|xfail|failure|skip): [\w\-=,_:\ /.&; \(\)]+( \[.*?\])?.*?
224 """, self._format_test, log)
226 return "<pre>%s</pre>" % log
229 def print_log_pretty(log):
230 return LogPrettyPrinter().pretty_print(log)
233 def print_log_cc_checker(input):
234 # generate pretty-printed html for static analysis tools
237 # for now, we only handle the IBM Checker's output style
238 if not re.search("^BEAM_VERSION", input):
247 for line in input.splitlines():
248 # for each line, check if the line is a new entry,
249 # otherwise, store the line under the current entry.
251 if line.startswith("-- "):
254 output += make_collapsible_html('cc_checker', title, content, id, status)
258 # clear maintenance vars
259 (inEntry, content) = (True, "")
262 m = re.match("^-- ((ERROR|WARNING|MISTAKE).*?)\s+>>>([a-zA-Z0-9]+_(\w+)_[a-zA-Z0-9]+)", line)
264 # then store the result
265 (title, status, id) = ("%s %s" % (m.group(1), m.group(4)), m.group(2), m.group(3))
266 elif line.startswith("CC_CHECKER STATUS"):
268 output += make_collapsible_html('cc_checker', title, content, id, status)
273 # not a new entry, so part of the current entry's output
274 content += "%s\n" % line
278 # This function does approximately the same as the following, following
279 # commented-out regular expression except that the regex doesn't quite
280 # handle IBM Checker's newlines quite right.
282 # --\ ((ERROR|WARNING|MISTAKE).*?)\s+
286 # }{make_collapsible_html('cc_checker', "$1 $4", $5, $3, $2)}exgs
290 def make_collapsible_html(type, title, output, id, status=""):
291 """generate html for a collapsible section
293 :param type: the logical type of it. e.g. "test" or "action"
294 :param title: the title to be displayed
296 if ((status == "" or "failed" == status.lower())):
297 icon = 'icon_hide_16.png'
299 icon = 'icon_unhide_16.png'
301 # trim leading and trailing whitespace
302 output = output.strip()
304 # note that we may be inside a <pre>, so we don't put any extra whitespace
306 ret = "<div class='%s unit %s' id='%s-%s'>" % (type, status, type, id)
307 ret += "<a href=\"javascript:handle('%s');\">" % id
308 ret += "<img id='img-%s' name='img-%s' alt='%s' src='%s' />" %(id, id, status, icon)
309 ret += "<div class='%s title'>%s</div></a>" % (type, title)
311 ret += "<div class='%s status %s'>%s</div>" % (type, status, status)
312 ret += "<div class='%s output' id='output-%s'>" % (type, id)
313 if output and len(output):
314 ret += "<pre>%s</pre>>" % (output)
315 ret += "</div></div>"
319 def web_paths(t, paths):
320 """change the given source paths into links"""
324 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)
327 raise Exception("Unknown scm %s" % t.scm)
330 def history_row_html(myself, entry, tree, changes):
331 """show one row of history table"""
332 msg = cgi.escape(entry.message)
333 t = time.asctime(time.gmtime(entry.date))
334 age = util.dhm_time(time.time()-entry.date)
336 t = t.replace(" ", " ")
339 <div class=\"history_row\">
340 <div class=\"datetime\">
341 <span class=\"date\">%s</span><br />
342 <span class=\"age\">%s ago</span>""" % (t, age)
344 yield " - <span class=\"revision\">%s</span><br/>" % entry.revision
345 revision_url = "revision=%s" % entry.revision
347 revision_url = "author=%s" % entry.author
350 <span class=\"html\"><a href=\"%s?function=diff;tree=%s;date=%s;%s\">show diffs</a></span>
352 <span class=\"text\"><a href=\"%s?function=text_diff;tree=%s;date=%s;%s\">download diffs</a></span>
354 <div class=\"history_log_message\">
358 <div class=\"author\">
359 <span class=\"label\">Author: </span>%s
360 </div>""" % (myself, tree.name, entry.date, revision_url,
361 myself, tree.name, entry.date, revision_url,
364 (added, modified, removed) = changes
367 yield "<div class=\"files\"><span class=\"label\">Modified: </span>"
368 yield web_paths(tree, modified)
372 yield "<div class=\"files\"><span class=\"label\">Added: </span>"
373 yield web_paths(tree, added)
377 yield "<div class=\"files\"><span class=\"label\">Removed: </span>"
378 yield web_paths(tree, removed)
384 def history_row_text(entry, tree, changes):
385 """show one row of history table"""
386 msg = cgi.escape(entry.message)
387 t = time.asctime(time.gmtime(entry.date))
388 age = util.dhm_time(time.time()-entry.date)
390 yield "Author: %s\n" % entry.author
392 yield "Revision: %s\n" % entry.revision
393 (added, modified, removed) = changes
394 yield "Modified: %s\n" % modified
395 yield "Added: %s\n" % added
396 yield "Removed: %s\n" % removed
397 yield "\n\n%s\n\n\n" % msg
400 class BuildFarmPage(object):
402 def __init__(self, buildfarm):
403 self.buildfarm = buildfarm
405 def red_age(self, age):
406 """show an age as a string"""
407 if age > self.buildfarm.OLDAGE:
408 return "<span clsas='old'>%s</span>" % util.dhm_time(age)
409 return util.dhm_time(age)
411 def tree_link(self, myself, tree):
412 # return a link to a particular tree
414 if tree in self.buildfarm.trees:
415 branch = ":%s" % self.buildfarm.trees[tree].branch
417 return "<a href='%s?function=Recent+Builds;tree=%s' title='View recent builds for %s'>%s%s</a>" % (myself, tree, tree, tree, branch)
419 def render(self, output_type):
420 raise NotImplementedError(self.render)
423 class ViewBuildPage(BuildFarmPage):
425 def show_oldrevs(self, myself, tree, host, compiler):
426 """show the available old revisions, if any"""
427 old_rev_builds = self.buildfarm.builds.get_old_revs(tree, host, compiler)
429 if not old_rev_builds:
432 yield "<h2>Older builds:</h2>\n"
434 yield "<table class='real'>\n"
435 yield "<thead><tr><th>Revision</th><th>Status</th></tr></thead>\n"
438 for build in old_rev_builds:
439 yield "<tr><td>%s</td><td>%s</td></tr>\n" % (
440 revision_link(myself, build.revision, tree),
441 build_status_html(myself, build))
443 yield "</tbody></table>\n"
445 def render(self, myself, tree, host, compiler, rev, checksum=None,
447 """view one build in detail"""
453 build = self.buildfarm.get_build(tree, host, compiler, rev,
455 except data.NoSuchBuildError:
456 yield "No such build: %s on %s with %s, rev %r, checksum %r" % (
457 tree, host, compiler, rev, checksum)
460 (revision, revision_time) = build.revision_details()
461 except data.MissingRevisionInfo:
470 except data.LogFileMissing:
479 log = cgi.escape(log)
481 m = re.search("(.*)", log)
484 m = re.search("CFLAGS=(.*)", log)
487 m = re.search("configure options: (.*)", log)
492 err = cgi.escape(err)
493 yield '<h2>Host information:</h2>'
495 host_web_file = "../web/%s.html" % host
496 if os.path.exists(host_web_file):
497 yield util.FileLoad(host_web_file)
499 yield "<table class='real'>\n"
500 yield "<tr><td>Host:</td><td><a href='%s?function=View+Host;host=%s;tree=%s;"\
501 "compiler=%s#'>%s</a> - %s</td></tr>\n" %\
502 (myself, host, tree, compiler, host, self.buildfarm.hostdb[host].platform.encode("utf-8"))
503 if uname is not None:
504 yield "<tr><td>Uname:</td><td>%s</td></tr>\n" % uname
505 yield "<tr><td>Tree:</td><td>%s</td></tr>\n" % self.tree_link(myself, tree)
506 yield "<tr><td>Build Revision:</td><td>%s</td></tr>\n" % revision_link(myself, revision, tree)
507 yield "<tr><td>Build age:</td><td><div class='age'>%s</div></td></tr>\n" % self.red_age(build.age)
508 yield "<tr><td>Status:</td><td>%s</td></tr>\n" % build_status_html(myself, build)
509 yield "<tr><td>Compiler:</td><td>%s</td></tr>\n" % compiler
510 if cflags is not None:
511 yield "<tr><td>CFLAGS:</td><td>%s</td></tr>\n" % cflags
512 if config is not None:
513 yield "<tr><td>configure options:</td><td>%s</td></tr>\n" % config
516 yield "".join(self.show_oldrevs(myself, tree, host, compiler))
518 # check the head of the output for our magic string
521 rev_var = ";revision=%s" % rev
523 yield "<div id='log'>"
526 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s"\
527 ";compiler=%s%s;plain=true' title='Switch to bland, non-javascript,"\
528 " unstyled view'>Plain View</a></p>" % (myself, host, tree, compiler, rev_var)
530 yield "<div id='actionList'>"
531 # These can be pretty wide -- perhaps we need to
532 # allow them to wrap in some way?
534 yield "<h2>No error log available</h2>\n"
536 yield "<h2>Error log:</h2>"
537 yield make_collapsible_html('action', "Error Output", "\n%s" % err, "stderr-0", "errorlog")
540 yield "<h2>No build log available</h2>"
542 yield "<h2>Build log:</h2>\n"
543 yield print_log_pretty(log)
545 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>"
548 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s;"\
549 "compiler=%s%s' title='Switch to colourful, javascript-enabled, styled"\
550 " view'>Enhanced View</a></p>" % (myself, host, tree, compiler, rev_var)
552 yield "<h2>No error log available</h2>"
554 yield '<h2>Error log:</h2>\n'
555 yield '<div id="errorLog"><pre>%s</pre></div>' % err
557 yield '<h2>No build log available</h2>'
559 yield '<h2>Build log:</h2>\n'
560 yield '<div id="buildLog"><pre>%s</pre></div>' % log
565 class ViewRecentBuildsPage(BuildFarmPage):
567 def render(self, myself, tree, sort_by=None):
568 """Draw the "recent builds" view"""
571 def build_platform(build):
573 host = self.buildfarm.hostdb[build.host]
574 except hostdb.NoSuchHost:
577 return host.platform.encode("utf-8")
580 "revision": lambda a, b: cmp(a.revision, b.revision),
581 "age": lambda a, b: cmp(a.age, b.age),
582 "host": lambda a, b: cmp(a.host, b.host),
583 "platform": lambda a, b: cmp(build_platform(a), build_platform(b)),
584 "compiler": lambda a, b: cmp(a.compiler, b.compiler),
585 "status": lambda a, b: cmp(a.status(), b.status()),
591 if sort_by not in cmp_funcs:
592 yield "not a valid sort mechanism: %r" % sort_by
595 all_builds = list(self.buildfarm.get_tree_builds(tree))
597 all_builds.sort(cmp_funcs[sort_by])
599 t = self.buildfarm.trees[tree]
601 sorturl = "%s?tree=%s;function=Recent+Builds" % (myself, tree)
603 yield "<div id='recent-builds' class='build-section'>"
604 yield "<h2>Recent builds of %s (%s branch %s)</h2>" % (tree, t.scm, t.branch)
605 yield "<table class='real'>"
608 yield "<th><a href='%s;sortby=age' title='Sort by build age'>Age</a></th>" % sorturl
609 yield "<th><a href='%s;sortby=revision' title='Sort by build revision'>Revision</a></th>" % sorturl
610 yield "<th>Tree</th>"
611 yield "<th><a href='%s;sortby=platform' title='Sort by platform'>Platform</a></th>" % sorturl
612 yield "<th><a href='%s;sortby=host' title='Sort by host'>Host</a></th>" % sorturl
613 yield "<th><a href='%s;sortby=compiler' title='Sort by compiler'>Compiler</a></th>" % sorturl
614 yield "<th><a href='%s;sortby=status' title='Sort by status'>Status</a></th>" % sorturl
617 for build in all_builds:
619 yield "<td>%s</td>" % util.dhm_time(build.age)
620 yield "<td>%s</td>" % revision_link(myself, build.revision, build.tree)
621 yield "<td>%s</td>" % build.tree
622 yield "<td>%s</td>" % build_platform(build)
623 yield "<td>%s</td>" % host_link(myself, build.host)
624 yield "<td>%s</td>" % build.compiler
625 yield "<td>%s</td>" % build_status_html(myself, build)
627 yield "</tbody></table>"
631 class ViewHostPage(BuildFarmPage):
633 def _render_build_list_header(self, host):
634 yield "<div class='host summary'>"
635 yield "<a id='host' name='host'/>"
636 yield "<h3>%s - %s</h3>" % (host.name, host.platform.encode("utf-8"))
637 yield "<table class='real'>"
638 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>"
641 def _render_build_html(self, myself, build):
643 (revision, revision_time) = build.revision_details()
644 except data.MissingRevisionInfo:
646 warnings = build.err_count()
648 yield "<td><span class='tree'>" + self.tree_link(myself, build.tree) +"</span>/" + build.compiler + "</td>"
649 yield "<td>" + revision_link(myself, revision, build.tree) + "</td>"
650 yield "<td><div class='age'>" + self.red_age(build.age) + "</div></td>"
651 yield "<td><div class='status'>%s</div></td>" % build_status_html(myself, build)
652 yield "<td>%s</td>" % warnings
655 def render_html(self, myself, *requested_hosts):
656 yield "<div class='build-section' id='build-summary'>"
657 yield '<h2>Host summary:</h2>'
658 for hostname in requested_hosts:
660 host = self.buildfarm.hostdb[hostname]
661 except hostdb.NoSuchHost:
662 deadhosts.append(hostname)
664 builds = list(self.buildfarm.get_host_builds(hostname))
666 yield "".join(self._render_build_list_header(host))
668 yield "".join(self._render_build_html(myself, build))
669 yield "</tbody></table>"
672 deadhosts.append(hostname)
675 yield "".join(self.draw_dead_hosts(*deadhosts))
677 def render_text(self, myself, *requested_hosts):
678 """print the host's table of information"""
679 yield "Host summary:\n"
681 for host in requested_hosts:
682 # make sure we have some data from it
684 self.buildfarm.hostdb[host]
685 except hostdb.NoSuchHost:
688 builds = list(self.buildfarm.get_host_builds(host))
690 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
691 "Tree", "Compiler", "Build Age", "Status", "Warnings")
693 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
694 build.tree, build.compiler,
695 util.dhm_time(build.age),
696 str(build.status()), build.err_count())
699 def draw_dead_hosts(self, *deadhosts):
700 """Draw the "dead hosts" table"""
702 # don't output anything if there are no dead hosts
703 if len(deadhosts) == 0:
706 yield "<div class='build-section' id='dead-hosts'>"
707 yield "<h2>Dead Hosts:</h2>"
708 yield "<table class='real'>"
709 yield "<thead><tr><th>Host</th><th>OS</th><th>Min Age</th></tr></thead>"
712 for host in deadhosts:
713 last_build = self.buildfarm.host_last_build(host)
714 age = time.time() - last_build
716 platform = self.buildfarm.hostdb[host].platform.encode("utf-8")
717 except hostdb.NoSuchHost:
719 yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" %\
720 (host, platform, util.dhm_time(age))
722 yield "</tbody></table>"
726 class ViewSummaryPage(BuildFarmPage):
728 def _get_counts(self):
729 broken_count = defaultdict(lambda: 0)
730 panic_count = defaultdict(lambda: 0)
731 host_count = defaultdict(lambda: 0)
733 # set up a variable to store the broken builds table's code, so we can
734 # output when we want
737 builds = self.buildfarm.get_last_builds()
740 host_count[build.tree]+=1
741 status = build.status()
744 broken_count[build.tree]+=1
745 if "panic" in status.other_failures:
746 panic_count[build.tree]+=1
747 return (host_count, broken_count, panic_count)
749 def render_text(self, myself):
751 (host_count, broken_count, panic_count) = self._get_counts()
752 # for the text report, include the current time
754 yield "Build status as of %s\n\n" % t
756 yield "Build counts:\n"
757 yield "%-12s %-6s %-6s %-6s\n" % ("Tree", "Total", "Broken", "Panic")
759 for tree in sorted(self.buildfarm.trees.keys()):
760 yield "%-12s %-6s %-6s %-6s\n" % (tree, host_count[tree],
761 broken_count[tree], panic_count[tree])
765 def render_html(self, myself):
766 """view build summary"""
768 (host_count, broken_count, panic_count) = self._get_counts()
770 yield "<div id='build-counts' class='build-section'>"
771 yield "<h2>Build counts:</h2>"
772 yield "<table class='real'>"
773 yield "<thead><tr><th>Tree</th><th>Total</th><th>Broken</th><th>Panic</th><th>Test coverage</th></tr></thead>"
776 for tree in sorted(self.buildfarm.trees.keys()):
778 yield "<td>%s</td>" % self.tree_link(myself, tree)
779 yield "<td>%s</td>" % host_count[tree]
780 yield "<td>%s</td>" % broken_count[tree]
781 if panic_count[tree]:
782 yield "<td class='panic'>"
785 yield "%d</td>" % panic_count[tree]
787 lcov_status = self.buildfarm.lcov_status(tree)
788 except data.NoSuchBuildError:
791 if lcov_status is not None:
792 yield "<td><a href=\"/lcov/data/%s/%s\">%s %%</a></td>" % (
793 self.buildfarm.LCOVHOST, tree, lcov_status)
798 yield "</tbody></table>"
802 class DiffPage(BuildFarmPage):
804 def render(self, myself, tree, revision):
805 t = self.buildfarm.trees[tree]
806 branch = t.get_branch()
807 (entry, diff) = branch.diff(revision)
808 # get information about the current diff
809 title = "GIT Diff in %s:%s for revision %s" % (
810 tree, t.branch, revision)
811 yield "<h2>%s</h2>" % title
812 changes = branch.changes_summary(revision)
813 yield "".join(history_row_html(myself, entry, t, changes))
814 diff = highlight(diff, DiffLexer(), HtmlFormatter())
815 yield "<pre>%s</pre>\n" % diff.encode("utf-8")
818 class RecentCheckinsPage(BuildFarmPage):
822 def render(self, myself, tree, author=None):
823 t = self.buildfarm.trees[tree]
825 authors = {"ALL": "ALL"}
826 branch = t.get_branch()
827 re_author = re.compile("^(.*) <(.*)>$")
828 for entry in branch.log(limit=HISTORY_HORIZON):
829 m = re_author.match(entry.author)
830 authors[m.group(2)] = m.group(1)
831 if author in ("ALL", "", m.group(2)):
832 interesting.append(entry)
834 yield "<h2>Recent checkins for %s (%s branch %s)</h2>\n" % (
835 tree, t.scm, t.branch)
836 yield "<form method='GET'>"
837 yield "Select Author: "
838 yield "<select name='author'>"
839 for email in sorted(authors):
840 yield "<option value='%s'>%s</option>" % (email, authors[email])
842 yield "<input type='submit' name='sub_function' value='Refresh'/>"
843 yield "<input type='hidden' name='tree' value='%s'/>" % tree
844 yield "<input type='hidden' name='function', value='Recent Checkins'/>"
847 for entry in interesting[:self.limit]:
848 changes = branch.changes_summary(entry.revision)
849 yield "".join(history_row_html(myself, entry, t, changes))
853 class BuildFarmApp(object):
855 def __init__(self, buildfarm):
856 self.buildfarm = buildfarm
861 yield "<form method='GET'>\n"
862 yield "<div id='build-menu'>\n"
863 yield "<select name='host'>\n"
864 for host in self.buildfarm.hostdb.hosts():
865 yield "<option value='%s'>%s -- %s</option>\n" % (
866 host.name, host.platform.encode("utf-8"), host.name)
868 yield "<select name='tree'>\n"
869 for tree, t in self.buildfarm.trees.iteritems():
870 yield "<option value='%s'>%s:%s</option>\n" % (tree, tree, t.branch)
872 yield "<select name='compiler'>\n"
873 for compiler in self.buildfarm.compilers:
874 yield "<option>%s</option>\n" % compiler
877 yield "<input type='submit' name='function' value='View Build'/>\n"
878 yield "<input type='submit' name='function' value='View Host'/>\n"
879 yield "<input type='submit' name='function' value='Recent Checkins'/>\n"
880 yield "<input type='submit' name='function' value='Summary'/>\n"
881 yield "<input type='submit' name='function' value='Recent Builds'/>\n"
885 def __call__(self, environ, start_response):
886 form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
887 fn_name = get_param(form, 'function') or ''
888 myself = wsgiref.util.application_uri(environ)
890 if fn_name == 'text_diff':
891 start_response('200 OK', [('Content-type', 'application/x-diff')])
892 tree = get_param(form, 'tree')
893 t = self.buildfarm.trees[tree]
894 branch = t.get_branch()
895 revision = get_param(form, 'revision')
896 (entry, diff) = branch.diff(revision)
897 changes = branch.changes_summary(revision)
898 yield "".join(history_row_text(entry, tree, changes))
900 elif fn_name == 'Text_Summary':
901 start_response('200 OK', [('Content-type', 'text/plain')])
902 page = ViewSummaryPage(self.buildfarm)
903 yield "".join(page.render_text(myself))
905 start_response('200 OK', [('Content-type', 'text/html')])
909 yield " <title>samba.org build farm</title>\n"
910 yield " <script language='javascript' src='/build_farm.js'></script>\n"
911 yield " <meta name='keywords' contents='Samba SMB CIFS Build Farm'/>\n"
912 yield " <meta name='description' contents='Home of the Samba Build Farm, the automated testing facility.'/>\n"
913 yield " <meta name='robots' contents='noindex'/>"
914 yield " <link rel='stylesheet' href='/build_farm.css' type='text/css' media='all'/>"
915 yield " <link rel='stylesheet' href='http://master.samba.org/samba/style/common.css' type='text/css' media='all'/>"
916 yield " <link rel='shortcut icon' href='http://www.samba.org/samba/images/favicon.ico'/>"
920 yield util.FileLoad(os.path.join(webdir, "header2.html"))
921 yield "".join(self.main_menu())
922 yield util.FileLoad(os.path.join(webdir, "header3.html"))
923 if fn_name == "View_Build":
924 plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
925 tree = get_param(form, "tree")
926 host = get_param(form, "host")
927 compiler = get_param(form, "compiler")
928 revision = get_param(form, "revision")
929 checksum = get_param(form, "checksum")
930 page = ViewBuildPage(self.buildfarm)
931 yield "".join(page.render(myself, tree, host, compiler, revision, checksum, plain_logs))
932 elif fn_name == "View_Host":
933 page = ViewHostPage(self.buildfarm)
934 yield "".join(page.render_html(myself, get_param(form, 'host')))
935 elif fn_name == "Recent_Builds":
936 page = ViewRecentBuildsPage(self.buildfarm)
937 yield "".join(page.render(myself, get_param(form, "tree"), get_param(form, "sortby") or "revision"))
938 elif fn_name == "Recent_Checkins":
940 tree = get_param(form, "tree")
941 author = get_param(form, 'author')
942 page = RecentCheckinsPage(self.buildfarm)
943 yield "".join(page.render(myself, tree, author))
944 elif fn_name == "diff":
945 tree = get_param(form, "tree")
946 revision = get_param(form, 'revision')
947 page = DiffPage(self.buildfarm)
948 yield "".join(page.render(myself, tree, revision))
949 elif os.getenv("PATH_INFO") not in (None, "", "/"):
950 paths = os.getenv("PATH_INFO").split('/')
951 if paths[1] == "recent":
952 page = ViewRecentBuildsPage(self.buildfarm)
953 yield "".join(page.render(myself, paths[2], get_param(form, 'sortby') or 'age'))
954 elif paths[1] == "host":
955 page = ViewHostPage(self.buildfarm)
956 yield "".join(page.render_html(myself, paths[2]))
958 page = ViewSummaryPage(self.buildfarm)
959 yield "".join(page.render_html(myself))
960 yield util.FileLoad(os.path.join(webdir, "footer.html"))
965 if __name__ == '__main__':
967 parser = optparse.OptionParser("[options]")
968 parser.add_option("--port", help="Port to listen on [localhost:8000]", default="localhost:8000", type=str)
969 opts, args = parser.parse_args()
970 from buildfarm.sqldb import StormCachingBuildFarm
971 buildfarm = StormCachingBuildFarm()
972 buildApp = BuildFarmApp(buildfarm)
973 from wsgiref.simple_server import make_server
977 def standaloneApp(environ, start_response):
978 if environ['PATH_INFO']:
979 m = re.match("^/([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)?", environ['PATH_INFO'])
981 static_file = os.path.join(webdir, m.group(1)+m.group(2))
982 if os.path.exists(static_file):
983 type = mimetypes.types_map[m.group(2)]
984 start_response('200 OK', [('Content-type', type)])
985 data = open(static_file, 'rb').read()
988 yield "".join(buildApp(environ, start_response))
990 (address, port) = opts.port.rsplit(":", 1)
992 address = "localhost"
994 httpd = make_server(address, int(port), standaloneApp)
995 print "Serving on %s:%d..." % (address, int(port))
996 httpd.serve_forever()