3 # Adds yet unknown changedby fields when this column is added to an existing
4 # database. If everything goes well, it needs to be run only once. Data is
5 # extracted from Filippo Giunchedi's upload-history project, get the file at
6 # merkel:/home/filippo/upload-history/*.db.
8 # Copyright (C) 2008 Christoph Berg <myon@debian.org>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ###############################################################################
26 # /Everybody stand back/
28 # I know regular expressions
30 ###############################################################################
32 import errno, fcntl, os, sys, time, re
34 import daklib.database
37 from pysqlite2 import dbapi2 as sqlite
40 DBNAME = "uploads-ddc.db"
43 ###############################################################################
46 print "Adding missing changedby fields."
48 projectB.query("BEGIN WORK")
50 q = projectB.query("SELECT id, source, version FROM source WHERE changedby IS NULL")
52 for i in q.getresult():
53 print i[1] + "/" + i[2] + ":",
55 cur = sqliteConn.cursor()
56 cur.execute("SELECT changedby FROM uploads WHERE package = '%s' AND version = '%s' LIMIT 1" % (i[1], i[2]))
62 changedby = res[0][0].replace("'", "\\'")
63 changedby_id = daklib.database.get_or_set_maintainer_id(changedby)
65 projectB.query("UPDATE source SET changedby = %d WHERE id = %d" % (changedby_id, i[0]))
66 print changedby, "(%d)" % changedby_id
68 projectB.query("COMMIT WORK")
70 ###############################################################################
73 global projectB, sqliteConn
75 Cnf = daklib.utils.get_conf()
76 Upload = daklib.queue.Upload(Cnf)
77 projectB = Upload.projectB
79 sqliteConn = sqlite.connect(DBNAME)
83 ###############################################################################
85 if __name__ == '__main__':