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 select(name, values, default=None):
60 yield "<select name='%s'>" % name
61 for key in sorted(values):
63 yield "<option selected value='%s'>%s</option>" % (key, values[key])
65 yield "<option value='%s'>%s</option>" % (key, values[key])
69 def get_param(form, param):
70 """get a param from the request, after sanitizing it"""
74 result = [s.replace(" ", "_") for s in form.getlist(param)]
77 if re.match("[^a-zA-Z0-9\-\_\.]", entry):
78 raise Exception("Parameter %s is invalid" % param)
83 def html_build_status(status):
84 def span(classname, contents):
85 return "<span class=\"%s\">%s</span>" % (classname, contents)
87 def span_status(stage):
88 if stage.name == "CC_CHECKER":
90 return span("status checker", "ok")
92 return span("status checker", stage.result)
94 if stage.result is None:
95 return span("status unknown", "?")
96 elif stage.result == 0:
97 return span("status passed", "ok")
99 return span("status failed", stage.result)
102 if "panic" in status.other_failures:
103 return span("status panic", "PANIC")
104 if "disk full" in status.other_failures:
105 return span("status failed", "disk full")
106 if "timeout" in status.other_failures:
107 return span("status failed", "timeout")
108 if "inconsistent test result" in status.other_failures:
109 ostatus.append(span("status failed", "unexpected return code"))
110 bstatus = "/".join([span_status(s) for s in status.stages])
113 return "/".join([bstatus] + ostatus)
116 def build_status_html(myself, build):
120 "compiler": build.compiler,
121 "checksum": build.log_checksum()
124 params["revision"] = build.revision
125 return "<a href='%s?function=View+Build;%s'>%s</a>" % (myself, ";".join(["%s=%s" % k for k in params.iteritems()]), html_build_status(build.status()))
128 def build_status_vals(status):
129 """translate a status into a set of int representing status"""
130 status = util.strip_html(status)
132 status = status.replace("ok", "0")
133 status = status.replace("-", "0")
134 status = status.replace("?", "0.1")
135 status = status.replace("PANIC", "1")
137 return status.split("/")
140 def host_link(myself, host):
141 return "<a href='%s?function=View+Host;host=%s'>%s</a>" % (
145 def revision_link(myself, revision, tree):
146 """return a link to a particular revision"""
149 return "<a href='%s?function=diff;tree=%s;revision=%s' title='View Diff for %s'>%s</a>" % (myself, tree, revision, revision, revision[:7])
152 def subunit_to_buildfarm_result(subunit_result):
153 if subunit_result == "success":
155 elif subunit_result == "error":
157 elif subunit_result == "skip":
159 elif subunit_result == "failure":
161 elif subunit_result == "xfail":
166 def format_subunit_reason(reason):
167 reason = re.sub("^\[\n+(.*?)\n+\]$", "\\1", reason)
168 return "<div class=\"reason\">%s</div>" % reason
171 class LogPrettyPrinter(object):
176 def _pretty_print(self, m):
178 actionName = m.group(2)
180 # handle pretty-printing of static-analysis tools
181 if actionName == 'cc_checker':
182 output = print_log_cc_checker(output)
185 return make_collapsible_html('action', actionName, output, self.indice, status)
187 # log is already CGI-escaped, so handle '>' in test name by handling >
188 def _format_stage(self, m):
190 return make_collapsible_html('test', m.group(1), m.group(2), self.indice, m.group(3))
192 def _format_skip_testsuite(self, m):
194 return make_collapsible_html('test', m.group(1), '', self.indice, 'skipped')
196 def _format_testsuite(self, m):
197 testName = m.group(1)
199 status = subunit_to_buildfarm_result(m.group(3))
201 errorReason = format_subunit_reason(m.group(4))
205 return make_collapsible_html('test', testName, content+errorReason, self.indice, status)
207 def _format_test(self, m):
209 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)))
211 def pretty_print(self, log):
212 # do some pretty printing for the actions
213 pattern = re.compile("(Running action\s+([\w\-]+)$(?:\s^.*$)*?\sACTION\ (PASSED|FAILED):\ ([\w\-]+)$)", re.M)
214 log = pattern.sub(self._pretty_print, log)
217 --==--==--==--==--==--==--==--==--==--==--.*?
218 Running\ test\ ([\w\-=,_:\ /.&;]+).*?
219 --==--==--==--==--==--==--==--==--==--==--
221 ==========================================.*?
222 TEST\ (FAILED|PASSED|SKIPPED):.*?
223 ==========================================\s+
224 """, self._format_stage, log)
226 log = re.sub("skip-testsuite: ([\w\-=,_:\ /.&; \(\)]+).*?",
227 self._format_skip_testsuite, log)
229 pattern = re.compile("^testsuite: (.+)$\s((?:^.*$\s)*?)testsuite-(\w+): .*?(?:(\[$\s(?:^.*$\s)*?^\]$)|$)", re.M)
230 log = pattern.sub(self._format_testsuite, log)
232 ^test: ([\w\-=,_:\ /.&; \(\)]+).*?
234 (success|xfail|failure|skip): [\w\-=,_:\ /.&; \(\)]+( \[.*?\])?.*?
235 """, self._format_test, log)
237 return "<pre>%s</pre>" % log
240 def print_log_pretty(log):
241 return LogPrettyPrinter().pretty_print(log)
244 def print_log_cc_checker(input):
245 # generate pretty-printed html for static analysis tools
248 # for now, we only handle the IBM Checker's output style
249 if not re.search("^BEAM_VERSION", input):
258 for line in input.splitlines():
259 # for each line, check if the line is a new entry,
260 # otherwise, store the line under the current entry.
262 if line.startswith("-- "):
265 output += make_collapsible_html('cc_checker', title, content, id, status)
269 # clear maintenance vars
270 (inEntry, content) = (True, "")
273 m = re.match("^-- ((ERROR|WARNING|MISTAKE).*?)\s+>>>([a-zA-Z0-9]+_(\w+)_[a-zA-Z0-9]+)", line)
275 # then store the result
276 (title, status, id) = ("%s %s" % (m.group(1), m.group(4)), m.group(2), m.group(3))
277 elif line.startswith("CC_CHECKER STATUS"):
279 output += make_collapsible_html('cc_checker', title, content, id, status)
284 # not a new entry, so part of the current entry's output
285 content += "%s\n" % line
289 # This function does approximately the same as the following, following
290 # commented-out regular expression except that the regex doesn't quite
291 # handle IBM Checker's newlines quite right.
293 # --\ ((ERROR|WARNING|MISTAKE).*?)\s+
297 # }{make_collapsible_html('cc_checker', "$1 $4", $5, $3, $2)}exgs
301 def make_collapsible_html(type, title, output, id, status=""):
302 """generate html for a collapsible section
304 :param type: the logical type of it. e.g. "test" or "action"
305 :param title: the title to be displayed
307 if ((status == "" or "failed" == status.lower())):
308 icon = 'icon_hide_16.png'
310 icon = 'icon_unhide_16.png'
312 # trim leading and trailing whitespace
313 output = output.strip()
315 # note that we may be inside a <pre>, so we don't put any extra whitespace
317 ret = "<div class='%s unit %s' id='%s-%s'>" % (type, status, type, id)
318 ret += "<a href=\"javascript:handle('%s');\">" % id
319 ret += "<img id='img-%s' name='img-%s' alt='%s' src='%s' />" %(id, id, status, icon)
320 ret += "<div class='%s title'>%s</div></a>" % (type, title)
322 ret += "<div class='%s status %s'>%s</div>" % (type, status, status)
323 ret += "<div class='%s output' id='output-%s'>" % (type, id)
324 if output and len(output):
325 ret += "<pre>%s</pre>>" % (output)
326 ret += "</div></div>"
330 def web_paths(t, paths):
331 """change the given source paths into links"""
335 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)
338 raise Exception("Unknown scm %s" % t.scm)
341 def history_row_text(entry, tree, changes):
342 """show one row of history table"""
343 msg = cgi.escape(entry.message)
344 t = time.asctime(time.gmtime(entry.date))
345 age = util.dhm_time(time.time()-entry.date)
347 yield "Author: %s\n" % entry.author
349 yield "Revision: %s\n" % entry.revision
350 (added, modified, removed) = changes
351 yield "Modified: %s\n" % modified
352 yield "Added: %s\n" % added
353 yield "Removed: %s\n" % removed
354 yield "\n\n%s\n\n\n" % msg
357 class BuildFarmPage(object):
359 def __init__(self, buildfarm):
360 self.buildfarm = buildfarm
362 def red_age(self, age):
363 """show an age as a string"""
364 if age > self.buildfarm.OLDAGE:
365 return "<span clsas='old'>%s</span>" % util.dhm_time(age)
366 return util.dhm_time(age)
368 def tree_link(self, myself, tree):
369 # return a link to a particular tree
371 if tree in self.buildfarm.trees:
372 branch = ":%s" % self.buildfarm.trees[tree].branch
374 return "<a href='%s?function=Recent+Builds;tree=%s' title='View recent builds for %s'>%s%s</a>" % (myself, tree, tree, tree, branch)
376 def render(self, output_type):
377 raise NotImplementedError(self.render)
380 class ViewBuildPage(BuildFarmPage):
382 def show_oldrevs(self, myself, tree, host, compiler):
383 """show the available old revisions, if any"""
384 old_builds = self.buildfarm.builds.get_old_builds(tree, host, compiler)
389 yield "<h2>Older builds:</h2>\n"
391 yield "<table class='real'>\n"
392 yield "<thead><tr><th>Revision</th><th>Status</th><th>Age</th></tr></thead>\n"
395 for build in old_builds:
396 yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n" % (
397 revision_link(myself, build.revision, tree),
398 build_status_html(myself, build), util.dhm_time(build.age))
400 yield "</tbody></table>\n"
402 def render(self, myself, tree, host, compiler, rev, checksum=None,
404 """view one build in detail"""
410 build = self.buildfarm.get_build(tree, host, compiler, rev,
412 except data.NoSuchBuildError:
413 yield "No such build: %s on %s with %s, rev %r, checksum %r" % (
414 tree, host, compiler, rev, checksum)
422 except data.LogFileMissing:
431 log = cgi.escape(log)
433 m = re.search("(.*)", log)
436 m = re.search("CFLAGS=(.*)", log)
439 m = re.search("configure options: (.*)", log)
444 err = cgi.escape(err)
445 yield '<h2>Host information:</h2>'
447 host_web_file = "../web/%s.html" % host
448 if os.path.exists(host_web_file):
449 yield util.FileLoad(host_web_file)
451 yield "<table class='real'>\n"
452 yield "<tr><td>Host:</td><td><a href='%s?function=View+Host;host=%s;tree=%s;"\
453 "compiler=%s#'>%s</a> - %s</td></tr>\n" %\
454 (myself, host, tree, compiler, host, self.buildfarm.hostdb[host].platform.encode("utf-8"))
455 if uname is not None:
456 yield "<tr><td>Uname:</td><td>%s</td></tr>\n" % uname
457 yield "<tr><td>Tree:</td><td>%s</td></tr>\n" % self.tree_link(myself, tree)
458 yield "<tr><td>Build Revision:</td><td>%s</td></tr>\n" % revision_link(myself, build.revision, tree)
459 yield "<tr><td>Build age:</td><td><div class='age'>%s</div></td></tr>\n" % self.red_age(build.age)
460 yield "<tr><td>Status:</td><td>%s</td></tr>\n" % build_status_html(myself, build)
461 yield "<tr><td>Compiler:</td><td>%s</td></tr>\n" % compiler
462 if cflags is not None:
463 yield "<tr><td>CFLAGS:</td><td>%s</td></tr>\n" % cflags
464 if config is not None:
465 yield "<tr><td>configure options:</td><td>%s</td></tr>\n" % config
468 yield "".join(self.show_oldrevs(myself, tree, host, compiler))
470 # check the head of the output for our magic string
473 rev_var = ";revision=%s" % rev
475 yield "<div id='log'>"
478 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s"\
479 ";compiler=%s%s;plain=true' title='Switch to bland, non-javascript,"\
480 " unstyled view'>Plain View</a></p>" % (myself, host, tree, compiler, rev_var)
482 yield "<div id='actionList'>"
483 # These can be pretty wide -- perhaps we need to
484 # allow them to wrap in some way?
486 yield "<h2>No error log available</h2>\n"
488 yield "<h2>Error log:</h2>"
489 yield make_collapsible_html('action', "Error Output", "\n%s" % err, "stderr-0", "errorlog")
492 yield "<h2>No build log available</h2>"
494 yield "<h2>Build log:</h2>\n"
495 yield print_log_pretty(log)
497 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>"
500 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s;"\
501 "compiler=%s%s' title='Switch to colourful, javascript-enabled, styled"\
502 " view'>Enhanced View</a></p>" % (myself, host, tree, compiler, rev_var)
504 yield "<h2>No error log available</h2>"
506 yield '<h2>Error log:</h2>\n'
507 yield '<div id="errorLog"><pre>%s</pre></div>' % err
509 yield '<h2>No build log available</h2>'
511 yield '<h2>Build log:</h2>\n'
512 yield '<div id="buildLog"><pre>%s</pre></div>' % log
517 class ViewRecentBuildsPage(BuildFarmPage):
519 def render(self, myself, tree, sort_by=None):
520 """Draw the "recent builds" view"""
523 def build_platform(build):
525 host = self.buildfarm.hostdb[build.host]
526 except hostdb.NoSuchHost:
529 return host.platform.encode("utf-8")
532 "revision": lambda a, b: cmp(a.revision, b.revision),
533 "age": lambda a, b: cmp(a.age, b.age),
534 "host": lambda a, b: cmp(a.host, b.host),
535 "platform": lambda a, b: cmp(build_platform(a), build_platform(b)),
536 "compiler": lambda a, b: cmp(a.compiler, b.compiler),
537 "status": lambda a, b: cmp(a.status(), b.status()),
543 if sort_by not in cmp_funcs:
544 yield "not a valid sort mechanism: %r" % sort_by
547 all_builds = list(self.buildfarm.get_tree_builds(tree))
549 all_builds.sort(cmp_funcs[sort_by])
551 t = self.buildfarm.trees[tree]
553 sorturl = "%s?tree=%s;function=Recent+Builds" % (myself, tree)
555 yield "<div id='recent-builds' class='build-section'>"
556 yield "<h2>Recent builds of %s (%s branch %s)</h2>" % (tree, t.scm, t.branch)
557 yield "<table class='real'>"
560 yield "<th><a href='%s;sortby=age' title='Sort by build age'>Age</a></th>" % sorturl
561 yield "<th><a href='%s;sortby=revision' title='Sort by build revision'>Revision</a></th>" % sorturl
562 yield "<th>Tree</th>"
563 yield "<th><a href='%s;sortby=platform' title='Sort by platform'>Platform</a></th>" % sorturl
564 yield "<th><a href='%s;sortby=host' title='Sort by host'>Host</a></th>" % sorturl
565 yield "<th><a href='%s;sortby=compiler' title='Sort by compiler'>Compiler</a></th>" % sorturl
566 yield "<th><a href='%s;sortby=status' title='Sort by status'>Status</a></th>" % sorturl
569 for build in all_builds:
571 yield "<td>%s</td>" % util.dhm_time(build.age)
572 yield "<td>%s</td>" % revision_link(myself, build.revision, build.tree)
573 yield "<td>%s</td>" % build.tree
574 yield "<td>%s</td>" % build_platform(build)
575 yield "<td>%s</td>" % host_link(myself, build.host)
576 yield "<td>%s</td>" % build.compiler
577 yield "<td>%s</td>" % build_status_html(myself, build)
579 yield "</tbody></table>"
583 class ViewHostPage(BuildFarmPage):
585 def _render_build_list_header(self, host):
586 yield "<div class='host summary'>"
587 yield "<a id='host' name='host'/>"
588 yield "<h3>%s - %s</h3>" % (host.name, host.platform.encode("utf-8"))
589 yield "<table class='real'>"
590 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>"
593 def _render_build_html(self, myself, build):
595 (revision, revision_time) = build.revision_details()
596 except data.MissingRevisionInfo:
598 warnings = build.err_count()
600 yield "<td><span class='tree'>" + self.tree_link(myself, build.tree) +"</span>/" + build.compiler + "</td>"
601 yield "<td>" + revision_link(myself, revision, build.tree) + "</td>"
602 yield "<td><div class='age'>" + self.red_age(build.age) + "</div></td>"
603 yield "<td><div class='status'>%s</div></td>" % build_status_html(myself, build)
604 yield "<td>%s</td>" % warnings
607 def render_html(self, myself, *requested_hosts):
608 yield "<div class='build-section' id='build-summary'>"
609 yield '<h2>Host summary:</h2>'
610 for hostname in requested_hosts:
612 host = self.buildfarm.hostdb[hostname]
613 except hostdb.NoSuchHost:
614 deadhosts.append(hostname)
616 builds = list(self.buildfarm.get_host_builds(hostname))
618 yield "".join(self._render_build_list_header(host))
620 yield "".join(self._render_build_html(myself, build))
621 yield "</tbody></table>"
624 deadhosts.append(hostname)
627 yield "".join(self.draw_dead_hosts(*deadhosts))
629 def render_text(self, myself, *requested_hosts):
630 """print the host's table of information"""
631 yield "Host summary:\n"
633 for host in requested_hosts:
634 # make sure we have some data from it
636 self.buildfarm.hostdb[host]
637 except hostdb.NoSuchHost:
640 builds = list(self.buildfarm.get_host_builds(host))
642 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
643 "Tree", "Compiler", "Build Age", "Status", "Warnings")
645 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
646 build.tree, build.compiler,
647 util.dhm_time(build.age),
648 str(build.status()), build.err_count())
651 def draw_dead_hosts(self, *deadhosts):
652 """Draw the "dead hosts" table"""
654 # don't output anything if there are no dead hosts
655 if len(deadhosts) == 0:
658 yield "<div class='build-section' id='dead-hosts'>"
659 yield "<h2>Dead Hosts:</h2>"
660 yield "<table class='real'>"
661 yield "<thead><tr><th>Host</th><th>OS</th><th>Min Age</th></tr></thead>"
664 for host in deadhosts:
665 last_build = self.buildfarm.host_last_build(host)
666 age = time.time() - last_build
668 platform = self.buildfarm.hostdb[host].platform.encode("utf-8")
669 except hostdb.NoSuchHost:
671 yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" %\
672 (host, platform, util.dhm_time(age))
674 yield "</tbody></table>"
678 class ViewSummaryPage(BuildFarmPage):
680 def _get_counts(self):
681 broken_count = defaultdict(lambda: 0)
682 panic_count = defaultdict(lambda: 0)
683 host_count = defaultdict(lambda: 0)
685 # set up a variable to store the broken builds table's code, so we can
686 # output when we want
689 builds = self.buildfarm.get_last_builds()
692 host_count[build.tree]+=1
693 status = build.status()
696 broken_count[build.tree]+=1
697 if "panic" in status.other_failures:
698 panic_count[build.tree]+=1
699 return (host_count, broken_count, panic_count)
701 def render_text(self, myself):
703 (host_count, broken_count, panic_count) = self._get_counts()
704 # for the text report, include the current time
706 yield "Build status as of %s\n\n" % t
708 yield "Build counts:\n"
709 yield "%-12s %-6s %-6s %-6s\n" % ("Tree", "Total", "Broken", "Panic")
711 for tree in sorted(self.buildfarm.trees.keys()):
712 yield "%-12s %-6s %-6s %-6s\n" % (tree, host_count[tree],
713 broken_count[tree], panic_count[tree])
717 def render_html(self, myself):
718 """view build summary"""
720 (host_count, broken_count, panic_count) = self._get_counts()
722 yield "<div id='build-counts' class='build-section'>"
723 yield "<h2>Build counts:</h2>"
724 yield "<table class='real'>"
725 yield "<thead><tr><th>Tree</th><th>Total</th><th>Broken</th><th>Panic</th><th>Test coverage</th></tr></thead>"
728 for tree in sorted(self.buildfarm.trees.keys()):
730 yield "<td>%s</td>" % self.tree_link(myself, tree)
731 yield "<td>%s</td>" % host_count[tree]
732 yield "<td>%s</td>" % broken_count[tree]
733 if panic_count[tree]:
734 yield "<td class='panic'>"
737 yield "%d</td>" % panic_count[tree]
739 lcov_status = self.buildfarm.lcov_status(tree)
740 except data.NoSuchBuildError:
743 if lcov_status is not None:
744 yield "<td><a href=\"/lcov/data/%s/%s\">%s %%</a></td>" % (
745 self.buildfarm.LCOVHOST, tree, lcov_status)
750 yield "</tbody></table>"
754 class HistoryPage(BuildFarmPage):
756 def history_row_html(self, myself, entry, tree, changes):
757 """show one row of history table"""
758 msg = cgi.escape(entry.message)
759 t = time.asctime(time.gmtime(entry.date))
760 age = util.dhm_time(time.time()-entry.date)
762 t = t.replace(" ", " ")
765 <div class=\"history_row\">
766 <div class=\"datetime\">
767 <span class=\"date\">%s</span><br />
768 <span class=\"age\">%s ago</span>""" % (t, age)
770 yield " - <span class=\"revision\">%s</span><br/>" % entry.revision
771 revision_url = "revision=%s" % entry.revision
773 revision_url = "author=%s" % entry.author
776 <span class=\"html\"><a href=\"%s?function=diff;tree=%s;date=%s;%s\">show diffs</a></span>
778 <span class=\"text\"><a href=\"%s?function=text_diff;tree=%s;date=%s;%s\">download diffs</a></span>
780 <div class=\"history_log_message\">
784 <div class=\"author\">
785 <span class=\"label\">Author: </span>%s
786 </div>""" % (myself, tree.name, entry.date, revision_url,
787 myself, tree.name, entry.date, revision_url,
790 (added, modified, removed) = changes
793 yield "<div class=\"files\"><span class=\"label\">Modified: </span>"
794 yield web_paths(tree, modified)
798 yield "<div class=\"files\"><span class=\"label\">Added: </span>"
799 yield web_paths(tree, added)
803 yield "<div class=\"files\"><span class=\"label\">Removed: </span>"
804 yield web_paths(tree, removed)
807 yield "<div class=\"builds\">\n"
808 yield "<span class=\"label\">Builds: </span>\n"
809 for build in self.buildfarm.get_revision_builds(tree.name, entry.revision):
810 yield "%s(%s) " % (build_status_html(myself, build),
811 host_link(myself, build.host))
817 class DiffPage(HistoryPage):
819 def render(self, myself, tree, revision):
820 t = self.buildfarm.trees[tree]
821 branch = t.get_branch()
822 (entry, diff) = branch.diff(revision)
823 # get information about the current diff
824 title = "GIT Diff in %s:%s for revision %s" % (
825 tree, t.branch, revision)
826 yield "<h2>%s</h2>" % title
827 changes = branch.changes_summary(revision)
828 yield "".join(self.history_row_html(myself, entry, t, changes))
829 diff = highlight(diff, DiffLexer(), HtmlFormatter())
830 yield "<pre>%s</pre>\n" % diff.encode("utf-8")
833 class RecentCheckinsPage(HistoryPage):
837 def render(self, myself, tree, author=None):
838 t = self.buildfarm.trees[tree]
840 authors = {"ALL": "ALL"}
841 branch = t.get_branch()
842 re_author = re.compile("^(.*) <(.*)>$")
843 for entry in branch.log(limit=HISTORY_HORIZON):
844 m = re_author.match(entry.author)
845 authors[m.group(2)] = m.group(1)
846 if author in ("ALL", "", m.group(2)):
847 interesting.append(entry)
849 yield "<h2>Recent checkins for %s (%s branch %s)</h2>\n" % (
850 tree, t.scm, t.branch)
851 yield "<form method='GET'>"
852 yield "Select Author: "
853 yield "".join(select(name="author", values=authors, default=author))
854 yield "<input type='submit' name='sub_function' value='Refresh'/>"
855 yield "<input type='hidden' name='tree' value='%s'/>" % tree
856 yield "<input type='hidden' name='function', value='Recent Checkins'/>"
859 for entry in interesting[:self.limit]:
860 changes = branch.changes_summary(entry.revision)
861 yield "".join(self.history_row_html(myself, entry, t, changes))
865 class BuildFarmApp(object):
867 def __init__(self, buildfarm):
868 self.buildfarm = buildfarm
870 def main_menu(self, tree, host, compiler):
873 yield "<form method='GET'>\n"
874 yield "<div id='build-menu'>\n"
876 for h in self.buildfarm.hostdb.hosts():
877 host_dict[h.name] = "%s -- %s" % (h.platform.encode("utf-8"), h.name)
878 yield "".join(select("host", host_dict, default=host))
880 for t in self.buildfarm.trees.values():
881 tree_dict[t.name] = "%s:%s" % (t.name, t.branch)
882 yield "".join(select("tree", tree_dict, default=tree))
883 yield "".join(select("compiler", dict(zip(self.buildfarm.compilers, self.buildfarm.compilers)), default=compiler))
885 yield "<input type='submit' name='function' value='View Build'/>\n"
886 yield "<input type='submit' name='function' value='View Host'/>\n"
887 yield "<input type='submit' name='function' value='Recent Checkins'/>\n"
888 yield "<input type='submit' name='function' value='Summary'/>\n"
889 yield "<input type='submit' name='function' value='Recent Builds'/>\n"
893 def __call__(self, environ, start_response):
894 form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
895 fn_name = get_param(form, 'function') or ''
896 myself = wsgiref.util.application_uri(environ)
898 if fn_name == 'text_diff':
899 start_response('200 OK', [('Content-type', 'application/x-diff')])
900 tree = get_param(form, 'tree')
901 t = self.buildfarm.trees[tree]
902 branch = t.get_branch()
903 revision = get_param(form, 'revision')
904 (entry, diff) = branch.diff(revision)
905 changes = branch.changes_summary(revision)
906 yield "".join(history_row_text(entry, tree, changes))
908 elif fn_name == 'Text_Summary':
909 start_response('200 OK', [('Content-type', 'text/plain')])
910 page = ViewSummaryPage(self.buildfarm)
911 yield "".join(page.render_text(myself))
913 start_response('200 OK', [('Content-type', 'text/html')])
917 yield " <title>samba.org build farm</title>\n"
918 yield " <script language='javascript' src='/build_farm.js'></script>\n"
919 yield " <meta name='keywords' contents='Samba SMB CIFS Build Farm'/>\n"
920 yield " <meta name='description' contents='Home of the Samba Build Farm, the automated testing facility.'/>\n"
921 yield " <meta name='robots' contents='noindex'/>"
922 yield " <link rel='stylesheet' href='/build_farm.css' type='text/css' media='all'/>"
923 yield " <link rel='stylesheet' href='http://master.samba.org/samba/style/common.css' type='text/css' media='all'/>"
924 yield " <link rel='shortcut icon' href='http://www.samba.org/samba/images/favicon.ico'/>"
928 yield util.FileLoad(os.path.join(webdir, "header2.html"))
929 tree = get_param(form, "tree")
930 host = get_param(form, "host")
931 compiler = get_param(form, "compiler")
932 yield "".join(self.main_menu(tree, host, compiler))
933 yield util.FileLoad(os.path.join(webdir, "header3.html"))
934 if fn_name == "View_Build":
935 plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
936 revision = get_param(form, "revision")
937 checksum = get_param(form, "checksum")
938 page = ViewBuildPage(self.buildfarm)
939 yield "".join(page.render(myself, tree, host, compiler, revision, checksum, plain_logs))
940 elif fn_name == "View_Host":
941 page = ViewHostPage(self.buildfarm)
942 yield "".join(page.render_html(myself, get_param(form, 'host')))
943 elif fn_name == "Recent_Builds":
944 page = ViewRecentBuildsPage(self.buildfarm)
945 yield "".join(page.render(myself, get_param(form, "tree"), get_param(form, "sortby") or "age"))
946 elif fn_name == "Recent_Checkins":
948 author = get_param(form, 'author')
949 page = RecentCheckinsPage(self.buildfarm)
950 yield "".join(page.render(myself, tree, author))
951 elif fn_name == "diff":
952 revision = get_param(form, 'revision')
953 page = DiffPage(self.buildfarm)
954 yield "".join(page.render(myself, tree, revision))
955 elif os.getenv("PATH_INFO") not in (None, "", "/"):
956 paths = os.getenv("PATH_INFO").split('/')
957 if paths[1] == "recent":
958 page = ViewRecentBuildsPage(self.buildfarm)
959 yield "".join(page.render(myself, paths[2], get_param(form, 'sortby') or 'age'))
960 elif paths[1] == "host":
961 page = ViewHostPage(self.buildfarm)
962 yield "".join(page.render_html(myself, paths[2]))
964 page = ViewSummaryPage(self.buildfarm)
965 yield "".join(page.render_html(myself))
966 yield util.FileLoad(os.path.join(webdir, "footer.html"))
971 if __name__ == '__main__':
973 parser = optparse.OptionParser("[options]")
974 parser.add_option("--port", help="Port to listen on [localhost:8000]", default="localhost:8000", type=str)
975 opts, args = parser.parse_args()
976 from buildfarm.sqldb import StormCachingBuildFarm
977 buildfarm = StormCachingBuildFarm()
978 buildApp = BuildFarmApp(buildfarm)
979 from wsgiref.simple_server import make_server
983 def standaloneApp(environ, start_response):
984 if environ['PATH_INFO']:
985 m = re.match("^/([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)?", environ['PATH_INFO'])
987 static_file = os.path.join(webdir, m.group(1)+m.group(2))
988 if os.path.exists(static_file):
989 type = mimetypes.types_map[m.group(2)]
990 start_response('200 OK', [('Content-type', type)])
991 data = open(static_file, 'rb').read()
994 yield "".join(buildApp(environ, start_response))
996 (address, port) = opts.port.rsplit(":", 1)
998 address = "localhost"
1000 httpd = make_server(address, int(port), standaloneApp)
1001 print "Serving on %s:%d..." % (address, int(port))
1002 httpd.serve_forever()