diff options
author | Sean Finney <seanius@debian.org> | 2008-09-08 21:32:44 +0200 |
---|---|---|
committer | Sean Finney <seanius@debian.org> | 2008-09-08 22:34:10 +0200 |
commit | c23a018c544320e053cf4a934906e3e61b9679d4 (patch) | |
tree | 90f93335e8a24fc2d61e89ed2e26fd7ac9acff75 /patchtracker/DB.py | |
parent | 26a4f31bc27b021dbb332c536e7d14c65fdf54c0 (diff) | |
download | patch-tracker-c23a018c544320e053cf4a934906e3e61b9679d4.tar.gz |
Revert previous database representation changes
This reverts commit 26a4f31bc27b021dbb332c536e7d14c65fdf54c0.
This reverts commit 5578d0fad24d68ecbd12a735c444910754db50ca.
Diffstat (limited to 'patchtracker/DB.py')
-rw-r--r-- | patchtracker/DB.py | 73 |
1 files changed, 37 insertions, 36 deletions
diff --git a/patchtracker/DB.py b/patchtracker/DB.py index 968b975..b7a91ef 100644 --- a/patchtracker/DB.py +++ b/patchtracker/DB.py @@ -5,11 +5,33 @@ import errno import patchtracker.SourceArchive as SourceArchive +def srcpkg_factory(cursor, row): + d = {} + for idx, col in enumerate(cursor.description): + d[col[0]] = row[idx] + + info = {} + info['Files'] = [] + if d['diffgz_name']: + diffgz = {'name':d['diffgz_name'], 'size':d['diffgz_size'], + 'md5sum':d['diffgz_md5sum'] } + info['Files'].append(diffgz) + + colmap = {'name':'Package','version':'Version','format':'Format', + 'loc':'Directory','maintainer':'Maintainer','uploaders':'Uploaders'} + + for col,field in colmap.iteritems(): + info[field] = d[col] + return SourceArchive.SourcePackage(info) + def srcpkg_collection_factory(cursor, row): d = {} rest = {} for idx, col in enumerate(cursor.description): - d[col[0]] = row[idx] + if not d.has_key(col[0]): + d[col[0]] = row[idx] + else: + rest[col[0]] = row[idx] info = {} info['Files'] = [] @@ -18,12 +40,12 @@ def srcpkg_collection_factory(cursor, row): 'md5sum':d['diffgz_md5sum'] } info['Files'].append(diffgz) - colmap = {'packagename':'Package','version':'Version','format':'Format', - 'loc':'Directory','emails':'Maintainer'} + colmap = {'name':'Package','version':'Version','format':'Format', + 'loc':'Directory','maintainer':'Maintainer','uploaders':'Uploaders'} for col,field in colmap.iteritems(): info[field] = d[col] - return (SourceArchive.SourcePackage(info), d) + return (SourceArchive.SourcePackage(info), rest) class PatchTrackerDB: @@ -48,11 +70,11 @@ class PatchTrackerDB: cursor = self.db.cursor() #print "creating new record for",srcpkg q = "INSERT OR IGNORE INTO packages \ - (name,format,loc,version,diffgz_name,diffgz_size,diffgz_md5sum) \ - VALUES (?,?,?,?,?,?,?)" + (name,format,loc,version,diffgz_name,diffgz_size,diffgz_md5sum,maintainer,uploaders) \ + VALUES (?,?,?,?,?,?,?,?,?)" cursor.execute(q, (srcpkg.name,srcpkg.format,srcpkg.loc, srcpkg.version,srcpkg.diffgz_name,srcpkg.diffgz_size, - srcpkg.diffgz_md5sum,)) + srcpkg.diffgz_md5sum,srcpkg.maintainers,srcpkg.uploaders)) def saveSuite(self, suite): q = "INSERT INTO suites (name) VALUES (?)" @@ -64,41 +86,25 @@ class PatchTrackerDB: cursor = self.db.cursor() cursor.execute(q, (component,)) - def saveMaintainers(self, maintainers): - q = "INSERT INTO maintainers (email) VALUES (?)" - cursor = self.db.cursor() - cursor.executemany(q, [(m,) for m in maintainers]) - - def findCollection(self, package=None, version=None, email=None): + def findCollection(self, package="%", version=None, email=None): oldfactory = self.db.row_factory self.db.row_factory = srcpkg_collection_factory cursor = self.db.cursor() toc = SourceArchive.SourcePackageIndex() - # zomgroflcoptersql!!1!one! - q = "SELECT p.name as packagename, version, format, loc, diffgz_name, \ - diffgz_size, diffgz_md5sum, s.name as suitename, \ - (SELECT GROUP_CONCAT(email) FROM maintainers AS m, \ - maint_rel_map AS mm \ - WHERE mm.package_id = p.id \ - AND mm.maintainer_id = m.id) AS emails \ - FROM packages AS p, package_rel_map AS pm, suites AS s \ - WHERE pm.package_id = p.id AND pm.suite_id = s.id" - - qargs = () - if package: - q += " AND packagename LIKE ?" - qargs += (package,) + q = "SELECT * FROM packages AS p,package_rel_map AS m,suites AS s \ + WHERE p.name LIKE ? AND p.id = m.package_id AND m.suite_id = s.id" + qargs = (package,) if version: q += " AND p.version = ?" qargs += (version,) if email: - q += " AND emails LIKE ?" - qargs += ("%%<%s>%%"%(email),) + q += " AND ( p.maintainer like ? OR p.uploaders like ? )" + qargs += (email,email) cursor.execute(q, qargs) # use srcpkg_factory to fetch sourcepackages, once per suite for srcpkg,rest in cursor.fetchall(): - toc.ins(srcpkg, rest['suitename']) + toc.ins(srcpkg, rest["name"]) self.db.row_factory = oldfactory return toc @@ -121,7 +127,7 @@ class PatchTrackerDB: indices.sort() return indices - def relateSourcePackage(self, name, version, suite, component, maintainers): + def relateSourcePackage(self, name, version, suite, component): q = "INSERT INTO package_rel_map \ (package_id,suite_id,component_id,marked) \ VALUES ((SELECT id FROM packages WHERE name=? AND version=?), \ @@ -129,11 +135,6 @@ class PatchTrackerDB: (SELECT id FROM components WHERE name=?), 1)" cursor = self.db.cursor() cursor.execute(q, (name, version, suite, component)) - q2 = "INSERT INTO maint_rel_map \ - (package_id,maintainer_id) \ - VALUES ((SELECT id FROM packages WHERE name=? AND version=?), \ - (SELECT id FROM maintainers WHERE email=?))" - cursor.executemany(q2, [(name, version, m) for m in maintainers]) def findDiffGz(self, pkgname, version): q = "SELECT diffgz_name,loc FROM packages WHERE name=? AND version=?" |