From 8810a354aea0e2fc3c2a41a795090ce8aca8c1ea Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Sun, 24 May 2015 19:36:19 +0000 Subject: Introduce named tuples BugsForSourcePackage, DSAsForSourcePackage git-svn-id: svn+ssh://svn.debian.org/svn/secure-testing@34474 e39458fd-73e7-0310-bf30-c45bca0a0e42 --- lib/python/security_db.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/python/security_db.py b/lib/python/security_db.py index a09ef3f486..2844b2809f 100644 --- a/lib/python/security_db.py +++ b/lib/python/security_db.py @@ -39,6 +39,8 @@ import sys import types import zlib +from collections import namedtuple + import debian_support import dist_config @@ -98,6 +100,21 @@ class SchemaMismatch(Exception): The caller is expected to remove and regenerate the database.""" + def getBugsForSourcePackage(self, cursor, pkg, vulnerable, unimportant): + """Returns a generator for a list of (BUG, DESCRIPTION) pairs + which have the requested status. Only bugs affecting supported + releases are returned.""" + +# Returned by DB.getBugsForSourcePackage(). +BugsForSourcePackage = namedtuple( + "BugsForSourcePackage", + "bug description") + +# Returned by DB.getDSAsForSourcePackage(). +DSAsForSourcePackage = namedtuple( + "DSAsForSourcePackage", + "bug description") + class DB: """Access to the security database. @@ -1719,10 +1736,11 @@ class DB: return flag def getBugsForSourcePackage(self, cursor, pkg, vulnerable, unimportant): - """Returns a generator for a list of (BUG, DESCRIPTION) pairs - which have the requested status. Only bugs affecting supported - releases are returned.""" - return cursor.execute( + """Returns a generator for BugsForSourcePackage named tuples which + have the requested status. Only bugs affecting supported + releases are returned. + """ + for row in cursor.execute( """SELECT DISTINCT name, description FROM (SELECT bugs.name AS name, bugs.description AS description, MAX(st.vulnerable @@ -1742,16 +1760,18 @@ class DB: AND (bugs.name LIKE 'CVE-%' OR bugs.name LIKE 'TEMP-%') GROUP BY bugs.name, bugs.description, sp.name) WHERE vulnerable = ? AND unimportant = ? - ORDER BY name DESC""", (pkg, vulnerable, unimportant)) + ORDER BY name DESC""", (pkg, vulnerable, unimportant)): + yield BugsForSourcePackage(*row) def getDSAsForSourcePackage(self, cursor, package): - return cursor.execute( + for row in cursor.execute( """SELECT bugs.name, bugs.description FROM bugs, package_notes as p WHERE p.bug_name = bugs.name AND ( bugs.name LIKE 'DSA-%' OR bugs.name LIKE 'DLA-%') AND p.package = ? - ORDER BY bugs.release_date DESC""", (package,)) + ORDER BY bugs.release_date DESC""", (package,)): + yield DSAsForSourcePackage(*row) def getTODOs(self, cursor=None, hide_check=False): -- cgit v1.2.3