# HG changeset patch # User Bernhard Herzog # Date 1173810574 -3600 # Node ID 467013d9d627a0d605fbfedea6dd4a47a0ca458f # Parent 0cdda44240a64ff219ae6f6e54dde82e7b31ba5c Add simple web interface for status reports diff -r 0cdda44240a6 -r 467013d9d627 starttreepkgweb.py --- /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 +# +# 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() diff -r 0cdda44240a6 -r 467013d9d627 treepkg/web-status.html --- /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 @@ + + + Tree Packager Status + + + +

Tree Packager Status

+ + + + + + + + + + + + + + + + + + + + + + + + + +
Revision${col[1]}
${row[0]} + ${col.status.desc}
+ Start: ${col.status.start}
+ Stop: ${col.status.stop}
+ + build_log + +
+ + All times are given in UTC. + + + diff -r 0cdda44240a6 -r 467013d9d627 treepkg/web.py --- /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 +# +# 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()