diff options
author | Florian Weimer <fw@deneb.enyo.de> | 2010-05-08 10:14:00 +0000 |
---|---|---|
committer | Florian Weimer <fw@deneb.enyo.de> | 2010-05-08 10:14:00 +0000 |
commit | e8fecebf8e982e90b39955d38fdf492f431f11ab (patch) | |
tree | dda8874c5efd3728d129f556f147e928198cd082 | |
parent | 3f5602f9ec7f707c6835f997d66fd5d7a9da5781 (diff) |
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.
git-svn-id: svn+ssh://svn.debian.org/svn/secure-testing@14639 e39458fd-73e7-0310-bf30-c45bca0a0e42
-rw-r--r-- | doc/python-format.txt | 13 | ||||
-rw-r--r-- | lib/python/sectracker/parsers.py | 31 | ||||
-rw-r--r-- | lib/python/sectracker_test/test_parsers.py | 6 |
3 files changed, 32 insertions, 18 deletions
diff --git a/doc/python-format.txt b/doc/python-format.txt index 9f20d7c0f5..b0f0a91613 100644 --- a/doc/python-format.txt +++ b/doc/python-format.txt @@ -14,6 +14,19 @@ except for the addition of additional attributes and changes in the 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 diff --git a/lib/python/sectracker/parsers.py b/lib/python/sectracker/parsers.py index 7f40f256e3..998127cefa 100644 --- a/lib/python/sectracker/parsers.py +++ b/lib/python/sectracker/parsers.py @@ -23,7 +23,12 @@ from sectracker.xcollections import namedtuple as _namedtuple 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): @@ -34,39 +39,37 @@ def binarypackages(name, f): 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") diff --git a/lib/python/sectracker_test/test_parsers.py b/lib/python/sectracker_test/test_parsers.py index 8d3f49b4f6..83a00645be 100644 --- a/lib/python/sectracker_test/test_parsers.py +++ b/lib/python/sectracker_test/test_parsers.py @@ -19,13 +19,11 @@ from sectracker.parsers import * 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") |