diff options
author | Giovanni Mascellani <mascellani@poisson.phc.unipi.it> | 2011-07-31 11:33:35 +0200 |
---|---|---|
committer | Sean Finney <seanius@htpc-l.(none)> | 2011-09-17 13:28:46 +0200 |
commit | b231a89e5bad73baa00edffc198bee93293eb295 (patch) | |
tree | 15e9c6b53564cf26e32d889f4a96ec32a72e0906 | |
parent | bf10ac14e0fce21e6ebf9dc51c9dba7f783ae139 (diff) | |
download | patch-tracker-b231a89e5bad73baa00edffc198bee93293eb295.tar.gz |
Move makeDiffHandler in DB, so it can be used in other contexts.
-rw-r--r-- | patchtracker/DB.py | 17 | ||||
-rwxr-xr-x | patchtracker/ReqHandler.py | 19 |
2 files changed, 22 insertions, 14 deletions
diff --git a/patchtracker/DB.py b/patchtracker/DB.py index 0bb0966..0913b24 100644 --- a/patchtracker/DB.py +++ b/patchtracker/DB.py @@ -55,6 +55,9 @@ def srcpkg_collection_factory(cursor, row): info[field] = d[col] return (SourceArchive.SourcePackage(info), rest) +class PackageWithoutDiffException(Exception): + def __init__(self, msg): + Exception.__init__(self, msg) class PatchTrackerDB: def __init__(self, dbname=Conf.database): @@ -167,6 +170,20 @@ class PatchTrackerDB: except: return None + # XXX this is kinda ugly... + def makeDiffHandler(self, pkgname, vers): + dfile = self.findDiffGz(pkgname,vers) + if dfile: + from DiffGzHandler import DiffGzHandler + return DiffGzHandler(dfile) + else: + dfile = self.findDebTar(pkgname, vers) + if dfile: + from DebTarHandler import DebTarHandler + return DebTarHandler(dfile) + else: + raise PackageWithoutDiffException("can not find diff file for %s / %s"%(pkgname,vers)) + def prune(self): q = "DELETE FROM package_rel_map WHERE marked != 1" cursor = self.db.cursor() diff --git a/patchtracker/ReqHandler.py b/patchtracker/ReqHandler.py index 90fc75a..2ac1afb 100755 --- a/patchtracker/ReqHandler.py +++ b/patchtracker/ReqHandler.py @@ -10,7 +10,7 @@ from patchtracker.DiffGzHandler import DiffGzHandler, DiffGzException from patchtracker.DebTarHandler import DebTarHandler from patchtracker.CacheObject import CacheObject, CacheMissException import patchtracker.DB as DB -from patchtracker.DB import PatchTrackerDB +from patchtracker.DB import PatchTrackerDB, PackageWithoutDiffException import pygments from pygments.lexers import DiffLexer from pygments.formatters import HtmlFormatter @@ -41,7 +41,10 @@ class PatchCmd(Cmd): self.db = PatchTrackerDB() self.patchtype,mode,pkgname,version = args[0:4] self.parsemode(mode) - dh = self.make_diffhandler(pkgname,version) + try: + dh = self.db.makeDiffHandler(pkgname,version) + except PackageWithoutDiffException, e: + raise ReqHandlerException(str(e)) if self.patchtype == "series": self.patchname = os.sep.join(args[4:]) self.content = dh.series().fetch(self.patchname) @@ -67,18 +70,6 @@ class PatchCmd(Cmd): if mode == "dl": self.content_type = "text/x-diff" - # XXX this is kinda ugly... - def make_diffhandler(self, pkgname, vers): - dfile = self.db.findDiffGz(pkgname,vers) - if dfile: - return DiffGzHandler(dfile) - else: - dfile = self.db.findDebTar(pkgname, vers) - if dfile: - return DebTarHandler(dfile) - else: - raise ReqHandlerException("can not find diff file for %s / %s"%(pkgname,vers)) - def output(self): if self.mode == "dl": return str(self.content) |