diff options
author | Sean Finney <seanius@debian.org> | 2008-06-25 21:57:51 +0200 |
---|---|---|
committer | Sean Finney <seanius@debian.org> | 2008-06-25 21:57:51 +0200 |
commit | e4042758f5801106a74a189110e5d521e288b53c (patch) | |
tree | 65e31bae3d734aadfa21db91e3d3a70a05e4d17f /pagehandler.py | |
parent | 8068846d7058be7742850e770808f33ff1f439a8 (diff) | |
download | patch-tracker-e4042758f5801106a74a189110e5d521e288b53c.tar.gz |
cleanup/reorganize pagehandler command handling
Diffstat (limited to 'pagehandler.py')
-rwxr-xr-x | pagehandler.py | 180 |
1 files changed, 103 insertions, 77 deletions
diff --git a/pagehandler.py b/pagehandler.py index 3f6562e..f9d06f9 100755 --- a/pagehandler.py +++ b/pagehandler.py @@ -15,54 +15,38 @@ from pygments.lexers import DiffLexer from pygments.formatters import HtmlFormatter import patchtracker.SourceArchive as SourceArchive -class CmdHandler: - def __init__(self, uri): - if len(uri)<len(Conf.root_url) or uri[0:len(Conf.root_url)]!=Conf.root_url: - self.error("Invalid URL!") +def error(msg): + print "Content-Type: text/html\n\n" + print ErrorTemplate(msg) + sys.exit(1) - self.db = PatchTrackerDB() - args = uri[len(Conf.root_url)+1:].split("/") - #print "args:",args - self.cmd = args[0] - if self.cmd == "patch": - self.patchtype,mode,pkgname,version = args[1:5] - self.parsemode(mode) - dh = self.make_diffhandler(pkgname,version) - if self.patchtype == "series": - self.patchname = os.sep.join(args[5:]) - self.content = dh.series().fetch(self.patchname) - elif self.patchtype == "debianonly": - self.patchname = "debian-dir only changes" - self.content = dh.debiandir() - elif self.patchtype == "nondebian": - self.patchname = "direct (non packaging) changes" - self.content = dh.nondebiandir() - elif self.patchtype == "misc": - self.patchname = os.sep.join(args[5:]) - self.content = dh.filterdiff(include=self.patchname) - else: - self.error("unhandled patch type '%s'"%(self.patchtype)) - self.pkgname = pkgname - self.version = version - elif self.cmd == "package": - self.db.setFactory(DB.srcpkg_factory) - self.name = args[1] - self.version = args[2] - self.srcpkg = self.db.findSourcePackage(self) - elif self.cmd == "index": - if len(args) < 2 or not len(args[1]): - self.error("please provide a letter on which to index") - else: - self.letter = args[1] - self.toc = self.db.findLetterToc(self.letter) - elif self.cmd == "jump": - form = cgi.FieldStorage() - self.name = form.getfirst("package") - elif not len(self.cmd): - self.index = self.db.findMasterIndex() - self.cmd = "frontpage" +class PatchCmd: + def __init__(self, args): + self.patchtype,mode,pkgname,version = args[0:4] + self.parsemode(mode) + dh = self.make_diffhandler(pkgname,version) + if self.patchtype == "series": + self.patchname = os.sep.join(args[4:]) + self.content = dh.series().fetch(self.patchname) + elif self.patchtype == "debianonly": + self.patchname = "debian-dir only changes" + self.content = dh.debiandir() + elif self.patchtype == "nondebian": + self.patchname = "direct (non packaging) changes" + self.content = dh.nondebiandir() + elif self.patchtype == "misc": + self.patchname = os.sep.join(args[4:]) + self.content = dh.filterdiff(include=self.patchname) else: - self.error("invalid command/location %s"%(self.cmd)) + error("unhandled patch type '%s'"%(self.patchtype)) + self.pkgname = pkgname + self.version = version + + def parsemode(self, mode): + if mode == "view" or mode == "dl": + self.mode = mode + else: + error("unhandled display mode '%s'"%(mode)) # XXX this assumes to much hard coded, but until there's a faster # XXX (i.e. database) way to query sourcepackage/diffs it will @@ -86,43 +70,85 @@ class CmdHandler: if file: return DiffGzHandler(file) else: - self.error("can not find diff file for %s / %s"%(pkgname,diffvers)) + error("can not find diff file for %s / %s"%(pkgname,diffvers)) - def parsemode(self, mode): - if mode == "view" or mode == "dl": - self.mode = mode + def output(self): + if self.mode == "dl": + print "Content-Type: text/x-diff\n\n" + print self.content else: - self.error("unhandled display mode '%s'"%(mode)) + print "Content-Type: text/html\n\n" + print PatchTemplate(pkg=self.pkgname,vers=self.version, + patch=self.content,name=self.patchname, + patchtype=self.patchtype) + +class PackageCmd: + def __init__(self, args): + self.db = PatchTrackerDB() + self.db.setFactory(DB.srcpkg_factory) + self.name = args[0] + self.version = args[1] + self.srcpkg = self.db.findSourcePackage(self) - def error(self, msg): + def output(self): print "Content-Type: text/html\n\n" - print ErrorTemplate(msg) - sys.exit(1) + print PackageVersTemplate(self.srcpkg) + +class IndexCmd: + def __init__(self, args): + if len(args) < 1 or not len(args[0]): + error("please provide a letter on which to index") + else: + self.db = PatchTrackerDB() + self.letter = args[0] + self.toc = self.db.findLetterToc(self.letter) def output(self): - if self.cmd == "patch": - 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, - patchtype=self.patchtype) - elif self.cmd == "package": - print "Content-Type: text/html\n\n" - print PackageVersTemplate(self.srcpkg) - elif self.cmd == "index": - print "Content-Type: text/html\n\n" - print LetterTocTemplate(self.letter, self.toc) - elif self.cmd == "frontpage": - print "Content-Type: text/html\n\n" - print FrontPageTemplate(self.index) - elif self.cmd == "jump": - print "Location: http://%s%s/index/%s#%s\n\n"%(os.getenv("HTTP_HOST"), - Conf.root_url, - SourceArchive.getidx(self.name), - self.name) + print "Content-Type: text/html\n\n" + print LetterTocTemplate(self.letter, self.toc) + +class JumpCmd: + def __init__(self): + form = cgi.FieldStorage() + self.name = form.getfirst("package") + + def output(self): + print "Location: http://%s%s/index/%s#%s\n\n"%( + os.getenv("HTTP_HOST"), Conf.root_url, + SourceArchive.getidx(self.name), self.name) + +class FrontPageCmd: + def __init__(self): + self.db = PatchTrackerDB() + self.index = self.db.findMasterIndex() + + def output(self): + print "Content-Type: text/html\n\n" + print FrontPageTemplate(self.index) + + +class CmdHandler: + def __init__(self, uri): + if len(uri)<len(Conf.root_url) or uri[0:len(Conf.root_url)]!=Conf.root_url: + error("Invalid URL!") + + args = uri[len(Conf.root_url)+1:].split("/") + cmdarg = args[0] + if cmdarg == "patch": + self.cmd = PatchCmd(args[1:]) + elif cmdarg == "package": + self.cmd = PackageCmd(args[1:]) + elif cmdarg == "index": + self.cmd = IndexCmd(args[1:]) + elif cmdarg == "jump": + self.cmd = JumpCmd() + elif not len(cmdarg): + self.cmd = FrontPageCmd() + else: + error("invalid command/location %s"%(cmdarg)) + + def output(self): + self.cmd.output() if __name__ == "__main__": uri = os.getenv("REQUEST_URI") |