summaryrefslogtreecommitdiff
path: root/patchtracker/DB.py
diff options
context:
space:
mode:
Diffstat (limited to 'patchtracker/DB.py')
-rw-r--r--patchtracker/DB.py74
1 files changed, 37 insertions, 37 deletions
diff --git a/patchtracker/DB.py b/patchtracker/DB.py
index 3a5be5c..0794903 100644
--- a/patchtracker/DB.py
+++ b/patchtracker/DB.py
@@ -5,33 +5,11 @@ 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):
- if not d.has_key(col[0]):
- d[col[0]] = row[idx]
- else:
- rest[col[0]] = row[idx]
+ d[col[0]] = row[idx]
info = {}
info['Files'] = []
@@ -40,12 +18,12 @@ def srcpkg_collection_factory(cursor, row):
'md5sum':d['diffgz_md5sum'] }
info['Files'].append(diffgz)
- colmap = {'name':'Package','version':'Version','format':'Format',
- 'loc':'Directory','maintainer':'Maintainer','uploaders':'Uploaders'}
+ colmap = {'packagename':'Package','version':'Version','format':'Format',
+ 'loc':'Directory','emails':'Maintainer'}
for col,field in colmap.iteritems():
info[field] = d[col]
- return (SourceArchive.SourcePackage(info), rest)
+ return (SourceArchive.SourcePackage(info), d)
class PatchTrackerDB:
@@ -70,11 +48,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,maintainer,uploaders) \
- VALUES (?,?,?,?,?,?,?,?,?)"
+ (name,format,loc,version,diffgz_name,diffgz_size,diffgz_md5sum) \
+ VALUES (?,?,?,?,?,?,?)"
cursor.execute(q, (srcpkg.name,srcpkg.format,srcpkg.loc,
srcpkg.version,srcpkg.diffgz_name,srcpkg.diffgz_size,
- srcpkg.diffgz_md5sum,srcpkg.maintainer,srcpkg.uploaders))
+ srcpkg.diffgz_md5sum,))
def saveSuite(self, suite):
q = "INSERT INTO suites (name) VALUES (?)"
@@ -86,25 +64,42 @@ class PatchTrackerDB:
cursor = self.db.cursor()
cursor.execute(q, (component,))
- def findCollection(self, package="%", version=None, email=None):
+ 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):
oldfactory = self.db.row_factory
self.db.row_factory = srcpkg_collection_factory
cursor = self.db.cursor()
toc = SourceArchive.SourcePackageIndex()
- 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,)
+ # 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 \
+ AND emails IS NOT NULL"
+
+ qargs = ()
+ if package:
+ q += " AND packagename LIKE ?"
+ qargs += (package,)
if version:
q += " AND p.version = ?"
qargs += (version,)
if email:
- q += " AND ( p.maintainer like ? OR p.uploaders like ? )"
- qargs += (email,email)
+ q += " AND emails LIKE ?"
+ qargs += ("%%<%s>%%"%(email),)
cursor.execute(q, qargs)
# use srcpkg_factory to fetch sourcepackages, once per suite
for srcpkg,rest in cursor.fetchall():
- toc.ins(srcpkg, rest["name"])
+ toc.ins(srcpkg, rest['suitename'])
self.db.row_factory = oldfactory
return toc
@@ -127,7 +122,7 @@ class PatchTrackerDB:
indices.sort()
return indices
- def relateSourcePackage(self, name, version, suite, component):
+ def relateSourcePackage(self, name, version, suite, component, maintainers):
q = "INSERT INTO package_rel_map \
(package_id,suite_id,component_id,marked) \
VALUES ((SELECT id FROM packages WHERE name=? AND version=?), \
@@ -135,6 +130,11 @@ 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=?"