[Secure-testing-commits] r14643 - data lib/python/sectracker lib/python/sectracker_test
Florian Weimer
fw at alioth.debian.org
Sat May 8 16:30:27 UTC 2010
Author: fw
Date: 2010-05-08 16:30:10 +0000 (Sat, 08 May 2010)
New Revision: 14643
Added:
data/config.json
Modified:
lib/python/sectracker/repo.py
lib/python/sectracker_test/test_repo.py
Log:
sectracker.repo.Config: new class, for loading config.json
Added: data/config.json
===================================================================
--- data/config.json (rev 0)
+++ data/config.json 2010-05-08 16:30:10 UTC (rev 14643)
@@ -0,0 +1,53 @@
+{
+ "repositories" : {
+ "etch": "http://mirror.1und1.de/debian/dists/etch",
+ "etch-security" :
+ "http://security.debian.org/debian-security/dists/etch/updates",
+ "etch-proposed-updates" :
+ "http://mirror.1und1.de/debian/dists/etch-proposed-updates",
+
+ "lenny": "http://mirror.1und1.de/debian/dists/lenny",
+ "lenny-security" :
+ "http://security.debian.org/debian-security/dists/lenny/updates",
+ "lenny-proposed-updates" :
+ "http://mirror.1und1.de/debian/dists/lenny-proposed-updates",
+
+ "squeeze": "http://mirror.1und1.de/debian/dists/squeeze",
+ "squeeze-security" :
+ "http://security.debian.org/debian-security/dists/squeeze/updates",
+ "squeeze-proposed-updates" :
+ "http://mirror.1und1.de/debian/dists/squeeze-proposed-updates",
+
+ "sid" : "http://mirror.1und1.de/debian/dists/sid"
+ },
+
+ "distributions" : {
+ "etch" : {
+ "members" : {
+ "unsupported" : ["etch", "etch-security"],
+ "optional" : ["etch-proposed-updates"]
+ },
+ "release" : "oldstable"
+ },
+ "lenny" : {
+ "members" : {
+ "supported" : ["lenny", "lenny-security"],
+ "optional" : ["lenny-proposed-updates"]
+ },
+ "release" : "stable"
+ },
+ "squeeze" : {
+ "members" : {
+ "supported" : ["squeeze", "squeeze-security"],
+ "optional" : ["squeeze-proposed-updates"]
+ },
+ "release" : "testing"
+ },
+ "sid" : {
+ "members" : {
+ "supported" : ["sid"]
+ },
+ "release" : "unstable"
+ }
+ }
+}
Modified: lib/python/sectracker/repo.py
===================================================================
--- lib/python/sectracker/repo.py 2010-05-08 14:49:37 UTC (rev 14642)
+++ lib/python/sectracker/repo.py 2010-05-08 16:30:10 UTC (rev 14643)
@@ -18,6 +18,7 @@
from __future__ import with_statement
import bz2 as _bz2
+import cjson as _cjson
import hashlib as _hashlib
import gzip as _gzip
import os as _os
@@ -199,7 +200,10 @@
with file(self._relname(name)) as f:
return _parserelease(name, f)
- def filemap(self):
+ def filemap(self, load=False):
+ """Returns dictionaries mapping repositories to components to files.
+ If load is true, the files are loaded using the source packages
+ parser."""
d = {}
for name in self.repos:
rel = self.release(name)
@@ -216,7 +220,10 @@
self.warn("file %s for %s/%s not present" %
(listname, name, comp))
continue
- comps[comp] = listname
+ if load:
+ comps[comp] = _parsers.sourcepackages(listname)
+ else:
+ comps[comp] = listname
d[name] = comps
return d
@@ -245,3 +252,51 @@
def warn(self, msg):
if self.verbose:
print msg
+
+class Config(object):
+ def __init__(self, config, root):
+ with file(config) as f:
+ self.config = _cjson.decode(f.read())
+ self.repositories = self.config["repositories"]
+ self.distributions = self.config["distributions"]
+ self.releases = {}
+
+ self.collection = RepoCollection(root)
+ for k,v in self.repositories.items():
+ self.collection.add(k, v)
+
+ for d, dobj in self.distributions.items():
+ for m, mobj in dobj.get("members", {}).items():
+ for mem in mobj:
+ if mem not in self.repositories:
+ raise ValueError(
+ "distributions[%r][%r] (%r) not a valid repository"
+ % (d, m, mem))
+ if dobj.has_key("release"):
+ rel = dobj["release"]
+ if rel in self.releases:
+ raise ValueError(
+ "distributions[%r] is duplicate of %r (previous was %r)"
+ % (d, rel, self.releases[rel]))
+ self.releases[rel] = d
+
+ def update(self):
+ self.collection.update()
+
+ def releasepackageversions(self):
+ """Returns dictionaries mapping release codenames to packages
+ to a set of versions."""
+ fm = self.collection.filemap(load=True)
+ r = {}
+ for d, dobj in self.distributions.items():
+ pkgver = {}
+ for mobj in dobj.get("members", {}).values():
+ for mem in mobj:
+ for comps in fm[mem].values():
+ for src in comps.values():
+ if src.name in pkgver:
+ pkgver[src.name].add(src.version)
+ else:
+ pkgver[src.name] = set((src.version,))
+ r[d] = pkgver
+ return r
Modified: lib/python/sectracker_test/test_repo.py
===================================================================
--- lib/python/sectracker_test/test_repo.py 2010-05-08 14:49:37 UTC (rev 14642)
+++ lib/python/sectracker_test/test_repo.py 2010-05-08 16:30:10 UTC (rev 14643)
@@ -15,6 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import os.path
import shutil
import tempfile
@@ -41,3 +42,12 @@
assert "bash" in o["bash"].binary
finally:
shutil.rmtree(tmp)
+
+if not os.path.exists("sectracker_test/tmp"):
+ os.makedirs("sectracker_test/tmp")
+c = Config("../../data/config.json", "sectracker_test/tmp/repo")
+c.update()
+rpv = c.releasepackageversions()
+assert "sid" in rpv
+assert "bash" in rpv["sid"]
+
More information about the Secure-testing-commits
mailing list