2 # This CGI script presents the results of the build_farm build
4 # Copyright (C) Andrew Tridgell <tridge@samba.org> 2001-2005
5 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2001
6 # Copyright (C) Vance Lankhaar <vance@samba.org> 2002-2005
7 # Copyright (C) Martin Pool <mbp@samba.org> 2001
8 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2010
9 # Copyright (C) Matthieu Patou <mat@matws.net> 2010-2010
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 # TODO: Allow filtering of the "Recent builds" list to show
26 # e.g. only broken builds or only builds that you care about.
30 sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
32 from buildfarm import (
45 webdir = os.path.dirname(__file__)
46 basedir = os.path.abspath(os.path.join(webdir, ".."))
48 buildfarm = BuildFarm()
50 db = data.BuildResultStore(basedir)
51 #history = history.History(db)
52 hostsdb = buildfarm.hostdb
54 compilers = buildfarm.compilers
55 # host.properties are unicode object and the framework expect string object
56 hosts = dict([(host.name.encode("utf-8"), host) for host in hostsdb.hosts()])
57 trees = buildfarm.trees
58 OLDAGE = buildfarm.OLDAGE
60 UNPACKED_BASE = "http://svn.samba.org/ftp/unpacked"
61 GITWEB_BASE = "http://gitweb.samba.org"
63 # this is automatically filled in
66 def get_param(form, param):
67 """get a param from the request, after sanitizing it"""
71 result = [s.replace(" ", "_") for s in form.getlist(param)]
74 if re.match("[^a-zA-Z0-9\-\_\.]", entry):
75 raise Exception("Parameter %s is invalid" % param)
80 def build_link(myself, tree, host, compiler, rev, status):
82 opt_rev = ';revision=%s' % rev
85 return "<a href='%s?function=View+Build;host=%s;tree=%s;compiler=%s%s'>%s</a>" % (
86 myself, host, tree, compiler, opt_rev, status)
89 def html_build_status(status):
90 def span(classname, contents):
91 return "<span class=\"%s\">%s</span>" % (classname, contents)
93 def span_status(n, st):
96 return span("status checker", "ok")
98 return span("status checker", st)
101 return span("status unknown", "?")
103 return span("status passed", "ok")
105 return span("status failed", st)
108 if "panic" in status.other_failures:
109 ostatus += "/"+span("status panic", "PANIC")
110 if "disk full" in status.other_failures:
111 ostatus += "/"+span("status failed", "disk full")
112 if "timeout" in status.other_failures:
113 ostatus += "/"+span("status failed", "timeout")
114 if "inconsistent test result" in status.other_failures:
115 ostatus += "/"+span("status failed", "unexpected return code")
116 bstatus = "/".join([span_status(n, s) for (n, s) in status.stages])
119 return bstatus + ostatus
122 def build_status_html(myself, build):
123 rawstatus = build.status()
124 status = html_build_status(rawstatus)
125 return build_link(myself, build.tree, build.host, build.compiler, build.rev, status)
129 """show an age as a string"""
131 return "<span clsas='old'>%s</span>" % util.dhm_time(age)
132 return util.dhm_time(age)
135 def build_status_vals(status):
136 """translate a status into a set of int representing status"""
137 status = util.strip_html(status)
139 status = status.replace("ok", "0")
140 status = status.replace("-", "0")
141 status = status.replace("?", "0.1")
142 status = status.replace("PANIC", "1")
144 return status.split("/")
147 def view_summary(myself, output_type):
148 """view build summary"""
156 # zero broken and panic counters
158 broken_count[tree] = 0
159 panic_count[tree] = 0
162 # set up a variable to store the broken builds table's code, so we can
163 # output when we want
167 # for the text report, include the current time
168 if output_type == 'text':
170 yield "Build status as of %s\n\n" % t
172 for host in hosts.values():
173 for compiler in compilers:
176 build = buildfarm.get_build(tree, host.name.encode("utf-8"), compiler)
177 status = build_status_html(myself, build)
178 except data.NoSuchBuildError:
180 age_mtime = build.age_mtime()
183 if "status failed" in status:
184 broken_count[tree]+=1
185 if "PANIC" in status:
188 if output_type == 'text':
189 yield "Build counts:\n"
190 yield "%-12s %-6s %-6s %-6s\n" % ("Tree", "Total", "Broken", "Panic")
192 yield "<div id='build-counts' class='build-section'>"
193 yield "<h2>Build counts:</h2>"
194 yield "<table class='real'>"
195 yield "<thead><tr><th>Tree</th><th>Total</th><th>Broken</th><th>Panic</th><th>Test coverage</th></tr></thead>"
198 for tree in sorted(trees.keys()):
199 if output_type == 'text':
200 yield "%-12s %-6s %-6s %-6s\n" % (tree, host_count[tree],
201 broken_count[tree], panic_count[tree])
204 yield "<td>%s</td>" % tree_link(myself, tree)
205 yield "<td>%s</td>" % host_count[tree]
206 yield "<td>%s</td>" % broken_count[tree]
207 if panic_count[tree]:
208 yield "<td class='panic'>"
211 yield "%d</td>" % panic_count[tree]
213 lcov_status = buildfarm.lcov_status(tree)
214 except data.NoSuchBuildError:
217 if lcov_status is not None:
218 yield "<td><a href=\"/lcov/data/%s/%s\">%s %%</a></td>" % (buildfarm.LCOVHOST, tree, lcov_status)
223 if output_type == 'text':
226 yield "</tbody></table>"
230 def revision_link(myself, revision, tree):
231 """return a link to a particular revision"""
233 revision = revision.lstrip()
238 if len(revision) == 40:
239 rev_short = re.sub("(^.{7}).*", "\\1(git)", rev_short)
241 return "<a href='%s?function=diff;tree=%s;revision=%s' title='View Diff for %s'>%s</a>" % (myself, tree, revision, revision, rev_short)
244 def tree_link(myself, tree):
245 # return a link to a particular tree
248 branch = ":%s" % trees[tree].branch
250 return "<a href='%s?function=Recent+Builds;tree=%s' title='View recent builds for %s'>%s%s</a>" % (myself, tree, tree, tree, branch)
253 def view_recent_builds(myself, tree, sort_by):
254 """Draw the "recent builds" view"""
262 "revision": lambda a, b: cmp(a[7], b[7]),
263 "age": lambda a, b: cmp(a[0], b[0]),
264 "host": lambda a, b: cmp(a[2], b[2]),
265 "platform": lambda a, b: cmp(a[1], b[1]),
266 "compiler": lambda a, b: cmp(a[3], b[3]),
267 "status": lambda a, b: a[6].cmp(b[6]),
270 assert tree in trees, "not a build tree"
271 assert sort_by in cmp_funcs, "not a valid sort"
275 for host in hosts.values():
276 for compiler in compilers:
278 build = buildfarm.get_build(tree, host.name.encode("utf-8"), compiler)
279 status = build_status_html(myself, build)
280 except data.NoSuchBuildError:
283 age_mtime = build.age_mtime()
284 age_ctime = build.age_ctime()
285 (revision, commit_revision, revision_time) = build.revision_details()
287 revision = commit_revision
289 all_builds.append([age_ctime,
290 host.platform.encode("utf-8"),
291 "<a href='%s?function=View+Host;host=%s;tree=%s;compiler=%s#%s'>%s</a>"
292 % (myself, host.name.encode("utf-8"),
293 tree, compiler, host.name.encode("utf-8"),
294 host.name.encode("utf-8")),
295 compiler, tree, status, build.status(),
296 revision_link(myself, revision, tree),
299 all_builds.sort(cmp_funcs[sort_by])
301 sorturl = "%s?tree=%s;function=Recent+Builds" % (myself, tree)
303 yield "<div id='recent-builds' class='build-section'>"
304 yield "<h2>Recent builds of %s (%s branch %s)</h2>" % (tree, t.scm, t.branch)
305 yield "<table class='real'>"
308 yield "<th><a href='%s;sortby=age' title='Sort by build age'>Age</a></th>" % sorturl
309 yield "<th><a href='%s;sortby=revision' title='Sort by build revision'>Revision</a></th>" % sorturl
310 yield "<th>Tree</th>"
311 yield "<th><a href='%s;sortby=platform' title='Sort by platform'>Platform</a></th>" % sorturl
312 yield "<th><a href='%s;sortby=host' title='Sort by host'>Host</a></th>" % sorturl
313 yield "<th><a href='%s;sortby=compiler' title='Sort by compiler'>Compiler</a></th>" % sorturl
314 yield "<th><a href='%s;sortby=status' title='Sort by status'>Status</a></th>" % sorturl
317 for build in all_builds:
319 yield "<td>%s</td>" % util.dhm_time(build[0])
320 yield "<td>%s</td>" % build[7]
321 yield "<td>%s</td>" % build[4]
322 yield "<td>%s</td>" % build[1]
323 yield "<td>%s</td>" % build[2]
324 yield "<td>%s</td>" % build[3]
325 yield "<td>%s</td>" % build[5]
327 yield "</tbody></table>"
331 def draw_dead_hosts(output_type, *deadhosts):
332 """Draw the "dead hosts" table"""
334 # don't output anything if there are no dead hosts
335 if len(deadhosts) == 0:
338 # don't include in text report
339 if output_type == "text":
342 yield "<div class='build-section' id='dead-hosts'>"
343 yield "<h2>Dead Hosts:</h2>"
344 yield "<table class='real'>"
345 yield "<thead><tr><th>Host</th><th>OS</th><th>Min Age</th></tr></thead>"
348 for host in deadhosts:
349 age_ctime = db.host_age(host)
350 yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" %\
351 (host,hosts[host].platform.encode("utf-8"),
352 util.dhm_time(age_ctime))
354 yield "</tbody></table>"
358 def show_oldrevs(myself, tree, host, compiler):
359 """show the available old revisions, if any"""
360 revs = db.get_old_revs(tree, host, compiler)
365 yield "<h2>Older builds:</h2>"
367 yield "<table class='real'>"
368 yield "<thead><tr><th>Revision</th><th>Status</th></tr></thead>"
373 s = html_build_status(rev["STATUS"])
374 revision = rev["REVISION"]
375 s = s.replace(revision, "0")
379 yield "<tr><td>%s</td><td>%s</td></tr>" % (revision_link(myself, revision, tree), build_link(myself, tree, host, compiler, rev["REVISION"], html_build_status(rev["STATUS"])))
382 # Only print table if there was any actual data
383 yield "</tbody></table>"
386 def view_build(myself, tree, host, compiler, rev, plain_logs=False):
387 """view one build in detail"""
388 # ensure the params are valid before using them
389 assert host in hosts, "unknown host %s" % host
390 assert compiler in compilers, "unknown compiler %s" % compiler
391 assert tree in trees, "not a build tree %s" % tree
396 build = buildfarm.get_build(tree, host, compiler, rev)
397 age_mtime = build.age_mtime()
398 (revision, commit_revision, revision_time) = build.revision_details()
400 revision = commit_revision
401 status = build_status_html(myself, build)
404 assert re.match("^[0-9a-fA-F]*$", rev)
418 log = cgi.escape(log)
420 m = re.search("(.*)", log)
423 m = re.search("CFLAGS=(.*)", log)
426 m = re.search("configure options: (.*)", log)
431 err = cgi.escape(err)
432 yield '<h2>Host information:</h2>'
434 host_web_file = "../web/%s.html" % host
435 if os.path.exists(host_web_file):
436 yield util.FileLoad(host_web_file)
438 yield "<table class='real'>\n"
439 yield "<tr><td>Host:</td><td><a href='%s?function=View+Host;host=%s;tree=%s;"\
440 "compiler=%s#'>%s</a> - %s</td></tr>\n" %\
441 (myself, host, tree, compiler, host, hosts[host].platform.encode("utf-8"))
442 yield "<tr><td>Uname:</td><td>%s</td></tr>\n" % uname
443 yield "<tr><td>Tree:</td><td>%s</td></tr>\n" % tree_link(myself, tree)
444 yield "<tr><td>Build Revision:</td><td>%s</td></tr>\n" % revision_link(myself, revision, tree)
445 yield "<tr><td>Build age:</td><td><div class='age'>%s</div></td></tr>\n" % red_age(age_mtime)
446 yield "<tr><td>Status:</td><td>%s</td></tr>\n" % status
447 yield "<tr><td>Compiler:</td><td>%s</td></tr>\n" % compiler
448 yield "<tr><td>CFLAGS:</td><td>%s</td></tr>\n" % cflags
449 yield "<tr><td>configure options:</td><td>%s</td></tr>\n" % config
452 yield "".join(show_oldrevs(myself, tree, host, compiler))
454 # check the head of the output for our magic string
457 rev_var = ";revision=%s" % rev
459 yield "<div id='log'>"
462 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s"\
463 ";compiler=%s%s;plain=true' title='Switch to bland, non-javascript,"\
464 " unstyled view'>Plain View</a></p>" % (myself, host, tree, compiler, rev_var)
466 yield "<div id='actionList'>"
467 # These can be pretty wide -- perhaps we need to
468 # allow them to wrap in some way?
470 yield "<h2>No error log available</h2>\n"
472 yield "<h2>Error log:</h2>"
473 yield make_collapsible_html('action', "Error Output", "\n%s" % err, "stderr-0", "errorlog")
476 yield "<h2>No build log available</h2>"
478 yield "<h2>Build log:</h2>\n"
479 yield print_log_pretty(log)
481 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>"
484 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s;"\
485 "compiler=%s%s' title='Switch to colourful, javascript-enabled, styled"\
486 " view'>Enhanced View</a></p>" % (myself, host, tree, compiler, rev_var)
488 yield "<h2>No error log available</h2>"
490 yield '<h2>Error log:</h2>\n'
491 yield '<div id="errorLog"><pre>%s</pre></div>' % err
493 yield '<h2>No build log available</h2>'
495 yield '<h2>Build log:</h2>\n'
496 yield '<div id="buildLog"><pre>%s</pre></div>' % log
501 def view_host(myself, output_type, *requested_hosts):
502 """print the host's table of information"""
504 if output_type == 'text':
505 yield "Host summary:\n"
507 yield "<div class='build-section' id='build-summary'>"
508 yield '<h2>Host summary:</h2>'
510 for host in requested_hosts:
511 assert host in hosts, "unknown host"
513 for host in requested_hosts:
514 # make sure we have some data from it
515 if not db.has_host(host):
516 if output_type == 'text':
517 yield "<!-- skipping %s -->" % host
522 for compiler in compilers:
523 for tree in sorted(trees.keys()):
525 build = buildfarm.get_build(tree, host, compiler)
526 except data.NoSuchBuildError:
529 (revision, commit_revision, revision_time) = build.revision_details()
531 revision = commit_revision
532 age_mtime = build.age_mtime()
533 age_ctime = build.age_ctime()
534 warnings = build.err_count()
535 status = build_status_html(myself, build)
537 if output_type == 'text':
538 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
539 "Tree", "Compiler", "Build Age", "Status", "Warnings")
541 yield "<div class='host summary'>"
542 yield "<a id='host' name='host'/>"
543 yield "<h3>%s - %s</h3>" % (host, hosts[host].platform.encode("utf-8"))
544 yield "<table class='real'>"
545 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>"
548 if output_type == 'text':
549 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
550 tree, compiler, util.dhm_time(age_mtime),
551 util.strip_html(status), warnings)
554 yield "<td><span class='tree'>" + tree_link(myself, tree) +"</span>/" + compiler + "</td>"
555 yield "<td>" + revision_link(myself, revision, tree) + "</td>"
556 yield "<td><div class='age'>" + red_age(age_mtime) + "</div></td>"
557 yield "<td><div class='status'>%s</div></td>" % status
558 yield "<td>%s</td>" % warnings
562 if output_type == 'text':
565 yield "</tbody></table>"
568 deadhosts.append(host)
570 if output_type != 'text':
573 yield "".join(draw_dead_hosts(output_type, *deadhosts))
576 def subunit_to_buildfarm_result(subunit_result):
577 if subunit_result == "success":
579 elif subunit_result == "error":
581 elif subunit_result == "skip":
583 elif subunit_result == "failure":
585 elif subunit_result == "xfail":
590 def format_subunit_reason(reason):
591 reason = re.sub("^\[\n+(.*?)\n+\]$", "\\1", reason)
592 return "<div class=\"reason\">%s</div>" % reason
595 def print_log_pretty(log):
596 # prints the log in a visually appealing manner
600 # do some pretty printing for the actions
604 actionName = m.group(2)
606 # handle pretty-printing of static-analysis tools
607 if actionName == 'cc_checker':
608 output = print_log_cc_checker(output)
611 return make_collapsible_html('action', actionName, output, indice, status)
613 pattern = re.compile("(Running action\s+([\w\-]+)$(?:\s^.*$)*?\sACTION\ (PASSED|FAILED):\ ([\w\-]+)$)", re.M)
614 log = pattern.sub(pretty_print, log)
616 # log is already CGI-escaped, so handle '>' in test name by handling >
619 return make_collapsible_html('test', m.group(1), m.group(2), indice, m.group(3))
622 --==--==--==--==--==--==--==--==--==--==--.*?
623 Running\ test\ ([\w\-=,_:\ /.&;]+).*?
624 --==--==--==--==--==--==--==--==--==--==--
626 ==========================================.*?
627 TEST\ (FAILED|PASSED|SKIPPED):.*?
628 ==========================================\s+
629 """, format_stage, log)
631 def format_skip_testsuite(m):
634 return make_collapsible_html('test', m.group(1), '', indice, 'skipped')
636 log = re.sub("skip-testsuite: ([\w\-=,_:\ /.&; \(\)]+).*?",
637 format_skip_testsuite, log)
639 def format_testsuite(m):
641 testName = m.group(1)
643 status = subunit_to_buildfarm_result(m.group(3))
645 errorReason = format_subunit_reason(m.group(4))
649 return make_collapsible_html('test', testName, content+errorReason, indice, status)
651 pattern = re.compile("^testsuite: (.+)$\s((?:^.*$\s)*?)testsuite-(\w+): .*?(?:(\[$\s(?:^.*$\s)*?^\]$)|$)", re.M)
652 log = pattern.sub(format_testsuite, log)
656 return make_collapsible_html('test', m.group(1), m.group(2)+format_subunit_reason(m.group(4)), id, subunit_to_buildfarm_result(m.group(3)))
659 ^test: ([\w\-=,_:\ /.&; \(\)]+).*?
661 (success|xfail|failure|skip): [\w\-=,_:\ /.&; \(\)]+( \[.*?\])?.*?
662 """, format_test, log)
664 return "<pre>%s</pre>" % log
667 def print_log_cc_checker(input):
668 # generate pretty-printed html for static analysis tools
671 # for now, we only handle the IBM Checker's output style
672 if not re.search("^BEAM_VERSION", input):
681 for line in input.splitlines():
682 # for each line, check if the line is a new entry,
683 # otherwise, store the line under the current entry.
685 if line.startswith("-- "):
688 output += make_collapsible_html('cc_checker', title, content, id, status)
692 # clear maintenance vars
693 (inEntry, content) = (True, "")
696 m = re.match("^-- ((ERROR|WARNING|MISTAKE).*?)\s+>>>([a-zA-Z0-9]+_(\w+)_[a-zA-Z0-9]+)", line)
698 # then store the result
699 (title, status, id) = ("%s %s" % (m.group(1), m.group(4)), m.group(2), m.group(3))
700 elif line.startswith("CC_CHECKER STATUS"):
702 output += make_collapsible_html('cc_checker', title, content, id, status)
707 # not a new entry, so part of the current entry's output
708 content += "%s\n" % line
712 # This function does approximately the same as the following, following
713 # commented-out regular expression except that the regex doesn't quite
714 # handle IBM Checker's newlines quite right.
716 # --\ ((ERROR|WARNING|MISTAKE).*?)\s+
720 # }{make_collapsible_html('cc_checker', "$1 $4", $5, $3, $2)}exgs
724 def make_collapsible_html(type, title, output, id, status=""):
725 """generate html for a collapsible section
727 :param type: the logical type of it. e.g. "test" or "action"
728 :param title: the title to be displayed
730 if ((status == "" or "failed" == status.lower())):
731 icon = 'icon_hide_16.png'
733 icon = 'icon_unhide_16.png'
735 # trim leading and trailing whitespace
736 output = output.strip()
738 # note that we may be inside a <pre>, so we don't put any extra whitespace
740 ret = "<div class='%s unit %s' id='%s-%s'>" % (type, status, type, id)
741 ret += "<a href=\"javascript:handle('%s');\">" % id
742 ret += "<img id='img-%s' name='img-%s' alt='%s' src='%s' />" %(id, id, status, icon)
743 ret += "<div class='%s title'>%s</div></a>" % (type, title)
745 ret += "<div class='%s status %s'>%s</div>" % (type, status, status)
746 ret += "<div class='%s output' id='output-%s'>" % (type, id)
747 if output and len(output):
748 ret += "<pre>%s</pre>>" % (output)
749 ret += "</div></div>"
755 yield "<form method='GET'>"
756 yield "<div id='build-menu'>"
757 yield "<select name='host'>"
758 for name, host in hosts.iteritems():
759 yield "<option value='%s'>%s -- %s</option>\n" % (name, host.platform.encode("utf-8"), name)
761 yield "<select name='tree'>"
762 for tree, t in trees.iteritems():
763 yield "<option value='%s'>%s:%s</option>\n" % (tree, tree, t.branch)
765 yield "<select name='compiler'>"
766 for compiler in compilers:
767 yield "<option>%s</option>\n" % compiler
770 yield "<input type='submit' name='function' value='View Build'/>"
771 yield "<input type='submit' name='function' value='View Host'/>"
772 yield "<input type='submit' name='function' value='Recent Checkins'/>"
773 yield "<input type='submit' name='function' value='Summary'/>"
774 yield "<input type='submit' name='function' value='Recent Builds'/>"
779 def diff_pretty(diff):
780 """pretty up a diff -u"""
781 # FIXME: JRV 20101109 Use pygments for this
783 lines = diff.splitlines()
786 '^diff.*': 'diff_diff',
787 '^=.*': 'diff_separator',
788 '^Index:.*': 'diff_index',
789 '^index.*': 'diff_index',
790 '^\-.*': 'diff_removed',
791 '^\+.*': 'diff_added',
792 '^@@.*': 'diff_fragment_header'
796 for r in line_types.iterkeys():
798 line = "<span class=\"%s\">%s</span>" % (line_types[r], line)
805 def web_paths(t, paths):
806 """change the given source paths into links"""
815 fmt = " <a href=\"%s/?p=%s;a=history;f=%s%%s;h=%s;hb=%s\">%%s</a>" % (GITWEB_BASE, r, s, b, b)
819 for m in re.finditer("\s*([^\s]+)", paths):
820 ret += fmt % (m.group(1), m.group(1))
825 def history_row_html(myself, entry, tree):
826 """show one row of history table"""
827 msg = cgi.escape(entry["MESSAGE"])
828 t = time.asctime(time.gmtime(entry["DATE"]))
829 age = util.dhm_time(time()-entry["DATE"])
831 t = t.replace(" ", " ")
834 <div class=\"history_row\">
835 <div class=\"datetime\">
836 <span class=\"date\">%s</span><br />
837 <span class=\"age\">%s ago</span>""" % (t, age)
838 if entry["REVISION"]:
839 yield " - <span class=\"revision\">%s</span><br/>" % entry["REVISION"]
840 revision_url = "revision=%s" % entry["REVISION"]
842 revision_url = "author=%s" % entry["AUTHOR"]
845 <span class=\"html\"><a href=\"%s?function=diff;tree=%s;date=%s;%s\">show diffs</a></span>
847 <span class=\"text\"><a href=\"%s?function=text_diff;tree=%s;date=%s;%s\">download diffs</a></span>
849 <div class=\"history_log_message\">
853 <div class=\"author\">
854 <span class=\"label\">Author: </span>%s
855 </div>""" % (myself, tree, entry["DATE"], revision_url,
856 myself, tree, entry["DATE"], revision_url,
857 msg, entry["AUTHOR"])
859 t = db.trees.get(tree)
866 yield "<div class=\"files\"><span class=\"label\">Modified: </span>"
867 yield web_paths(t, entry["FILES"])
871 yield "<div class=\"files\"><span class=\"label\">Added: </span>"
872 yield web_paths(t, entry["ADDED"])
876 yield "<div class=\"files\"><span class=\"label\">Removed: </span>"
877 yield web_paths(t, entry["REMOVED"])
882 def history_row_text(entry, tree):
883 """show one row of history table"""
884 msg = cgi.escape(entry["MESSAGE"])
885 t = time.asctime(time.gmtime(entry["DATE"]))
886 age = util.dhm_time(time()-entry["DATE"])
888 yield "Author: %s\n" % entry["AUTHOR"]
889 if entry["REVISION"]:
890 yield "Revision: %s\n" % entry["REVISION"]
891 yield "Modified: %s\n" % entry["FILES"]
892 yield "Added: %s\n" % entry["ADDED"]
893 yield "Removed: %s\n" % entry["REMOVED"]
894 yield "\n\n%s\n\n\n" % msg
897 def show_diff(cmd, diff, text_html):
898 if text_html == "html":
899 diff = cgi.escape(diff)
900 diff = diff_pretty(diff)
901 ret = "<!-- %s -->\n" % cmd
902 ret += "<pre>%s</pre>\n" % diff
908 def buildApp(environ, start_response):
909 form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
910 fn_name = get_param(form, 'function') or ''
911 myself = wsgiref.util.application_uri(environ)
913 if standalone and environ['PATH_INFO']:
914 dir = os.path.join(os.path.dirname(__file__))
915 if re.match("^/[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)?", environ['PATH_INFO']):
916 static_file = "%s/%s" % (dir, environ['PATH_INFO'])
917 if os.path.exists(static_file):
918 tab = environ['PATH_INFO'].split('.')
923 type = mimetypes.types_map[".%s" % extension]
924 start_response('200 OK', [('Content-type', type)])
925 data = open(static_file, 'rb').read()
929 if fn_name == 'text_diff':
930 start_response('200 OK', [('Content-type', 'application/x-diff')])
931 (title, entry, tree, diffs) = history.diff(get_param(form, 'author'),
932 get_param(form, 'date'),
933 get_param(form, 'tree'),
934 get_param(form, 'revision'))
935 yield "".join(history_row_text(entry, tree))
936 for (cmd, diff) in diffs:
937 yield show_diff(cmd, diff, "text")
938 elif fn_name == 'Text_Summary':
939 start_response('200 OK', [('Content-type', 'text/plain')])
940 yield "".join(view_summary(myself, 'text'))
942 start_response('200 OK', [('Content-type', 'text/html')])
946 yield " <title>samba.org build farm</title>"
947 yield " <script language='javascript' src='/build_farm.js'></script>"
948 yield " <meta name='keywords' contents='Samba SMB CIFS Build Farm'/>"
949 yield " <meta name='description' contents='Home of the Samba Build Farm, the automated testing facility.'/>"
950 yield " <meta name='robots' contents='noindex'/>"
951 yield " <link rel='stylesheet' href='/build_farm.css' type='text/css' media='all'/>"
953 yield " <link rel='stylesheet' href='common.css' type='text/css' media='all'/>"
955 yield " <link rel='stylesheet' href='http://master.samba.org/samba/style/common.css' type='text/css' media='all'/>"
956 yield " <link rel='shortcut icon' href='http://www.samba.org/samba/images/favicon.ico'/>"
960 yield util.FileLoad(os.path.join(webdir, "header2.html"))
961 yield "".join(main_menu())
962 yield util.FileLoad(os.path.join(webdir, "header3.html"))
963 if fn_name == "View_Build":
964 plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
965 yield "".join(view_build(myself, get_param(form, "tree"), get_param(form, "host"),
966 get_param(form, "compiler"), get_param(form, "revision"), plain_logs))
967 elif fn_name == "View_Host":
968 yield "".join(view_host(myself, "html", get_param(form, 'host')))
969 elif fn_name == "Recent_Builds":
970 yield "".join(view_recent_builds(myself, get_param(form, "tree"), get_param(form, "sortby") or "revision"))
971 elif fn_name == "Recent_Checkins":
973 tree = get_param(form, "tree")
975 authors = set(["ALL"])
976 authors.update(history.authors(tree))
978 yield "<h2>Recent checkins for %s (%s branch %s)</h2>\n" % (
979 tree, t.scm, t.branch)
980 yield "<form method='GET'>"
981 yield "Select Author: "
982 yield "<select name='author'>"
983 for name in sorted(authors):
984 yield "<option>%s</option>" % name
986 yield "<input type='submit' name='sub_function' value='Refresh'/>"
987 yield "<input type='hidden' name='tree' value='%s'/>" % tree
988 yield "<input type='hidden' name='function', value='Recent Checkins'/>"
991 for entry, tree in history.history(get_param(form, 'tree'), get_param(form, 'author')):
992 yield "".join(history_row_html(myself, entry, tree))
994 elif fn_name == "diff":
995 (title, entry, tree, diffs) = history.diff(get_param(form, 'author'),
996 get_param(form, 'date'),
997 get_param(form, 'tree'),
998 get_param(form, 'revision'))
999 yield "<h2>%s</h2>" % title
1000 yield "".join(history_row_html(myself, entry, tree))
1001 for (cmd, diff) in diffs:
1002 yield show_diff(cmd, diff, "html")
1003 elif os.getenv("PATH_INFO") not in (None, "", "/"):
1004 paths = os.getenv("PATH_INFO").split('/')
1005 if paths[1] == "recent":
1006 yield "".join(view_recent_builds(myself, paths[2], get_param(form, 'sortby') or 'revision'))
1007 elif paths[1] == "host":
1008 yield "".join(view_host(myself, "html", paths[2]))
1010 yield "".join(view_summary(myself, 'html'))
1011 yield util.FileLoad(os.path.join(webdir, "footer.html"))
1015 if __name__ == '__main__':
1017 parser = optparse.OptionParser("[options]")
1018 parser.add_option("--standalone", help="Run as standalone server (useful for debugging)", action="store_true")
1019 opts, args = parser.parse_args()
1022 from wsgiref.simple_server import make_server
1023 httpd = make_server('localhost', 8000, buildApp)
1024 print "Serving on port 8000..."
1025 httpd.serve_forever()
1027 import wsgiref.handlers
1028 handler = wsgiref.handlers.CGIHandler()
1029 handler.run(buildApp)