[Collab-qa-commits] r1603 - in udd: . sql udd

Lucas Nussbaum lucas at alioth.debian.org
Mon Oct 19 20:03:17 UTC 2009


Author: lucas
Date: 2009-10-19 20:03:16 +0000 (Mon, 19 Oct 2009)
New Revision: 1603

Added:
   udd/udd/wannabuild_gatherer.py
Modified:
   udd/config-org.yaml
   udd/sql/setup.sql
Log:
add an importer for wanna-build data

Modified: udd/config-org.yaml
===================================================================
--- udd/config-org.yaml	2009-10-16 18:33:43 UTC (rev 1602)
+++ udd/config-org.yaml	2009-10-19 20:03:16 UTC (rev 1603)
@@ -21,6 +21,7 @@
     screenshots: module udd.screenshot_gatherer
     dehs: module udd.dehs_gatherer
     ldap: module udd.ldap_gatherer
+    wannabuild: module udd.wannabuild_gatherer
   timestamp-dir: /org/udd.debian.org/timestamps
   lock-dir: /org/udd.debian.org/locks
   archs:
@@ -423,3 +424,11 @@
   cache: /org/udd.debian.org/mirrors/cache
   table:  screenshots
   screenshots_json: /org/udd.debian.org/mirrors/screenshots/screenshots.json
+
+wannabuild:
+  type: wannabuild
+  wbdb: "dbname=wanna-build host=localhost port=5433 user=guest"
+  archs: [alpha, amd64, arm, armel, hppa, hurd-i386,
+    i386, ia64, kfreebsd-amd64, kfreebsd-i386, mips,
+    mipsel, powerpc, s390, sparc]
+

Modified: udd/sql/setup.sql
===================================================================
--- udd/sql/setup.sql	2009-10-16 18:33:43 UTC (rev 1602)
+++ udd/sql/setup.sql	2009-10-19 20:03:16 UTC (rev 1603)
@@ -519,6 +519,23 @@
 );
 GRANT SELECT ON ldap TO guestdd;
 
+-- wannabuild
+CREATE TABLE wannabuild (
+  source text,
+  distribution text,
+  architecture text,
+  version debversion,
+  state text,
+  installed_version debversion,
+  previous_state text,
+  state_change timestamp,
+  binary_nmu_version numeric,
+  notes text,
+  PRIMARY KEY (source, distribution, architecture)
+);
+GRANT SELECT ON wannabuild TO public;
+
+
 -- views
 -- bugs_count
 create view bugs_count as

Added: udd/udd/wannabuild_gatherer.py
===================================================================
--- udd/udd/wannabuild_gatherer.py	                        (rev 0)
+++ udd/udd/wannabuild_gatherer.py	2009-10-19 20:03:16 UTC (rev 1603)
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+"""
+This script imports some fields from the Debian LDAP into the database
+"""
+
+from aux import quote
+from gatherer import gatherer
+import re
+import psycopg2
+import time
+
+def get_gatherer(connection, config, source):
+  return wannabuild_gatherer(connection, config, source)
+
+class wannabuild_gatherer(gatherer):
+
+  def __init__(self, connection, config, source):
+    gatherer.__init__(self, connection, config, source)
+    self.assert_my_config()
+
+  def run(self):
+    #start harassing the DB, preparing the final inserts and making place
+    #for the new data:
+    cur = self.cursor()
+
+    cur.execute("DELETE FROM wannabuild")
+
+    cur.execute("""PREPARE wb_insert 
+      AS INSERT INTO wannabuild
+      (architecture, source, distribution, version, state, installed_version, previous_state, state_change, binary_nmu_version, notes)
+      VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)""")
+
+    wbconn = psycopg2.connect(self.my_config['wbdb'])
+    wbcur = wbconn.cursor()
+
+    entries = []
+    for arch in self.my_config['archs']:
+        wbcur.execute("SELECT package, distribution, version, state, installed_version, previous_state, state_change, binary_nmu_version, notes FROM \"%s_public\".packages" % arch)
+        for row in wbcur.fetchall():
+            row = list(row)
+            if row[6] != None:
+                try:
+                    t = time.strptime(row[6], "%Y %b %d %H:%M:%S")
+                    row[6] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", t)
+                except ValueError:
+                    row[6] = None
+            entries.append([arch] + row)
+        cur.executemany("EXECUTE wb_insert (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", entries)
+        entries = []
+    cur.execute("DEALLOCATE wb_insert")
+    cur.execute("ANALYZE wannabuild")
+
+if __name__ == '__main__':
+  main()
+
+# vim:set et tabstop=2:




More information about the Collab-qa-commits mailing list