aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2008-11-08 20:30:01 +0100
committerGuido Guenther <agx@sigxcpu.org>2008-11-08 20:30:01 +0100
commiteedb25016b89e8090f35c4b4cc86c513264bb63a (patch)
tree44b13c9b0a152df86f37f5dd60dd96242749fd2c
parent3b28bc894e71df060d2895f506ed1958e43d6110 (diff)
add cgi
-rwxr-xr-xindex.cgi144
-rw-r--r--templates/index.html41
2 files changed, 185 insertions, 0 deletions
diff --git a/index.cgi b/index.cgi
new file mode 100755
index 0000000..20a9f9e
--- /dev/null
+++ b/index.cgi
@@ -0,0 +1,144 @@
+#!/usr/bin/python -u
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2008 Guido Guenther <agx@sigxcpu.org>
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+"""Link Debian changelog entries to the VCS"""
+
+import cgi
+import os
+import re
+import sys
+#import cgitb; cgitb.enable(display=0, logdir='/tmp')
+import urlgrabber
+from lxml import etree
+from genshi.template import TemplateLoader
+import vcsbrowsers
+from htmlchangelog import HTMLChangelog
+
+VERSION="0.0.1"
+XMLNS='http://www.w3.org/1999/xhtml'
+PTS='http://packages.qa.debian.org'
+PKGNAMERE="[a-zA-Z0-9.+\-]+$"
+
+
+def fetch_changelog(cl_url):
+ changelog = urlgrabber.urlread(cl_url).decode('utf-8')
+ return changelog
+
+
+def fetch_pts_page(package):
+ pts = None
+ try:
+ url = "%s/%s" % (PTS, package)
+ pts = urlgrabber.urlopen(url)
+ except urlgrabber.grabber.URLGrabError, (code, msg):
+ if code == 14:
+ raise Exception, "Can't find package '%s' on '%s'" % (package, PTS)
+ else:
+ raise
+ return pts
+
+
+def parse_pts_xhtml(pts):
+ cl_url = None
+ vcs_url = None
+ vcs = None
+
+ tree = etree.parse(pts)
+ searcher = etree.ETXPath('/{%s}html/{%s}body//{%s}a[@href]' % (XMLNS, XMLNS, XMLNS))
+ result = searcher(tree)
+
+ for r in result:
+ if r.text == "Changelog":
+ cl_url = r.attrib['href']
+ elif r.text == "browse":
+ vcs_url = r.attrib['href']
+ parent = r.getparent()
+ vcs = parent.getchildren()[0].text.lower()
+ return cl_url, vcs_url, vcs
+
+
+def get_vcsbrowser(vcs, vcs_url):
+ if vcs == "git":
+ return vcsbrowsers.GitWebBrowser(vcs_url)
+ elif vcs == "Mercurial":
+ return vcsbrowsers.HgBrowser(vcs_url)
+
+
+def render_search_page(title, pkg=None, err=None):
+ loader = TemplateLoader('templates')
+ tmpl = loader.load('index.html')
+ print tmpl.generate(title=title, pkg=pkg,
+ err=err).render('xhtml', doctype='xhtml-strict')
+
+
+def render_changelog_page(cl):
+ print cl
+
+
+def main(argv):
+ title = "cl2vcs %s" % VERSION
+ err = ""
+
+ print "Content-Type: text/html; charset=utf-8"
+ print
+
+ try:
+ form = cgi.FieldStorage()
+
+ if form.has_key('pkg'):
+ pkg = form.getfirst('pkg').decode('utf-8').strip()
+ else:
+ pkg = None
+
+ if pkg:
+ if not re.match(PKGNAMERE, pkg):
+ return render_search_page(title=title, err=u"Invalid package name: '%s'" % pkg)
+ else:
+ return render_search_page(title=title, err=err)
+
+ try:
+ pts = fetch_pts_page(pkg)
+ except Exception, exc_err:
+ err=exc_err
+ pts = None
+
+ if not pts:
+ return render_search_page(title=title, pkg=pkg, err=err)
+
+ cl_url, vcs_url, vcs = parse_pts_xhtml(pts)
+ if cl_url == None:
+ return render_search_page(pkg=pkg, err=err)
+
+ cl_text = fetch_changelog(cl_url)
+ if vcs and vcs_url:
+ vcsbrowser = get_vcsbrowser(vcs, vcs_url)
+ else:
+ vcsbrowser = None
+ cl = HTMLChangelog(cl_text, vcsbrowser=vcsbrowser)
+ if cl:
+ render_changelog_page(cl)
+ except Exception, err:
+ import traceback
+ traceback.print_exc(file=sys.stderr)
+ render_search_page(title=title, err="Unknown error")
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))
+
+# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
diff --git a/templates/index.html b/templates/index.html
new file mode 100644
index 0000000..186626c
--- /dev/null
+++ b/templates/index.html
@@ -0,0 +1,41 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:py="http://genshi.edgewall.org/">
+ <head>
+ <title>$title</title>
+ </head>
+ <body class="index">
+ <div id="header">
+ <h1>$title</h1>
+ </div>
+
+ <form action="/cl2vcs/index.cgi" method="get">
+ <p>
+ <label for="pkg">Source Package:</label>
+ <input type="text" name="pkg" id="pkg"/>
+ <input type="submit" value="cl2vcs"/>
+ </p>
+ </form>
+
+ <div py:if="err">
+ <em>${err}</em>
+ </div>
+
+ <div id="description">
+ <hr />
+ <a href="http://honk.sigxcpu.org/git/cl2vcs.git">cl2vcs</a> parses and displays
+ changelogs of <a href="http://debian.org">Debian</a> packages. If the package's
+ changelog lists <a href="http://honk.sigxcpu.org/projects/git-buildpackage/manual-html/gbp.releases.html#GBP.RELEASE.COMMIT">
+ Vcs commit ids</a> and if the package's debian/control file has a <a
+ href="http://www.debian.org/doc/developers-reference/best-pkging-practices.html#bpp-vcs">
+ Vcs-Browser field</a>, <em>cl2vcs</em> adds links from the
+ changelog back to the version control system for easy patch review. A real
+ live package that supports this is <a href="/cl2vcs/?pkg=libvirt">libvirt</a>.
+ </div>
+
+ <div id="footer">
+ <hr />
+ <p>© 2008 Guido Günther <a href="mailto:agx@sigxcpu.org">&lt;agx@sigxcpu.org&gt;</a></p>
+ </div>
+ </body>
+</html>
+