]> git.decadent.org.uk Git - dak.git/commitdiff
Merge Myons patch to write the changed-by information into the database
authorJoerg Jaspert <joerg@debian.org>
Wed, 23 Apr 2008 19:02:56 +0000 (21:02 +0200)
committerJoerg Jaspert <joerg@debian.org>
Wed, 23 Apr 2008 19:02:56 +0000 (21:02 +0200)
ChangeLog
dak/process_accepted.py
scripts/debian/insert_missing_changedby.py [new file with mode: 0755]
setup/add_constraints.sql
setup/init_pool.sql

index 8b132e72ced87f40b23e1cd44fecbfe98f26010d..4f72b591b03c7149670fdaf491d3b3fc78a90a48 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        * daklib/queue.py (get_type): fubar does not exist in global
        namespace.
 
+       * setup/add_constraints.sql setup/init_pool.sql: Add changedby column
+       to source table, and move src_uploaders after source so the REFERNCES
+       clause works.
+       * dak/process_accepted.py (install): Fill the changedby column from
+       the information found in the .changes. This will allow to identify
+       NMUs and sponsored uploads more precisely in tools querying projectb.
+       * scripts/debian/insert_missing_changedby.py: Script to import yet
+       missing fields from filippo's uploads-history DB.
+
 2008-02-06  Joerg Jaspert  <joerg@debian.org>
 
        * daklib/utils.py (check_signature): Make variable key available,
index 90edaf55d2e73f1ad3f53a5452b9461e7f1fc44e..86396832e741e864fb8355ce976d06927235efd6 100755 (executable)
@@ -281,6 +281,9 @@ def install ():
             maintainer = dsc["maintainer"]
             maintainer = maintainer.replace("'", "\\'")
             maintainer_id = daklib.database.get_or_set_maintainer_id(maintainer)
+            changedby = changes["changed-by"]
+            changedby = changedby.replace("'", "\\'")
+            changedby_id = daklib.database.get_or_set_maintainer_id(changedby)
             fingerprint_id = daklib.database.get_or_set_fingerprint_id(dsc["fingerprint"])
             install_date = time.strftime("%Y-%m-%d")
             filename = files[file]["pool name"] + file
@@ -288,8 +291,8 @@ def install ():
             dsc_location_id = files[file]["location id"]
             if not files[file].has_key("files id") or not files[file]["files id"]:
                 files[file]["files id"] = daklib.database.set_files_id (filename, files[file]["size"], files[file]["md5sum"], dsc_location_id)
-            projectB.query("INSERT INTO source (source, version, maintainer, file, install_date, sig_fpr) VALUES ('%s', '%s', %d, %d, '%s', %s)"
-                           % (package, version, maintainer_id, files[file]["files id"], install_date, fingerprint_id))
+            projectB.query("INSERT INTO source (source, version, maintainer, changedby, file, install_date, sig_fpr) VALUES ('%s', '%s', %d, %d, %d, '%s', %s)"
+                           % (package, version, maintainer_id, changedby_id, files[file]["files id"], install_date, fingerprint_id))
 
             for suite in changes["distribution"].keys():
                 suite_id = daklib.database.get_suite_id(suite)
