Florian Weimer
2005-Sep-22 12:01 UTC
[Secure-testing-commits] r2088 - bin data/packages lib/python
Author: fw Date: 2005-09-22 12:00:31 +0000 (Thu, 22 Sep 2005) New Revision: 2088 Added: data/packages/removed-packages Modified: bin/update-db lib/python/security_db.py Log: lib/python/security_db.py (DB.initSchema): Add removed_packages table. (DB.readRemovedPackages, DB.getUnknownPackages): New. bin/update-db: Read removed packages. data/packages/removed-packages: New file. Modified: bin/update-db ==================================================================--- bin/update-db 2005-09-22 11:59:56 UTC (rev 2087) +++ bin/update-db 2005-09-22 12:00:31 UTC (rev 2088) @@ -57,6 +57,10 @@ db.commit(cursor) cursor = db.writeTxn() +# Removed packages + +db.readRemovedPackages(cursor, ''data/packages/removed-packages'') + # Calculate vulnerability information. warnings = db.calculateVulnerabilities(cursor) Added: data/packages/removed-packages ==================================================================--- data/packages/removed-packages 2005-09-22 11:59:56 UTC (rev 2087) +++ data/packages/removed-packages 2005-09-22 12:00:31 UTC (rev 2088) @@ -0,0 +1,4 @@ +# This file lists packages which are no longer present in the Debian +# archive, one per line. + +openwebmail Modified: lib/python/security_db.py ==================================================================--- lib/python/security_db.py 2005-09-22 11:59:56 UTC (rev 2087) +++ lib/python/security_db.py 2005-09-22 12:00:31 UTC (rev 2088) @@ -93,7 +93,7 @@ self.db = apsw.Connection(name) self.verbose = verbose - self.schema_version = 11 + self.schema_version = 12 self._initFunctions() c = self.cursor() @@ -262,6 +262,9 @@ ON binary_package_status(package)""") cursor.execute( + "CREATE TABLE removed_packages (name TEXT NOT NULL PRIMARY KEY)") + + cursor.execute( """CREATE VIEW testing_status AS SELECT DISTINCT sp.name AS package, st.bug_name AS bug, sp.archive AS section, st.urgency AS urgency, @@ -1362,6 +1365,54 @@ ORDER BY bug""", (bug, bug, bug, bug)): yield bug_name + def readRemovedPackages(self, cursor, filename): + """Reads a file of removed packages and stores it in the database.""" + + f = file(filename) + + re_package = re.compile(r''^\s*([a-z0-9]\S+)\s*$'') + + # Not very good error reporting, but changes to that file are + # rare. + + def gen(): + for line in f: + if line == '''': + break + if line[0] == ''#'' or line == ''\n'': + continue + match = re_package.match(line) + if match: + yield match.groups() + else: + raise ValueError, "not a package: " + `line` + + cursor.execute("DELETE FROM removed_packages") + cursor.executemany("INSERT INTO removed_packages (name) VALUES (?)", + gen()) + + + def getUnknownPackages(self, cursor): + """Returns a generator for a list of unknown packages. + Each entry has the form (PACKAGE, BUG-LIST).""" + + old_package = '''' + bugs = [] + for (package, bug_name) in cursor.execute( + """SELECT DISTINCT package, bug_name + FROM package_notes WHERE package_kind = ''unknown'' + AND NOT EXISTS (SELECT * FROM removed_packages + WHERE name = package) + ORDER BY package, bug_name"""): + if package <> old_package: + if old_package: + yield (old_package, bugs) + old_package = package + bugs = [] + bugs.append(bug_name) + if old_package: + yield (old_package, bugs) + def check(self, cursor=None): """Runs a simple consistency check and prints the results."""