summaryrefslogtreecommitdiffstats
path: root/bin/list-queue
diff options
context:
space:
mode:
authorFlorian Weimer <fw@deneb.enyo.de>2011-04-24 14:07:43 +0000
committerFlorian Weimer <fw@deneb.enyo.de>2011-04-24 14:07:43 +0000
commit7fa0aa34bc8530f12e95673d403865f125b860ac (patch)
treeff9740ec141631576329347ee4014362036ed73b /bin/list-queue
parent56780da0846b5ed92cc97a2ec5d33f088e051eda (diff)
bin/list-queue: new script, eventually to be run on security-master
git-svn-id: svn+ssh://svn.debian.org/svn/secure-testing@16576 e39458fd-73e7-0310-bf30-c45bca0a0e42
Diffstat (limited to 'bin/list-queue')
-rwxr-xr-xbin/list-queue126
1 files changed, 126 insertions, 0 deletions
diff --git a/bin/list-queue b/bin/list-queue
new file mode 100755
index 0000000000..167e9afe34
--- /dev/null
+++ b/bin/list-queue
@@ -0,0 +1,126 @@
+#!/usr/bin/python
+# list-queue -- list security-master queue contents
+# Copyright (C) 2011 Florian Weimer <fw@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
+
+# This script is intended to be run on security-master to get an
+# unprocessed dump of the contents of the embargoed and unembargoed
+# queues.
+#
+# The script reads .deb files. A caching database is written to
+# ~/.cache.
+
+
+######################################################################
+# Configuration
+
+DIRECTORIES = ('/org/security-master.debian.org/queue/embargoed',
+ '/org/security-master.debian.org/queue/unembargoed')
+
+# End Configuration
+######################################################################
+
+import sys
+import os.path
+def setup_path():
+ dirname = os.path.dirname
+ base = dirname(dirname(os.path.realpath(sys.argv[0])))
+ sys.path.insert(0, os.path.join(base, "lib", "python"))
+setup_path()
+
+import sqlite3
+import json
+
+import debian_support
+
+def createdb():
+ cache = os.path.expanduser("~/.cache")
+ if not os.path.isdir(cache):
+ os.mkdir(cache)
+ dbfile = os.path.join(cache, "secure-testing_list-debs.sqlite")
+ db = sqlite3.connect(dbfile, isolation_level="IMMEDIATE")
+ db.execute("PRAGMA page_size = 4096")
+ db.execute("PRAGMA journal_mode = WAL")
+ db.execute("""CREATE TABLE IF NOT EXISTS package (
+ path TEXT NOT NULL PRIMARY KEY,
+ size INTEGER NOT NULL CHECK (size >= 0),
+ mtime INTEGER NOT NULL CHECK (size >= 0),
+ name TEXT NOT NULL,
+ version TEXT NOT NULL,
+ arch TEXT NOT NULL,
+ source TEXT NOT NULL,
+ source_version TEXT NOT NULL
+)""")
+ return db
+
+def readdirs():
+ result = {}
+ for path in DIRECTORIES:
+ for entry in os.listdir(path):
+ if entry.startswith(".") or not entry.endswith(".deb"):
+ continue
+ name = os.path.join(path, entry)
+ stat = os.stat(name)
+ result[name] = (stat.st_size, stat.st_mtime)
+ return result
+
+def readpackages(db):
+ result = {}
+ c = db.cursor()
+ for row in c.execute("SELECT * FROM package"):
+ name, size, mtime = row[0:3]
+ pkg = debian_support.BinaryPackage(row[3:])
+ result[name] = (size, mtime, pkg)
+ return result
+
+def updatepackages(db):
+ """Updates the package table from the file system.
+
+ Returns the current list of package objects, in arbitary order.
+ """
+ ondisk = readdirs()
+ indb = readpackages(db)
+
+ # Expire old entries
+ need_delete = ((path,) for path in indb if path not in ondisk)
+ db.executemany("DELETE FROM package WHERE path = ?", need_delete)
+
+ # Update the cache in indb and the database
+ need_update = [(path, stat) for (path, stat) in ondisk.items()
+ if path not in indb or stat <> tuple(indb[path][0:2])]
+ db.executemany("DELETE FROM package WHERE path = ?",
+ ((path,) for path, _ in need_update))
+ def do_update():
+ for (path, stat) in need_update:
+ pkg = debian_support.inspect_deb(path)
+ indb[path] = stat + (pkg,)
+ yield (path,) + stat + pkg.astuple()
+ db.executemany("INSERT INTO package VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
+ do_update())
+
+ # Return a list of BinaryPackage objects
+ return [item[2] for item in indb.values()]
+
+def main():
+ db = createdb()
+ pkgs = updatepackages(db)
+ result = {
+ "version" : 1,
+ "binary" : [pkg.astuple() for pkg in pkgs],
+ }
+ db.commit()
+ print json.dumps(result)
+main()

© 2014-2024 Faster IT GmbH | imprint | privacy policy