diff --git a/scripts/debian/insert_missing_changedby.py b/scripts/debian/insert_missing_changedby.py
new file mode 100755 (executable)
index 0000000..7b817b5
--- /dev/null
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+
+# Adds yet unknown changedby fields when this column is added to an existing
+# database. If everything goes well, it needs to be run only once. Data is
+# extracted from Filippo Giunchedi's upload-history project, get the file at
+# merkel:/home/filippo/upload-history/*.db.
+
+# Copyright (C) 2008  Christoph Berg <myon@debian.org>
+
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+###############################################################################
+
+#    /Everybody stand back/
+#
+#    I know regular expressions
+
+###############################################################################
+
+import errno, fcntl, os, sys, time, re
+import apt_pkg
+import daklib.database
+import daklib.queue
+import daklib.utils
+from pysqlite2 import dbapi2 as sqlite
+
+projectB = None
+DBNAME = "uploads-ddc.db"
+sqliteConn = None
+
+###############################################################################
+
+def insert ():
+    print "Adding missing changedby fields."
+
+    projectB.query("BEGIN WORK")
+
+    q = projectB.query("SELECT id, source, version FROM source WHERE changedby IS NULL")
+
+    for i in q.getresult():
+        print i[1] + "/" + i[2] + ":",
+
+        cur = sqliteConn.cursor()
+        cur.execute("SELECT changedby FROM uploads WHERE package = '%s' AND version = '%s' LIMIT 1" % (i[1], i[2]))
+        res = cur.fetchall()
+        if len(res) != 1:
+            print "nothing found"
+            continue
+
+        changedby = res[0][0].replace("'", "\\'")
+        changedby_id = daklib.database.get_or_set_maintainer_id(changedby)
+
+        projectB.query("UPDATE source SET changedby = %d WHERE id = %d" % (changedby_id, i[0]))
+        print changedby, "(%d)" % changedby_id
+
+    projectB.query("COMMIT WORK")
+
+###############################################################################
+
+def main():
+    global projectB, sqliteConn
+
+    Cnf = daklib.utils.get_conf()
+    Upload = daklib.queue.Upload(Cnf)
+    projectB = Upload.projectB
+
+    sqliteConn = sqlite.connect(DBNAME)
+
+    insert()
+
+###############################################################################
+
+if __name__ == '__main__':
+    main()
index 8d275502c313cfa9d19fc9e4fd7ff46fd6e71c11..1d2bad66f4e0684937856526932d7851794a954f 100644 (file)
@@ -5,6 +5,7 @@
 ALTER TABLE files ADD CONSTRAINT files_location FOREIGN KEY (location) REFERENCES location(id) MATCH FULL;
 
 ALTER TABLE source ADD CONSTRAINT source_maintainer FOREIGN KEY (maintainer) REFERENCES maintainer(id) MATCH FULL;
+ALTER TABLE source ADD CONSTRAINT source_changedby FOREIGN KEY (changedby) REFERENCES maintainer(id) MATCH FULL;
 ALTER TABLE source ADD CONSTRAINT source_file FOREIGN KEY (file) REFERENCES files(id) MATCH FULL;
 ALTER TABLE source ADD CONSTRAINT source_sig_fpr FOREIGN KEY (sig_fpr) REFERENCES fingerprint(id) MATCH FULL;
 
index 0ab91ad637213fa8c1d937f993e01627e23adb41..9925148cfcd9638d66e025a10d03178c72f20c87 100644 (file)
@@ -28,12 +28,6 @@ CREATE TABLE maintainer (
        name TEXT UNIQUE NOT NULL
 );
 
-CREATE TABLE src_uploaders (
-       id SERIAL PRIMARY KEY,
-       source INT4 NOT NULL REFERENCES source,
-       maintainer INT4 NOT NULL REFERENCES maintainer
-);
-
 CREATE TABLE uid (
        id SERIAL PRIMARY KEY,
        uid TEXT UNIQUE NOT NULL,
@@ -78,12 +72,19 @@ CREATE TABLE source (
         source TEXT NOT NULL,
         version TEXT NOT NULL,
         maintainer INT4 NOT NULL, -- REFERENCES maintainer
+        changedby INT4 NOT NULL, -- REFERENCES maintainer
         file INT4 UNIQUE NOT NULL, -- REFERENCES files
        install_date TIMESTAMP NOT NULL,
        sig_fpr INT4 NOT NULL, -- REFERENCES fingerprint
        unique (source, version)
 );
 
+CREATE TABLE src_uploaders (
+       id SERIAL PRIMARY KEY,
+       source INT4 NOT NULL REFERENCES source,
+       maintainer INT4 NOT NULL REFERENCES maintainer
+);
+
 CREATE TABLE dsc_files (
        id SERIAL PRIMARY KEY,
        source INT4 NOT NULL, -- REFERENCES source,