Author: fw Date: 2011-04-24 16:14:39 +0000 (Sun, 24 Apr 2011) New Revision: 16583 Added: lib/python/secmaster.py Log: secmaster: new Python module Added: lib/python/secmaster.py ==================================================================--- lib/python/secmaster.py (rev 0) +++ lib/python/secmaster.py 2011-04-24 16:14:39 UTC (rev 16583) @@ -0,0 +1,74 @@ +#!/usr/bin/python +# secmaster -- access to data on security-master.debian.org +# Copyright (C) 2011 Florian Weimer <fw at deneb.enyo.de> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +# Name of the security-master host +HOST = "chopin.debian.org" + +import json +import subprocess + +import debian_support + +def listqueue(): + """Returns a list of pairs (PACKAGE, SET-OF-DISTRIBUTIONS). + + PACKAGE is a debian_support.BinaryPackage object. + SET-OF-DISTRIBUTIONS contains normalized distribution names, + using the code names (sid etc.). + """ + ssh = subprocess.Popen( + ("ssh", "chopin.debian.org", "secure-testing/bin/list-queue"), + stdin=file("/dev/null"), + stdout=subprocess.PIPE) + data = ssh.stdout.read() + ssh.wait() + if ssh.returncode != 0: + raise IOError("unexpected ssh return code: " + repr(ssh.returncode)) + data = json.loads(data) + if data["version"] != 1: + raise IOError("unexpected version number: " + repr(data["version"])) + + distributions = debian_support.getconfig()["distributions"] + distdict = {} + def normdist(dist): + if dist in distdict: + return distdict[dist] + if dist.endswith("-security"): + d = dist[:-9] + else: + d = dist + result = None + if d in distributions: + result = d + else: + for (codename, obj) in distributions.items(): + if obj.get("release", None) == d: + result = codename + break + if result is None: + raise ValueError("unknown distribution: " + repr(dist)) + distdict[dist] = result + return result + + return [(debian_support.BinaryPackage(row[0:5]), + set(normdist(dist) for dist in row[5])) + for row in data["binary"]] + +if __name__ == "__main__": + for pkg, archs in listqueue(): + print " ".join(pkg.astuple()), "=>", ", ".join(archs)