From: Joerg Jaspert Date: Wed, 23 Apr 2008 19:02:56 +0000 (+0200) Subject: Merge Myons patch to write the changed-by information into the database X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=1e8dd7a1e4aa362cb5275a4db27251a77e5a9c34;hp=5558f026c44ea053c2be6e66bf733e8740406a58;p=dak.git Merge Myons patch to write the changed-by information into the database --- diff --git a/ChangeLog b/ChangeLog index 8b132e72..4f72b591 100644 --- a/ChangeLog +++ b/ChangeLog @@ -148,6 +148,15 @@ * 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 * daklib/utils.py (check_signature): Make variable key available, diff --git a/dak/process_accepted.py b/dak/process_accepted.py index 90edaf55..86396832 100755 --- a/dak/process_accepted.py +++ b/dak/process_accepted.py @@ -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 index 00000000..7b817b5e --- /dev/null +++ b/scripts/debian/insert_missing_changedby.py @@ -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 + +# 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() diff --git a/setup/add_constraints.sql b/setup/add_constraints.sql index 8d275502..1d2bad66 100644 --- a/setup/add_constraints.sql +++ b/setup/add_constraints.sql @@ -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; diff --git a/setup/init_pool.sql b/setup/init_pool.sql index 0ab91ad6..9925148c 100644 --- a/setup/init_pool.sql +++ b/setup/init_pool.sql @@ -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,