[Collab-qa-commits] r1318 - upload-history

filippo at alioth.debian.org filippo at alioth.debian.org
Sat Oct 4 18:30:57 UTC 2008


Author: filippo
Date: 2008-10-04 18:30:57 +0000 (Sat, 04 Oct 2008)
New Revision: 1318

Added:
   upload-history/munged_to_sqlite.py
Log:
script to import from munged format to sqlite

Added: upload-history/munged_to_sqlite.py
===================================================================
--- upload-history/munged_to_sqlite.py	                        (rev 0)
+++ upload-history/munged_to_sqlite.py	2008-10-04 18:30:57 UTC (rev 1318)
@@ -0,0 +1,56 @@
+#!/usr/bin/python
+
+from debian_bundle import deb822
+import sqlite3
+
+import sys
+import rfc822
+import os
+import cPickle
+import gzip
+
+done_cache = {}
+
+def munged_to_sqlite(file, connection, cache):
+    if file.endswith(".gz"):
+        paragraphs = deb822.Deb822.iter_paragraphs(gzip.open(file))
+    else: 
+        paragraphs = deb822.Deb822.iter_paragraphs(open(file))
+
+    c = connection.cursor()
+    for p in paragraphs:
+        cache_key = p['Source'] + p['Version']
+
+        if cache.has_key(cache_key):
+            sys.stderr.write("skipping %s\n" % cache_key)
+            continue
+        epochdate = int(rfc822.mktime_tz(rfc822.parsedate_tz(p['Date'])))
+        c.execute("INSERT INTO uploads VALUES (?,?,?,?,?,?)",
+                    (p['Source'], p['Version'], epochdate,
+                     p['Maintainer'], p['Changed-By'], p['NMU'])
+                 )
+        cache[cache_key] = 1
+    c.close()
+
+    
+if __name__ == '__main__':
+    if len(sys.argv) < 2:
+        print "usage: file1 .. fileN"
+        sys.exit(1)
+
+    if os.path.exists("imports_done.db") and not os.environ.has_key("NO_CACHE"):
+        done_cache = cPickle.load(open("imports_done.db"))
+
+    conn = sqlite3.connect("upload-history.db")
+
+    for f in sys.argv[1:]:
+        munged_to_sqlite(f, conn, done_cache)
+
+        conn.commit()
+
+        if not os.environ.has_key("NO_CACHE"):
+            cPickle.dump(done_cache, open("imports_done.db", "w"), 2)
+
+    conn.close()
+
+# vim: et:ts=4:sw=4


Property changes on: upload-history/munged_to_sqlite.py
___________________________________________________________________
Name: svn:executable
   + *




More information about the Collab-qa-commits mailing list