Author: fw Date: 2005-09-17 22:41:49 +0000 (Sat, 17 Sep 2005) New Revision: 2035 Modified: lib/python/security_db.py Log: data/python/security_db.py (DB.getSourcePackageVersions, DB.getBinaryPackageVersions, DB.getBinaryPackagesForSource, DB.getBugsFromDebianBug, DB.isSourcePackage, DB.isBinaryPackage, DB.getBugsForSourcePackage, DB.getBugsForBinaryPackage, DB.getTODOs): New methods. Modified: lib/python/security_db.py ==================================================================--- lib/python/security_db.py 2005-09-17 22:38:40 UTC (rev 2034) +++ lib/python/security_db.py 2005-09-17 22:41:49 UTC (rev 2035) @@ -1165,6 +1165,50 @@ record(''fixed'', ''packages are not vulnerable'') return result + + def getSourcePackageVersions(self, cursor, pkg): + """A generator which returns tuples (RELEASE-LIST, VERSION), + the available versions of the source package pkg.""" + + for (releases, version) in cursor.execute( + """SELECT string_list(release) AS releases, version + FROM (SELECT release, version FROM source_packages + WHERE name = ? + ORDER BY release_to_number(release)) + GROUP BY version""", (pkg,)): + yield releases.split('', ''), version + + def getBinaryPackageVersions(self, cursor, pkg): + """A generator which returns tuples (RELEASE-LIST, VERSION), + the available versions of the source package pkg.""" + + for (releases, version, archs) in cursor.execute( + """SELECT string_list(release) AS releases, version, archs + FROM (SELECT release, version, string_set(archs) AS archs + FROM binary_packages + WHERE name = ? + GROUP BY release, version + ORDER BY release_to_number(release)) + GROUP BY version, archs""", (pkg,)): + yield releases.split('', ''), version, archs.split('','') + + def getBinaryPackagesForSource(self, cursor, pkg): + """A generator which returns tuples (PACKAGES, RELEASE-LIST, + VERSION), the available binary packages built from the source + package pkg.""" + + for (packages, releases, version) in cursor.execute( + """SELECT string_list(package) AS packages, releases, version + FROM (SELECT package, string_list(rel) AS releases, version + FROM (SELECT name AS package, + release_name(release, subrelease, archive) AS rel, version + FROM binary_packages + WHERE source = ? + ORDER BY release_to_number(release)) + GROUP BY package, version + ORDER BY package) + GROUP BY releases, version""", (pkg,)): + yield packages.split('', ''), releases.split('', ''), version def getSourcePackages(self, cursor, bug): """A generator which returns tuples (SOURCE-PACKAGE, @@ -1213,6 +1257,69 @@ yield (packages.split('', ''), releases.split('',''), version, archs.split('',''), vulnerable) + def getBugsFromDebianBug(self, cursor, number): + """A generator which returns a list of tuples + (BUG-NAME, URGENCY, DESCRIPTION).""" + + return cursor.execute( + """SELECT DISTINCT bugs.name, package_notes.urgency, + bugs.description + FROM debian_bugs, package_notes, bugs + WHERE debian_bugs.bug = ? AND package_notes.id = debian_bugs.note + AND bugs.name = package_notes.bug_name + ORDER BY bug_name""", (number,)) + + def isSourcePackage(self, cursor, pkg): + """Returns a true value if pkg is a source package.""" + ((flag,),) = cursor.execute( + "SELECT EXISTS (SELECT * FROM source_packages WHERE name = ?)", + (pkg,)) + return flag + + def isBinaryPackage(self, cursor, pkg): + """Returns a true value if pkg is a binary package.""" + ((flag,),) = cursor.execute( + "SELECT EXISTS (SELECT * FROM binary_packages WHERE name = ?)", + (pkg,)) + + def getBugsForSourcePackage(self, cursor, pkg, vulnerable): + """Returns a generator for a list of (BUG, DESCRIPTION) pairs + which have the requested status.""" + return cursor.execute( + """SELECT name, description + FROM (SELECT bugs.name AS name, bugs.description AS description, + MAX(st.vulnerable) AS vulnerable + FROM source_packages AS sp, source_package_status AS st, + package_notes AS n, bugs + WHERE sp.name = ? AND st.package = sp.rowid AND n.id = st.note + AND bugs.name = n.bug_name + GROUP BY bugs.name, bugs.description) + WHERE vulnerable = ?""", (pkg, vulnerable)) + + def getBugsForBinaryPackage(self, cursor, pkg, vulnerable): + """Returns a generator for a list of (BUG, DESCRIPTION) pairs + which have the requested status.""" + return cursor.execute( + """SELECT name, description + FROM (SELECT bugs.name AS name, bugs.description AS description, + MAX(st.vulnerable) AS vulnerable + FROM binary_packages AS bp, binary_package_status AS st, + package_notes AS n, bugs + WHERE bp.name = ? AND st.package = bp.rowid AND n.id = st.note + AND bugs.name = n.bug_name + GROUP BY bugs.name, bugs.description) + WHERE vulnerable = ?""", (pkg, vulnerable)) + + def getTODOs(self, cursor=None): + """Returns a list of pairs (BUG-NAME, DESCRIPTION).""" + if cursor is None: + cursor = self.cursor() + return cursor.execute( + """SELECT DISTINCT bugs.name, bugs.description + FROM bugs_notes, bugs + WHERE bugs_notes.typ = ''TODO'' AND bugs.name = bugs_notes.bug_name + ORDER BY name """) + def check(self, cursor=None): """Runs a simple consistency check and prints the results."""