Merge branch 'query4summarypage' of git://github.com/krishnatejaperannagari/build...
authorJelmer Vernooij <jelmer@samba.org>
Sat, 2 Aug 2014 18:03:58 +0000 (20:03 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 2 Aug 2014 18:03:58 +0000 (20:03 +0200)
1  2 
buildfarm/web/__init__.py

index b1f0fb4096c3ba9411ae0a08f837bc639fb3ed60,ead25730a7599cbe5d5be9a1dc19db37707999d5..92730a0b4e3f198a1b014ef7f622690b781bce14
@@@ -1,7 -1,7 +1,7 @@@
  #!/usr/bin/python
  # This CGI script presents the results of the build_farm build
  
 -# Copyright (C) Jelmer Vernooij <jelmer@samba.org>     2010
 +# Copyright (C) Jelmer Vernooij <jelmer@samba.org>     2010-2014
  # Copyright (C) Matthieu Patou <mat@matws.net>         2010-2012
  #
  # Based on the original web/build.pl:
@@@ -33,7 -33,6 +33,7 @@@
  
  from collections import defaultdict
  import os
 +import sys
  
  from buildfarm import (
      hostdb,
@@@ -43,6 -42,7 +43,7 @@@ from buildfarm.build import 
      LogFileMissing,
      NoSuchBuildError,
      NoTestOutput,
+     BuildStatus,
      )
  
  import cgi
@@@ -126,8 -126,7 +127,8 @@@ def build_uri(myself, build)
  
  
  def build_link(myself, build):
 -    return "<a href='%s'>%s</a>" % (build_uri(myself, build), html_build_status(build.status()))
 +    return "<a href='%s'>%s</a>" % (
 +        build_uri(myself, build), html_build_status(build.status()))
  
  
  def tree_uri(myself, tree):
  
  def tree_link(myself, tree):
      """return a link to a particular tree"""
 -    return "<a href='%s' title='View recent builds for %s'>%s:%s</a>" % (tree_uri(myself, tree), tree.name, tree.name, tree.branch)
 +    return "<a href='%s' title='View recent builds for %s'>%s:%s</a>" % (
 +        tree_uri(myself, tree), tree.name, tree.name, tree.branch)
  
  
  def host_uri(myself, host):
@@@ -407,7 -405,7 +408,7 @@@ class BuildFarmPage(object)
  
  class ViewBuildPage(BuildFarmPage):
  
 -    def show_oldrevs(self, myself, build, host, compiler, limit):
 +    def show_oldrevs(self, myself, build, host, compiler, limit=None):
          """show the available old revisions, if any"""
  
          tree = build.tree
          yield "<thead><tr><th>Revision</th><th>Status</th><th>Age</th></tr></thead>\n"
          yield "<tbody>\n"
  
 -        nb = 0
 -        for old_build in old_builds:
 -            if limit >= 0 and nb >= limit:
 -                break
 -            nb = nb + 1
 +        for old_build in old_builds[:limit]:
              yield "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n" % (
                  revision_link(myself, old_build.revision, tree),
                  build_link(myself, old_build),
@@@ -727,16 -729,16 +728,16 @@@ class ViewSummaryPage(BuildFarmPage)
          # output when we want
          broken_table = ""
  
-         builds = self.buildfarm.get_last_builds()
+         builds = self.buildfarm.get_summary_builds()
  
-         for build in builds:
-             host_count[build.tree]+=1
-             status = build.status()
+         for tree, status_str in builds:
+             host_count[tree]+=1
+             status = BuildStatus.__deserialize__(status_str)
  
              if status.failed:
-                 broken_count[build.tree]+=1
+                 broken_count[tree]+=1
                  if "panic" in status.other_failures:
-                     panic_count[build.tree]+=1
+                     panic_count[tree]+=1
          return (host_count, broken_count, panic_count)
  
      def render_text(self, myself):
@@@ -886,15 -888,14 +887,15 @@@ class DiffPage(HistoryPage)
  
  class RecentCheckinsPage(HistoryPage):
  
 -    limit = 40
 +    limit = 10
  
 -    def render(self, myself, tree, author=None):
 +    def render(self, myself, tree, gitstart, author=None):
          t = self.buildfarm.trees[tree]
          interesting = list()
          authors = {"ALL": "ALL"}
          branch = t.get_branch()
          re_author = re.compile("^(.*) <(.*)>$")
 + 
          for entry in branch.log(limit=HISTORY_HORIZON):
              m = re_author.match(entry.author)
              authors[m.group(2)] = m.group(1)
          yield "<input type='hidden' name='function', value='Recent Checkins'/>"
          yield "</form>"
  
 -        for entry in interesting[:self.limit]:
 +        gitstop = gitstart + self.limit
 +
 +        for entry in interesting[gitstart:gitstop]:
              changes = branch.changes_summary(entry.revision)
              yield "".join(self.history_row_html(myself, entry, t, changes))
          yield "\n"
  
 +        yield "<form method='GET'>"
 +        yield "<div class='newform'>\n"
 +        if gitstart != 0:
 +            yield "<button name='gitstart' type='submit' value=" + str(gitstart - self.limit) + " style='position:absolute;left:0px;'>Previous</button>"
 +        if len(interesting) > gitstop:
 +            yield "<button name='gitstart' type='submit' value=" + str(gitstop) + " style='position:absolute;right:0px;'>Next</button>"
 +        yield "<input type='hidden' name='function', value='Recent Checkins'/>"
 +        yield "<input type='hidden' name='gitcount' value='%s'/>" % gitstop
 +        if author and author != "ALL":
 +            yield "<input type='hidden' name='author' value='%s'/>" % author
 +        yield "<input type='hidden' name='tree' value='%s'/>" % tree
 +        yield "</div>\n"
 +        yield "</form>"
 +        yield "<br>"
 +
  
  class BuildFarmApp(object):
  
              elif fn_name == "Recent_Checkins":
                  # validate the tree
                  author = get_param(form, 'author')
 +                gitstart = get_param(form, 'gitstart')
 +                if gitstart is None:
 +                    gitstart = 0
 +                else:
 +                    gitstart = int(gitstart)
                  page = RecentCheckinsPage(self.buildfarm)
 -                yield "".join(self.html_page(form, page.render(myself, tree, author)))
 +                yield "".join(self.html_page(form, page.render(myself, tree, gitstart, author)))
              elif fn_name == "diff":
                  revision = get_param(form, 'revision')
                  page = DiffPage(self.buildfarm)
  if __name__ == '__main__':
      import optparse
      parser = optparse.OptionParser("[options]")
 +    parser.add_option("--debug-storm", help="Enable storm debugging",
 +                      default=False, action='store_true')
      parser.add_option("--port", help="Port to listen on [localhost:8000]",
          default="localhost:8000", type=str)
      opts, args = parser.parse_args()
      except ValueError:
          address = "localhost"
          port = opts.port
 +    if opts.debug_storm:
 +        from storm.tracer import debug
 +        debug(True, stream=sys.stdout)
      httpd = make_server(address, int(port), standaloneApp)
      print "Serving on %s:%d..." % (address, int(port))
      httpd.serve_forever()