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 (
46 webdir = os.path.dirname(__file__)
47 basedir = os.path.abspath(os.path.join(webdir, ".."))
49 db = data.BuildResultStore(basedir)
50 history = history.History(db)
51 hostsdb = open_hostdb()
53 compilers = db.compilers
54 # host.properties are unicode object and the framework expect string object
55 hosts = dict([(host.name.encode("utf-8"), host) for host in hostsdb.hosts()])
59 UNPACKED_BASE = "http://svn.samba.org/ftp/unpacked"
60 GITWEB_BASE = "http://gitweb.samba.org"
62 # this is automatically filled in
65 def get_param(form, param):
66 """get a param from the request, after sanitizing it"""
70 result = [s.replace(" ", "_") for s in form.getlist(param)]
73 if re.match("[^a-zA-Z0-9\-\_\.]", entry):
74 raise Exception("Parameter %s is invalid" % param)
79 def build_link(myself, tree, host, compiler, rev, status):
81 opt_rev = ';revision=%s' % rev
84 return "<a href='%s?function=View+Build;host=%s;tree=%s;compiler=%s%s'>%s</a>" % (
85 myself, host, tree, compiler, opt_rev, status)
88 def html_build_status(status):
89 def span(classname, contents):
90 return "<span class=\"%s\">%s</span>" % (classname, contents)
92 def span_status(n, st):
95 return span("status checker", "ok")
97 return span("status checker", st)
100 return span("status unknown", "?")
102 return span("status passed", "ok")
104 return span("status failed", st)
107 if "panic" in status.other_failures:
108 ostatus += "/"+span("status panic", "PANIC")
109 if "disk full" in status.other_failures:
110 ostatus += "/"+span("status failed", "disk full")
111 if "timeout" in status.other_failures:
112 ostatus += "/"+span("status failed", "timeout")
113 if "inconsistent test result" in status.other_failures:
114 ostatus += "/"+span("status failed", "unexpected return code")
115 bstatus = "/".join([span_status(n, s) for (n, s) in status.stages])
118 return bstatus + ostatus
121 def build_status_html(myself, build):
122 rawstatus = build.status()
123 status = html_build_status(rawstatus)
124 return build_link(myself, build.tree, build.host, build.compiler, build.rev, status)
128 """show an age as a string"""
130 return "<span clsas='old'>%s</span>" % util.dhm_time(age)
131 return util.dhm_time(age)
134 def build_status_vals(status):
135 """translate a status into a set of int representing status"""
136 status = util.strip_html(status)
138 status = status.replace("ok", "0")
139 status = status.replace("-", "0")
140 status = status.replace("?", "0.1")
141 status = status.replace("PANIC", "1")
143 return status.split("/")
146 def view_summary(myself, output_type):
147 """view build summary"""
155 # zero broken and panic counters
157 broken_count[tree] = 0
158 panic_count[tree] = 0
161 # set up a variable to store the broken builds table's code, so we can
162 # output when we want
166 # for the text report, include the current time
167 if output_type == 'text':
169 yield "Build status as of %s\n\n" % t
171 for host in hosts.values():
172 for compiler in compilers:
175 build = db.get_build(tree, host.name.encode("utf-8"), compiler)
176 status = build_status_html(myself, build)
177 except data.NoSuchBuildError:
179 age_mtime = build.age_mtime()
182 if "status failed" in status:
183 broken_count[tree]+=1
184 if "PANIC" in status:
187 if output_type == 'text':
188 yield "Build counts:\n"
189 yield "%-12s %-6s %-6s %-6s\n" % ("Tree", "Total", "Broken", "Panic")
191 yield "<div id='build-counts' class='build-section'>"
192 yield "<h2>Build counts:</h2>"
193 yield "<table class='real'>"
194 yield "<thead><tr><th>Tree</th><th>Total</th><th>Broken</th><th>Panic</th><th>Test coverage</th></tr></thead>"
197 for tree in sorted(trees.keys()):
198 if output_type == 'text':
199 yield "%-12s %-6s %-6s %-6s\n" % (tree, host_count[tree],
200 broken_count[tree], panic_count[tree])
203 yield "<td>%s</td>" % tree_link(myself, tree)
204 yield "<td>%s</td>" % host_count[tree]
205 yield "<td>%s</td>" % broken_count[tree]
206 if panic_count[tree]:
207 yield "<td class='panic'>"
210 yield "%d</td>" % panic_count[tree]
212 lcov_status = db.lcov_status(tree)
213 except data.NoSuchBuildError:
216 if lcov_status is not None:
217 yield "<td><a href=\"/lcov/data/%s/%s\">%s %%</a></td>" % (db.LCOVHOST, tree, lcov_status)
222 if output_type == 'text':
225 yield "</tbody></table>"
229 def revision_link(myself, revision, tree):
230 """return a link to a particular revision"""
232 revision = revision.lstrip()
237 if len(revision) == 40:
238 rev_short = re.sub("(^.{7}).*", "\\1(git)", rev_short)
240 return "<a href='%s?function=diff;tree=%s;revision=%s' title='View Diff for %s'>%s</a>" % (myself, tree, revision, revision, rev_short)
243 def tree_link(myself, tree):
244 # return a link to a particular tree
247 branch = ":%s" % trees[tree].branch
249 return "<a href='%s?function=Recent+Builds;tree=%s' title='View recent builds for %s'>%s%s</a>" % (myself, tree, tree, tree, branch)
252 def view_recent_builds(myself, tree, sort_by):
253 """Draw the "recent builds" view"""
260 def status_cmp(a, b):
262 #put other failure on top
263 if len(b.other_failures):
265 if len(a.other_failures):
277 if sa[0] == "TEST" and sa[1] == 0:
279 if sb[0] == "TEST" and sb[1] == 0:
282 return (sb[-1] <= sb[-1])
285 "revision": lambda a, b: cmp(a[7], b[7]),
286 "age": lambda a, b: cmp(a[0], b[0]),
287 "host": lambda a, b: cmp(a[2], b[2]),
288 "platform": lambda a, b: cmp(a[1], b[1]),
289 "compiler": lambda a, b: cmp(a[3], b[3]),
290 "status": lambda a, b: status_cmp(a[6], b[6]),
293 assert tree in trees, "not a build tree"
294 assert sort_by in cmp_funcs, "not a valid sort"
298 for host in hosts.values():
299 for compiler in compilers:
301 build = db.get_build(tree, host.name.encode("utf-8"), compiler)
302 status = build_status_html(myself, build)
303 except data.NoSuchBuildError:
306 age_mtime = build.age_mtime()
307 age_ctime = build.age_ctime()
308 (revision, commit_revision, revision_time) = build.revision_details()
310 revision = commit_revision
312 all_builds.append([age_ctime,
313 host.platform.encode("utf-8"),
314 "<a href='%s?function=View+Host;host=%s;tree=%s;compiler=%s#%s'>%s</a>"
315 % (myself, host.name.encode("utf-8"),
316 tree, compiler, host.name.encode("utf-8"),
317 host.name.encode("utf-8")),
318 compiler, tree, status, build.status(),
319 revision_link(myself, revision, tree),
322 all_builds.sort(cmp_funcs[sort_by])
324 sorturl = "%s?tree=%s;function=Recent+Builds" % (myself, tree)
326 yield "<div id='recent-builds' class='build-section'>"
327 yield "<h2>Recent builds of %s (%s branch %s)</h2>" % (tree, t.scm, t.branch)
328 yield "<table class='real'>"
331 yield "<th><a href='%s;sortby=age' title='Sort by build age'>Age</a></th>" % sorturl
332 yield "<th><a href='%s;sortby=revision' title='Sort by build revision'>Revision</a></th>" % sorturl
333 yield "<th>Tree</th>"
334 yield "<th><a href='%s;sortby=platform' title='Sort by platform'>Platform</a></th>" % sorturl
335 yield "<th><a href='%s;sortby=host' title='Sort by host'>Host</a></th>" % sorturl
336 yield "<th><a href='%s;sortby=compiler' title='Sort by compiler'>Compiler</a></th>" % sorturl
337 yield "<th><a href='%s;sortby=status' title='Sort by status'>Status</a></th>" % sorturl
340 for build in all_builds:
342 yield "<td>%s</td>" % util.dhm_time(build[0])
343 yield "<td>%s</td>" % build[7]
344 yield "<td>%s</td>" % build[4]
345 yield "<td>%s</td>" % build[1]
346 yield "<td>%s</td>" % build[2]
347 yield "<td>%s</td>" % build[3]
348 yield "<td>%s</td>" % build[5]
350 yield "</tbody></table>"
354 def draw_dead_hosts(output_type, *deadhosts):
355 """Draw the "dead hosts" table"""
357 # don't output anything if there are no dead hosts
358 if len(deadhosts) == 0:
361 # don't include in text report
362 if output_type == "text":
365 yield "<div class='build-section' id='dead-hosts'>"
366 yield "<h2>Dead Hosts:</h2>"
367 yield "<table class='real'>"
368 yield "<thead><tr><th>Host</th><th>OS</th><th>Min Age</th></tr></thead>"
371 for host in deadhosts:
372 age_ctime = db.host_age(host)
373 yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" %\
374 (host,hosts[host].platform.encode("utf-8"),
375 util.dhm_time(age_ctime))
377 yield "</tbody></table>"
381 def show_oldrevs(myself, tree, host, compiler):
382 """show the available old revisions, if any"""
383 revs = db.get_old_revs(tree, host, compiler)
388 yield "<h2>Older builds:</h2>"
390 yield "<table class='real'>"
391 yield "<thead><tr><th>Revision</th><th>Status</th></tr></thead>"
396 s = html_build_status(rev["STATUS"])
397 revision = rev["REVISION"]
398 s = s.replace(revision, "0")
402 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"])))
405 # Only print table if there was any actual data
406 yield "</tbody></table>"
409 def view_build(myself, tree, host, compiler, rev, plain_logs=False):
410 """view one build in detail"""
411 # ensure the params are valid before using them
412 assert host in hosts, "unknown host %s" % host
413 assert compiler in compilers, "unknown compiler %s" % compiler
414 assert tree in trees, "not a build tree %s" % tree
419 build = db.get_build(tree, host, compiler, rev)
420 age_mtime = build.age_mtime()
421 (revision, commit_revision, revision_time) = build.revision_details()
423 revision = commit_revision
424 status = build_status_html(myself, build)
427 assert re.match("^[0-9a-fA-F]*$", rev)
441 log = cgi.escape(log)
443 m = re.search("(.*)", log)
446 m = re.search("CFLAGS=(.*)", log)
449 m = re.search("configure options: (.*)", log)
454 err = cgi.escape(err)
455 yield '<h2>Host information:</h2>'
457 host_web_file = "../web/%s.html" % host
458 if os.path.exists(host_web_file):
459 yield util.FileLoad(host_web_file)
461 yield "<table class='real'>\n"
462 yield "<tr><td>Host:</td><td><a href='%s?function=View+Host;host=%s;tree=%s;"\
463 "compiler=%s#'>%s</a> - %s</td></tr>\n" %\
464 (myself, host, tree, compiler, host, hosts[host].platform.encode("utf-8"))
465 yield "<tr><td>Uname:</td><td>%s</td></tr>\n" % uname
466 yield "<tr><td>Tree:</td><td>%s</td></tr>\n" % tree_link(myself, tree)
467 yield "<tr><td>Build Revision:</td><td>%s</td></tr>\n" % revision_link(myself, revision, tree)
468 yield "<tr><td>Build age:</td><td><div class='age'>%s</div></td></tr>\n" % red_age(age_mtime)
469 yield "<tr><td>Status:</td><td>%s</td></tr>\n" % status
470 yield "<tr><td>Compiler:</td><td>%s</td></tr>\n" % compiler
471 yield "<tr><td>CFLAGS:</td><td>%s</td></tr>\n" % cflags
472 yield "<tr><td>configure options:</td><td>%s</td></tr>\n" % config
475 yield "".join(show_oldrevs(myself, tree, host, compiler))
477 # check the head of the output for our magic string
480 rev_var = ";revision=%s" % rev
482 yield "<div id='log'>"
485 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s"\
486 ";compiler=%s%s;plain=true' title='Switch to bland, non-javascript,"\
487 " unstyled view'>Plain View</a></p>" % (myself, host, tree, compiler, rev_var)
489 yield "<div id='actionList'>"
490 # These can be pretty wide -- perhaps we need to
491 # allow them to wrap in some way?
493 yield "<h2>No error log available</h2>\n"
495 yield "<h2>Error log:</h2>"
496 yield make_collapsible_html('action', "Error Output", "\n%s" % err, "stderr-0", "errorlog")
499 yield "<h2>No build log available</h2>"
501 yield "<h2>Build log:</h2>\n"
502 yield print_log_pretty(log)
504 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>"
507 yield "<p>Switch to the <a href='%s?function=View+Build;host=%s;tree=%s;"\
508 "compiler=%s%s' title='Switch to colourful, javascript-enabled, styled"\
509 " view'>Enhanced View</a></p>" % (myself, host, tree, compiler, rev_var)
511 yield "<h2>No error log available</h2>"
513 yield '<h2>Error log:</h2>\n'
514 yield '<div id="errorLog"><pre>%s</pre></div>' % err
516 yield '<h2>No build log available</h2>'
518 yield '<h2>Build log:</h2>\n'
519 yield '<div id="buildLog"><pre>%s</pre></div>' % log
524 def view_host(myself, output_type, *requested_hosts):
525 """print the host's table of information"""
527 if output_type == 'text':
528 yield "Host summary:\n"
530 yield "<div class='build-section' id='build-summary'>"
531 yield '<h2>Host summary:</h2>'
533 for host in requested_hosts:
534 assert host in hosts, "unknown host"
536 for host in requested_hosts:
537 # make sure we have some data from it
538 if not db.has_host(host):
539 if output_type == 'text':
540 yield "<!-- skipping %s -->" % host
545 for compiler in compilers:
546 for tree in sorted(trees.keys()):
548 build = db.get_build(tree, host, compiler)
549 except data.NoSuchBuildError:
552 (revision, commit_revision, revision_time) = build.revision_details()
554 revision = commit_revision
555 age_mtime = build.age_mtime()
556 age_ctime = build.age_ctime()
557 warnings = build.err_count()
558 status = build_status_html(myself, build)
560 if output_type == 'text':
561 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
562 "Tree", "Compiler", "Build Age", "Status", "Warnings")
564 yield "<div class='host summary'>"
565 yield "<a id='host' name='host'/>"
566 yield "<h3>%s - %s</h3>" % (host, hosts[host].platform.encode("utf-8"))
567 yield "<table class='real'>"
568 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>"
571 if output_type == 'text':
572 yield "%-12s %-10s %-10s %-10s %-10s\n" % (
573 tree, compiler, util.dhm_time(age_mtime),
574 util.strip_html(status), warnings)
577 yield "<td><span class='tree'>" + tree_link(myself, tree) +"</span>/" + compiler + "</td>"
578 yield "<td>" + revision_link(myself, revision, tree) + "</td>"
579 yield "<td><div class='age'>" + red_age(age_mtime) + "</div></td>"
580 yield "<td><div class='status'>%s</div></td>" % status
581 yield "<td>%s</td>" % warnings
585 if output_type == 'text':
588 yield "</tbody></table>"
591 deadhosts.append(host)
593 if output_type != 'text':
596 yield "".join(draw_dead_hosts(output_type, *deadhosts))
599 def subunit_to_buildfarm_result(subunit_result):
600 if subunit_result == "success":
602 elif subunit_result == "error":
604 elif subunit_result == "skip":
606 elif subunit_result == "failure":
608 elif subunit_result == "xfail":
613 def format_subunit_reason(reason):
614 reason = re.sub("^\[\n+(.*?)\n+\]$", "\\1", reason)
615 return "<div class=\"reason\">%s</div>" % reason
618 def print_log_pretty(log):
619 # prints the log in a visually appealing manner
623 # do some pretty printing for the actions
627 actionName = m.group(2)
629 # handle pretty-printing of static-analysis tools
630 if actionName == 'cc_checker':
631 output = print_log_cc_checker(output)
634 return make_collapsible_html('action', actionName, output, indice, status)
636 pattern = re.compile("(Running action\s+([\w\-]+)$(?:\s^.*$)*?\sACTION\ (PASSED|FAILED):\ ([\w\-]+)$)", re.M)
637 log = pattern.sub(pretty_print, log)
639 # log is already CGI-escaped, so handle '>' in test name by handling >
642 return make_collapsible_html('test', m.group(1), m.group(2), indice, m.group(3))
645 --==--==--==--==--==--==--==--==--==--==--.*?
646 Running\ test\ ([\w\-=,_:\ /.&;]+).*?
647 --==--==--==--==--==--==--==--==--==--==--
649 ==========================================.*?
650 TEST\ (FAILED|PASSED|SKIPPED):.*?
651 ==========================================\s+
652 """, format_stage, log)
654 def format_skip_testsuite(m):
657 return make_collapsible_html('test', m.group(1), '', indice, 'skipped')
659 log = re.sub("skip-testsuite: ([\w\-=,_:\ /.&; \(\)]+).*?",
660 format_skip_testsuite, log)
662 def format_testsuite(m):
664 testName = m.group(1)
666 status = subunit_to_buildfarm_result(m.group(3))
668 errorReason = format_subunit_reason(m.group(4))
672 return make_collapsible_html('test', testName, content+errorReason, indice, status)
674 pattern = re.compile("^testsuite: (.+)$\s((?:^.*$\s)*?)testsuite-(\w+): .*?(?:(\[$\s(?:^.*$\s)*?^\]$)|$)", re.M)
675 log = pattern.sub(format_testsuite, log)
679 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)))
682 ^test: ([\w\-=,_:\ /.&; \(\)]+).*?
684 (success|xfail|failure|skip): [\w\-=,_:\ /.&; \(\)]+( \[.*?\])?.*?
685 """, format_test, log)
687 return "<pre>%s</pre>" % log
690 def print_log_cc_checker(input):
691 # generate pretty-printed html for static analysis tools
694 # for now, we only handle the IBM Checker's output style
695 if not re.search("^BEAM_VERSION", input):
704 for line in input.splitlines():
705 # for each line, check if the line is a new entry,
706 # otherwise, store the line under the current entry.
708 if line.startswith("-- "):
711 output += make_collapsible_html('cc_checker', title, content, id, status)
715 # clear maintenance vars
716 (inEntry, content) = (True, "")
719 m = re.match("^-- ((ERROR|WARNING|MISTAKE).*?)\s+>>>([a-zA-Z0-9]+_(\w+)_[a-zA-Z0-9]+)", line)
721 # then store the result
722 (title, status, id) = ("%s %s" % (m.group(1), m.group(4)), m.group(2), m.group(3))
723 elif line.startswith("CC_CHECKER STATUS"):
725 output += make_collapsible_html('cc_checker', title, content, id, status)
730 # not a new entry, so part of the current entry's output
731 content += "%s\n" % line
735 # This function does approximately the same as the following, following
736 # commented-out regular expression except that the regex doesn't quite
737 # handle IBM Checker's newlines quite right.
739 # --\ ((ERROR|WARNING|MISTAKE).*?)\s+
743 # }{make_collapsible_html('cc_checker', "$1 $4", $5, $3, $2)}exgs
747 def make_collapsible_html(type, title, output, id, status=""):
748 """generate html for a collapsible section
750 :param type: the logical type of it. e.g. "test" or "action"
751 :param title: the title to be displayed
753 if ((status == "" or "failed" == status.lower())):
754 icon = 'icon_hide_16.png'
756 icon = 'icon_unhide_16.png'
758 # trim leading and trailing whitespace
759 output = output.strip()
761 # note that we may be inside a <pre>, so we don't put any extra whitespace
763 ret = "<div class='%s unit %s' id='%s-%s'>" % (type, status, type, id)
764 ret += "<a href=\"javascript:handle('%s');\">" % id
765 ret += "<img id='img-%s' name='img-%s' alt='%s' src='%s' />" %(id, id, status, icon)
766 ret += "<div class='%s title'>%s</div></a>" % (type, title)
768 ret += "<div class='%s status %s'>%s</div>" % (type, status, status)
769 ret += "<div class='%s output' id='output-%s'>" % (type, id)
770 if output and len(output):
771 ret += "<pre>%s</pre>>" % (output)
772 ret += "</div></div>"
778 yield "<form method='GET'>"
779 yield "<div id='build-menu'>"
780 yield "<select name='host'>"
781 for name, host in hosts.iteritems():
782 yield "<option value='%s'>%s -- %s</option>\n" % (name, host.platform.encode("utf-8"), name)
784 yield "<select name='tree'>"
785 for tree, t in trees.iteritems():
786 yield "<option value='%s'>%s:%s</option>\n" % (tree, tree, t.branch)
788 yield "<select name='compiler'>"
789 for compiler in compilers:
790 yield "<option>%s</option>\n" % compiler
793 yield "<input type='submit' name='function' value='View Build'/>"
794 yield "<input type='submit' name='function' value='View Host'/>"
795 yield "<input type='submit' name='function' value='Recent Checkins'/>"
796 yield "<input type='submit' name='function' value='Summary'/>"
797 yield "<input type='submit' name='function' value='Recent Builds'/>"
802 def diff_pretty(diff):
803 """pretty up a diff -u"""
804 # FIXME: JRV 20101109 Use pygments for this
806 lines = diff.splitlines()
809 '^diff.*': 'diff_diff',
810 '^=.*': 'diff_separator',
811 '^Index:.*': 'diff_index',
812 '^index.*': 'diff_index',
813 '^\-.*': 'diff_removed',
814 '^\+.*': 'diff_added',
815 '^@@.*': 'diff_fragment_header'
819 for r in line_types.iterkeys():
821 line = "<span class=\"%s\">%s</span>" % (line_types[r], line)
828 def web_paths(t, paths):
829 """change the given source paths into links"""
838 fmt = " <a href=\"%s/?p=%s;a=history;f=%s%%s;h=%s;hb=%s\">%%s</a>" % (GITWEB_BASE, r, s, b, b)
842 for m in re.finditer("\s*([^\s]+)", paths):
843 ret += fmt % (m.group(1), m.group(1))
848 def history_row_html(myself, entry, tree):
849 """show one row of history table"""
850 msg = cgi.escape(entry["MESSAGE"])
851 t = time.asctime(time.gmtime(entry["DATE"]))
852 age = util.dhm_time(time()-entry["DATE"])
854 t = t.replace(" ", " ")
857 <div class=\"history_row\">
858 <div class=\"datetime\">
859 <span class=\"date\">%s</span><br />
860 <span class=\"age\">%s ago</span>""" % (t, age)
861 if entry["REVISION"]:
862 yield " - <span class=\"revision\">%s</span><br/>" % entry["REVISION"]
863 revision_url = "revision=%s" % entry["REVISION"]
865 revision_url = "author=%s" % entry["AUTHOR"]
868 <span class=\"html\"><a href=\"%s?function=diff;tree=%s;date=%s;%s\">show diffs</a></span>
870 <span class=\"text\"><a href=\"%s?function=text_diff;tree=%s;date=%s;%s\">download diffs</a></span>
872 <div class=\"history_log_message\">
876 <div class=\"author\">
877 <span class=\"label\">Author: </span>%s
878 </div>""" % (myself, tree, entry["DATE"], revision_url,
879 myself, tree, entry["DATE"], revision_url,
880 msg, entry["AUTHOR"])
882 t = db.trees.get(tree)
889 yield "<div class=\"files\"><span class=\"label\">Modified: </span>"
890 yield web_paths(t, entry["FILES"])
894 yield "<div class=\"files\"><span class=\"label\">Added: </span>"
895 yield web_paths(t, entry["ADDED"])
899 yield "<div class=\"files\"><span class=\"label\">Removed: </span>"
900 yield web_paths(t, entry["REMOVED"])
905 def history_row_text(entry, tree):
906 """show one row of history table"""
907 msg = cgi.escape(entry["MESSAGE"])
908 t = time.asctime(time.gmtime(entry["DATE"]))
909 age = util.dhm_time(time()-entry["DATE"])
911 yield "Author: %s\n" % entry["AUTHOR"]
912 if entry["REVISION"]:
913 yield "Revision: %s\n" % entry["REVISION"]
914 yield "Modified: %s\n" % entry["FILES"]
915 yield "Added: %s\n" % entry["ADDED"]
916 yield "Removed: %s\n" % entry["REMOVED"]
917 yield "\n\n%s\n\n\n" % msg
920 def show_diff(cmd, diff, text_html):
921 if text_html == "html":
922 diff = cgi.escape(diff)
923 diff = diff_pretty(diff)
924 ret = "<!-- %s -->\n" % cmd
925 ret += "<pre>%s</pre>\n" % diff
931 def buildApp(environ, start_response):
932 form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
933 fn_name = get_param(form, 'function') or ''
934 myself = wsgiref.util.application_uri(environ)
936 if standalone and environ['PATH_INFO']:
937 dir = os.path.join(os.path.dirname(__file__))
938 static_file = "%s/%s" % (dir, environ['PATH_INFO'])
939 if os.path.exists(static_file):
940 tab = environ['PATH_INFO'].split('.')
945 type = mimetypes.types_map[".%s" % extension]
946 start_response('200 OK', [('Content-type', type)])
947 data = open(static_file, 'rb').read()
951 if fn_name == 'text_diff':
952 start_response('200 OK', [('Content-type', 'application/x-diff')])
953 (title, entry, tree, diffs) = history.diff(get_param(form, 'author'),
954 get_param(form, 'date'),
955 get_param(form, 'tree'),
956 get_param(form, 'revision'))
957 yield "".join(history_row_text(entry, tree))
958 for (cmd, diff) in diffs:
959 yield show_diff(cmd, diff, "text")
960 elif fn_name == 'Text_Summary':
961 start_response('200 OK', [('Content-type', 'text/plain')])
962 yield "".join(view_summary(myself, 'text'))
964 start_response('200 OK', [('Content-type', 'text/html')])
968 yield " <title>samba.org build farm</title>"
969 yield " <script language='javascript' src='/build_farm.js'></script>"
970 yield " <meta name='keywords' contents='Samba SMB CIFS Build Farm'/>"
971 yield " <meta name='description' contents='Home of the Samba Build Farm, the automated testing facility.'/>"
972 yield " <meta name='robots' contents='noindex'/>"
973 yield " <link rel='stylesheet' href='/build_farm.css' type='text/css' media='all'/>"
975 yield " <link rel='stylesheet' href='common.css' type='text/css' media='all'/>"
977 yield " <link rel='stylesheet' href='http://master.samba.org/samba/style/common.css' type='text/css' media='all'/>"
978 yield " <link rel='shortcut icon' href='http://www.samba.org/samba/images/favicon.ico'/>"
982 yield util.FileLoad(os.path.join(webdir, "header2.html"))
983 yield "".join(main_menu())
984 yield util.FileLoad(os.path.join(webdir, "header3.html"))
985 if fn_name == "View_Build":
986 plain_logs = (get_param(form, "plain") is not None and get_param(form, "plain").lower() in ("yes", "1", "on", "true", "y"))
987 yield "".join(view_build(myself, get_param(form, "tree"), get_param(form, "host"),
988 get_param(form, "compiler"), get_param(form, "revision"), plain_logs))
989 elif fn_name == "View_Host":
990 yield "".join(view_host(myself, "html", get_param(form, 'host')))
991 elif fn_name == "Recent_Builds":
992 yield "".join(view_recent_builds(myself, get_param(form, "tree"), get_param(form, "sortby") or "revision"))
993 elif fn_name == "Recent_Checkins":
995 tree = get_param(form, "tree")
997 authors = set(["ALL"])
998 authors.update(history.authors(tree))
1000 yield "<h2>Recent checkins for %s (%s branch %s)</h2>\n" % (
1001 tree, t.scm, t.branch)
1002 yield "<form method='GET'>"
1003 yield "Select Author: "
1004 yield "<select name='author'>"
1005 for name in sorted(authors):
1006 yield "<option>%s</option>" % name
1008 yield "<input type='submit' name='sub_function' value='Refresh'/>"
1009 yield "<input type='hidden' name='tree' value='%s'/>" % tree
1010 yield "<input type='hidden' name='function', value='Recent Checkins'/>"
1013 for entry, tree in history.history(get_param(form, 'tree'), get_param(form, 'author')):
1014 yield "".join(history_row_html(myself, entry, tree))
1016 elif fn_name == "diff":
1017 (title, entry, tree, diffs) = history.diff(get_param(form, 'author'),
1018 get_param(form, 'date'),
1019 get_param(form, 'tree'),
1020 get_param(form, 'revision'))
1021 yield "<h2>%s</h2>" % title
1022 yield "".join(history_row_html(myself, entry, tree))
1023 for (cmd, diff) in diffs:
1024 yield show_diff(cmd, diff, "html")
1025 elif os.getenv("PATH_INFO") not in (None, "", "/"):
1026 paths = os.getenv("PATH_INFO").split('/')
1027 if paths[1] == "recent":
1028 yield "".join(view_recent_builds(myself, paths[2], get_param(form, 'sortby') or 'revision'))
1029 elif paths[1] == "host":
1030 yield "".join(view_host(myself, "html", paths[2]))
1032 yield "".join(view_summary(myself, 'html'))
1033 yield util.FileLoad(os.path.join(webdir, "footer.html"))
1037 if __name__ == '__main__':
1039 parser = optparse.OptionParser("[options]")
1040 parser.add_option("--standalone", help="Run as standalone server (useful for debugging)", action="store_true")
1041 opts, args = parser.parse_args()
1044 from wsgiref.simple_server import make_server
1045 httpd = make_server('localhost', 8000, buildApp)
1046 print "Serving on port 8000..."
1047 httpd.serve_forever()
1049 import wsgiref.handlers
1050 handler = wsgiref.handlers.CGIHandler()
1051 handler.run(buildApp)