[Secure-testing-commits] r14639 - doc lib/python/sectracker lib/python/sectracker_test

Florian Weimer fw at alioth.debian.org
Sat May 8 10:14:01 UTC 2010


Author: fw
Date: 2010-05-08 10:14:00 +0000 (Sat, 08 May 2010)
New Revision: 14639

Modified:
   doc/python-format.txt
   lib/python/sectracker/parsers.py
   lib/python/sectracker_test/test_parsers.py
Log:
sectracker.parsers.sourcepackages(): extract binary packages

It turns out that we can reconstruct the binary packages list
from the Binary: field in the Sources files.


Modified: doc/python-format.txt
===================================================================
--- doc/python-format.txt	2010-05-08 09:16:30 UTC (rev 14638)
+++ doc/python-format.txt	2010-05-08 10:14:00 UTC (rev 14639)
@@ -14,6 +14,19 @@
 internal order of named tuples (so you really should not rely on
 that).
 
+# Source packages
+
+The dictionary returned by sectracker.parsers.sourcepackages()
+contains the source package name as the key, and as values named
+tuples with the following field:
+
+* pkg.name: the name of the source package
+
+* pkg.version: the source version
+
+* pkg.binary: a list of binary package names compiled from this source
+  package
+
 # Individual bug information
 
 The data/*/list files are parsed as lists of bugs.  A line which does

Modified: lib/python/sectracker/parsers.py
===================================================================
--- lib/python/sectracker/parsers.py	2010-05-08 09:16:30 UTC (rev 14638)
+++ lib/python/sectracker/parsers.py	2010-05-08 10:14:00 UTC (rev 14639)
@@ -23,8 +23,13 @@
 import sectracker.xpickle as _xpickle
 import sectracker.diagnostics
 
-FORMAT = "1"
+FORMAT = "2"
 
+def _sortedtuple(seq):
+    l = list(seq)
+    l.sort()
+    return tuple(l)
+
 @_xpickle.loader("BINARY" + FORMAT)
 def binarypackages(name, f):
     """Returns a sequence of binary package names"""
@@ -34,39 +39,37 @@
     obj.sort()
     return tuple(obj)
 
+SourcePackage = _namedtuple("SourcePackage", "name version binary")
 
 @_xpickle.loader("SOURCE" + FORMAT)
 def sourcepackages(name, f):
-    """Returns a dictionary of source package objects.
-
-    The keys are strings, containing the source package name, the
-    values are corresponding source package versions."""
-    
+    """Returns a dictionary of source package objects"""
     data = {}
     for p in debian_support.PackageFile(name, f):
-        pkg_name, pkg_version = (None, None)
+        pkg_name = pkg_version = pkg_binary = None
         for name, contents in p:
             if name == "Package":
                 pkg_name = intern(contents)
             elif name == "Version":
                 pkg_version = contents
+            elif name == "Binary":
+                pkg_binary = _sortedtuple(contents.replace(",", " ")
+                                          .strip().split())
         if pkg_name is None:
             raise SyntaxError("package record does not contain package name")
         if pkg_version is None:
             raise SyntaxError("package record for %s does not contain version"
                               % pkg_name)
+        if pkg_binary is None:
+            raise SyntaxError("package record lacks Binary field")
+
         if pkg_name in data:
-            oversion = debian_support.Version(data[pkg_name])
+            oversion = debian_support.Version(data[pkg_name].version)
             if oversion >= debian_support.Version(pkg_version):
                 continue
-        data[pkg_name] = pkg_version
+        data[pkg_name] = SourcePackage(pkg_name, pkg_version, pkg_binary)
     return data
 
-def _sortedtuple(seq):
-    l = list(seq)
-    l.sort()
-    return tuple(l)
-
 FlagAnnotation = _namedtuple("FlagAnnotation", "line type")
 StringAnnotation = _namedtuple("StringAnnotation",
                                            "line type description")

Modified: lib/python/sectracker_test/test_parsers.py
===================================================================
--- lib/python/sectracker_test/test_parsers.py	2010-05-08 09:16:30 UTC (rev 14638)
+++ lib/python/sectracker_test/test_parsers.py	2010-05-08 10:14:00 UTC (rev 14639)
@@ -19,13 +19,11 @@
 import sectracker.parsers as p
 from sectracker.xpickle import safeunlink, EXTENSION
 
-o = binarypackages("../../data/packages/sid__main_i386_Packages")
-assert type(o) == type(())
-assert "bash" in o
-
 o = sourcepackages("../../data/packages/sid__main_Sources")
 assert type(o) == type({})
 assert "bash" in o
+assert o["bash"].name == "bash"
+assert "bash" in o["bash"].binary
 
 safeunlink("../../data/CVE/list" + EXTENSION)
 o = cvelist("../../data/CVE/list")




More information about the Secure-testing-commits mailing list