summaryrefslogtreecommitdiff
path: root/patchtracker
diff options
context:
space:
mode:
authorGiovanni Mascellani <mascellani@poisson.phc.unipi.it>2011-07-31 11:33:35 +0200
committerSean Finney <seanius@htpc-l.(none)>2011-09-17 13:28:46 +0200
commitb231a89e5bad73baa00edffc198bee93293eb295 (patch)
tree15e9c6b53564cf26e32d889f4a96ec32a72e0906 /patchtracker
parentbf10ac14e0fce21e6ebf9dc51c9dba7f783ae139 (diff)
downloadpatch-tracker-b231a89e5bad73baa00edffc198bee93293eb295.tar.gz
Move makeDiffHandler in DB, so it can be used in other contexts.
Diffstat (limited to 'patchtracker')
-rw-r--r--patchtracker/DB.py17
-rwxr-xr-xpatchtracker/ReqHandler.py19
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)