summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Finney <seanius@debian.org>2008-06-11 01:05:17 +0200
committerSean Finney <seanius@debian.org>2008-06-11 01:05:17 +0200
commit6a70f64a3cac69d9d6dc8346ad845db07f6c1dc5 (patch)
tree6d9a50f32d7f89b51cadb688d81e7b8578905a08
parent90b32ea02cd73f90f66b9d0698cc6f71a6f77125 (diff)
downloadpatch-tracker-6a70f64a3cac69d9d6dc8346ad845db07f6c1dc5.tar.gz
initial stab at cgi-based patch generation
complete with many ugly hacks to workaround the lack of an underlying database. hopefully it's all marked with XXX for later fixing :) does not cover all patch cases, in fact currently it only covers series patch viewing and downloading.
-rwxr-xr-xpagehandler.py74
-rw-r--r--patchtracker/Patch.py2
-rwxr-xr-xpatchtracker/Writers.py11
-rw-r--r--static/css/patches.css6
-rw-r--r--templates/cgi_error.tmpl12
-rw-r--r--templates/patch_view.tmpl19
6 files changed, 123 insertions, 1 deletions
diff --git a/pagehandler.py b/pagehandler.py
new file mode 100755
index 0000000..2ae7a08
--- /dev/null
+++ b/pagehandler.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+
+import cgi
+import os
+import sys
+import patchtracker.Conf as Conf
+from patchtracker.Writers import ErrorTemplate, PatchTemplate
+from patchtracker.DiffGzHandler import DiffGzHandler
+import pygments
+from pygments.lexers import DiffLexer
+from pygments.formatters import HtmlFormatter
+
+class CmdHandler:
+ def __init__(self, req_uri):
+ args = req_uri.split("/")
+ # XXX this assumes http://site/foo/patch/adsfadf
+ if args[2] == "patch":
+ patchtype,mode,pkgname,version = args[3:7]
+ self.parsemode(mode)
+ dh = self.make_diffhandler(pkgname,version)
+ if patchtype == "series":
+ self.patchname = args[7]
+ self.content = dh.series().fetch(self.patchname)
+ elif patchtype == "debianonly":
+ something = True
+ else:
+ self.error("unhandled patch type '%s'"%(patchtype))
+ self.pkgname = pkgname
+ self.version = version
+ else:
+ self.error("unhandled command: '%s'"%(args[2]))
+
+ # XXX this assumes to much hard coded, but until there's a faster
+ # XXX (i.e. database) way to query sourcepackage/diffs it will
+ # XXX have to do...
+ def make_diffhandler(self, pkgname, vers):
+ file = None
+ dfile = pkgname+"_"+vers+".diff.gz"
+ for comp in ['main', 'contrib', 'non-free']:
+ loc = os.sep.join([Conf.archive_root, 'pool', comp, pkgname[0], pkgname])
+ try:
+ test = os.sep.join([loc, dfile])
+ os.stat(test)
+ file = test
+ break
+ except:
+ pass
+ if file:
+ return DiffGzHandler(file)
+ else:
+ self.error("can not find diff file for %s / %s"%(pkgname,vers))
+
+ def parsemode(self, mode):
+ if mode == "view" or mode == "dl":
+ self.mode = mode
+ else:
+ self.error("unhandled display mode '%s'"%(mode))
+
+ def error(self, msg):
+ print "Content-Type: text/html\n\n"
+ print ErrorTemplate(msg)
+ sys.exit(1)
+
+ def output(self):
+ if self.mode == "dl":
+ print "Content-Type: text/x-diff\n\n"
+ print self.content
+ else:
+ print "Content-Type: text/html\n\n"
+ print PatchTemplate(pkg=self.pkgname,vers=self.version,patch=self.content,name=self.patchname)
+
+if __name__ == "__main__":
+ uri = os.getenv("REQUEST_URI")
+ CmdHandler(uri).output()
diff --git a/patchtracker/Patch.py b/patchtracker/Patch.py
index 64cf9c9..2f604e1 100644
--- a/patchtracker/Patch.py
+++ b/patchtracker/Patch.py
@@ -54,7 +54,7 @@ class PatchSeries (list):
continue
# here's the name
name = stuff[0]
- print "\t\t\t%s: %s"%(self.style,name)
+ #print "\t\t\t%s: %s"%(self.style,name)
self.names.append(name)
# anything else are either patch args or comments
self.patchargs[name] = []
diff --git a/patchtracker/Writers.py b/patchtracker/Writers.py
index 74dd95d..9b6ded4 100755
--- a/patchtracker/Writers.py
+++ b/patchtracker/Writers.py
@@ -58,6 +58,17 @@ class LetterTocTemplate(OurTemplate):
tpl = os.sep.join([Conf.template_dir, "letter_toc.tmpl"])
OurTemplate.__init__(self, file=tpl)
+class ErrorTemplate(OurTemplate):
+ def __init__(self, msg):
+ tpl = os.sep.join([Conf.template_dir, "cgi_error.tmpl"])
+ OurTemplate.__init__(self, file=tpl, searchList={'error':msg})
+
+class PatchTemplate(OurTemplate):
+ def __init__(self, pkg=None, vers=None, name=None, patch=None):
+ tpl = os.sep.join([Conf.template_dir, "patch_view.tmpl"])
+ sl = {'package':pkg, 'version':vers, 'name':name, 'patch':str(patch)}
+ OurTemplate.__init__(self, file=tpl, searchList=sl)
+
class PageWriter:
def __init__(self, filename, template):
try:
diff --git a/static/css/patches.css b/static/css/patches.css
index 6c7509e..57c29b0 100644
--- a/static/css/patches.css
+++ b/static/css/patches.css
@@ -29,3 +29,9 @@ table.packagelisting td, table.packagelisting th {
td, th {
padding: 10px;
}
+
+div.patch {
+ margin: 30px;
+ padding: 15px;
+ background-color: #eee;
+}
diff --git a/templates/cgi_error.tmpl b/templates/cgi_error.tmpl
new file mode 100644
index 0000000..6b39f2e
--- /dev/null
+++ b/templates/cgi_error.tmpl
@@ -0,0 +1,12 @@
+#import templates
+#extends templates.skeleton
+#from cgi import escape
+#def title
+Oh noes! Error!
+#end def
+#def body
+ <h1>There was an error processing ur request</h1>
+ <div>
+ $escape($error)
+ </div>
+#end def
diff --git a/templates/patch_view.tmpl b/templates/patch_view.tmpl
new file mode 100644
index 0000000..b3f645e
--- /dev/null
+++ b/templates/patch_view.tmpl
@@ -0,0 +1,19 @@
+#import templates
+#extends templates.skeleton
+#import pygments
+#from pygments.lexers import DiffLexer
+#from pygments.formatters import HtmlFormatter
+#def title
+Patch information for $package / $version / $name
+#end def
+#def body
+ <h1>$package / $version / $name</h1>
+ <div>
+ <a href="$conf.archive_root_url/patch/series/dl/$package/$version/$name">
+ download this patch
+ </a>
+ </div>
+ <div class=patch>
+ $pygments.highlight($patch, $DiffLexer(), $HtmlFormatter(style='colorful', noclasses=True))
+ </div>
+#end def