1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
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":
self.patchname = "debian-dir only changes"
self.content = dh.debiandir()
elif patchtype == "nondebian":
self.patchname = "direct (non packaging) changes"
self.content = dh.nondebiandir()
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()
|