[Secure-testing-commits] r9092 - lib/python
fw at alioth.debian.org
fw at alioth.debian.org
Tue Jun 17 19:52:56 UTC 2008
Author: fw
Date: 2008-06-17 19:52:55 +0000 (Tue, 17 Jun 2008)
New Revision: 9092
Modified:
lib/python/security_db.py
Log:
lib/python/security_db.py (DB.getEffectiveVersion): New method
Modified: lib/python/security_db.py
===================================================================
--- lib/python/security_db.py 2008-06-17 19:52:51 UTC (rev 9091)
+++ lib/python/security_db.py 2008-06-17 19:52:55 UTC (rev 9092)
@@ -31,7 +31,6 @@
import bugs
import cPickle
import cStringIO
-import debian_support
import glob
import os
import os.path
@@ -40,6 +39,9 @@
import types
import zlib
+import debian_support
+import dist_config
+
class InsertError(Exception):
"""Class for capturing insert errors.
@@ -1883,6 +1885,59 @@
ORDER BY n.package"""):
yield (package, bugs.split(','), map(int, debian_bugs.split(',')))
+ def getEffectiveVersion(self, release, pkg, purpose, cache=None, cursor=None):
+ """Retrieve the effective version of a source package in a release.
+
+ The effective version is the version that matches the recommended
+ sources.list file for the intended purpose. For suitable values
+ of purpose, see dist_config.
+ """
+ # The cache is structured as a (RELEASE, PACKAGE) => VAL
+ # dict, where VAL is either a dict PURPOSE => VERSION,
+ # a VERSION, or None.
+ if cache is not None:
+ sp = (release, pkg)
+ if cache.has_key(sp):
+ d = cache[sp]
+ if d.__class__ == dict:
+ return d.get(purpose, None)
+ else:
+ return d
+
+ if cursor is None:
+ cursor = self.cursor()
+
+ rel = dist_config.releases[release]
+ purposes = rel['purpose']
+ results = {}
+
+ Version = debian_support.Version
+ for (part, ver) in cursor.execute(
+ """SELECT DISTINCT subrelease, version FROM source_packages
+ WHERE release = ? AND name = ?""", (str(release), pkg)):
+ ver = Version(ver)
+ for (purpose, permitted) in purposes.items():
+ if part not in permitted:
+ continue
+ if results.has_key(purpose):
+ oldver = results[purpose]
+ if ver <= oldver:
+ continue
+ results[purpose] = ver
+
+ if cache is not None:
+ vers = set(map(str, results.values()))
+ l = len(vers)
+ if l == 1:
+ for r in vers:
+ cache[sp] = Version(r)
+ elif l == 0:
+ cache[sp] = None
+ else:
+ cache[sp] = results
+
+ return results.get(purpose, None)
+
def check(self, cursor=None):
"""Runs a simple consistency check and prints the results."""
More information about the Secure-testing-commits
mailing list