changeset 20:467013d9d627

Add simple web interface for status reports
author Bernhard Herzog <bh@intevation.de>
date Tue, 13 Mar 2007 19:29:34 +0100
parents 0cdda44240a6
children 52a1d74084a6
files starttreepkgweb.py treepkg/web-status.html treepkg/web.py
diffstat 3 files changed, 157 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/starttreepkgweb.py	Tue Mar 13 19:29:34 2007 +0100
@@ -0,0 +1,33 @@
+#! /usr/bin/python2.4
+# Copyright (C) 2007 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh@intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+"""Starts the tree packager webinterface"""
+
+import os
+from optparse import OptionParser
+
+from treepkg.web import runserver
+
+def parse_commandline():
+    parser = OptionParser()
+    dirname = os.path.dirname(__file__)
+    parser.set_defaults(config_file=os.path.join(dirname, "treepkg.cfg"),
+                        cherrypy_config=os.path.join(dirname, "cherrypy.cfg"))
+    parser.add_option("--config-file",
+                      help=("The tree packager config file."
+                            " Default treepkg.cfg"))
+    parser.add_option("--cherrypy-config",
+                      help=("The cherrypy config file for the web interface."
+                            " Default cherrypy.cfg"))
+    return parser.parse_args()
+
+def main():
+    options, args = parse_commandline()
+    runserver(options.config_file, options.cherrypy_config)
+
+main()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/treepkg/web-status.html	Tue Mar 13 19:29:34 2007 +0100
@@ -0,0 +1,53 @@
+<html xmlns:py="http://genshi.edgewall.org/">
+  <head>
+    <title>Tree Packager Status</title>
+    <style type="text/css">
+      .statustable { background:#F4F4F4; }
+      .statustablehead { background:#E0E0E0; }
+      .statusheading { font-weight:bold; }
+      .finished { background:#C0FFC0; }
+      .inprogress { background:#FFFFC0; }
+      .error { background:#FFC0C0; }
+      td { padding:5px; background:#FFFFFF}
+    </style>
+  </head>
+  <body>
+    <h1>Tree Packager Status</h1>
+
+    <table class="statustable">
+      <tr>
+	<th class="statustablehead">Revision</th>
+	<py:for each="col in report.columns">
+	  <th class="statustablehead">${col[1]}</th>
+	</py:for>
+      </tr>
+
+      <py:for each="row in report.revisions">
+	<tr>
+	  <td>${row[0]}</td>
+	  <py:for each="col in row[1]">
+	    <py:choose>
+	      <py:when test="col">
+		<td class="${col.status.cls}">
+		  <span class="statusheading">${col.status.desc}</span><br/>
+		  Start: ${col.status.start}<br/>
+		  Stop: ${col.status.stop}<br/>
+		  <py:if test="col.revision.has_build_log">
+		    <a href="${col.name}/${col.revno}/build.log">build_log</a>
+		  </py:if>
+		</td>
+	      </py:when>
+	      <py:otherwise>
+		<td></td>
+	      </py:otherwise>
+	    </py:choose>
+	  </py:for>
+
+	</tr>
+      </py:for>
+    </table>
+
+    All times are given in UTC.
+
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/treepkg/web.py	Tue Mar 13 19:29:34 2007 +0100
@@ -0,0 +1,71 @@
+# Copyright (C) 2007 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh@intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+import os
+
+from genshi.template import TemplateLoader
+
+import cherrypy
+from cherrypy import expose
+from cherrypy.lib import cptools
+
+import report
+
+
+class Status(object):
+
+    """Implements the tree packager status pages"""
+
+    def __init__(self, treepkg_config):
+        self.treepkg_config = treepkg_config
+        self.loader = TemplateLoader([os.path.dirname(__file__)])
+
+    @expose
+    def index(self):
+        group = report.get_packager_group(self.treepkg_config)
+        tmpl = self.loader.load('web-status.html')
+        stream = tmpl.generate(report=report.prepare_report(group))
+        return stream.render('html')
+
+    def build_log_filename(self, package_line_name, revno):
+        """Returns the name of the build log file of a revision if it exists"""
+        group = report.get_packager_group(self.treepkg_config)
+        for line in group.get_package_lines():
+            if line.name == package_line_name:
+                for revision in line.get_revisions():
+                    if str(revision.revision) == revno:
+                        if revision.has_build_log():
+                            return revision.build_log
+
+    @expose
+    def default(self, *rest):
+        """Handles requests for .../pkg/revno/build.log"""
+        filename = None
+        if len(rest) == 3 and rest[2] == "build.log":
+            filename = self.build_log_filename(*rest[:2])
+        if filename is not None:
+            return cptools.serveFile(filename, contentType="text/plain")
+        else:
+            raise cherrypy.HTTPError(status="404")
+
+
+
+class TreePKG(object):
+
+    """Root object for the tree packager web interface"""
+
+    @expose
+    def index(self):
+        raise cherrypy.HTTPRedirect('/status')
+
+
+def runserver(treepkg_config, cherrypy_config):
+    cherrypy.root = TreePKG()
+    cherrypy.root.status = Status(treepkg_config=treepkg_config)
+
+    cherrypy.config.update(file=cherrypy_config)
+    cherrypy.server.start()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)