]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update1.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / dakdb / update1.py
1 #!/usr/bin/env python
2
3 """
4 Saner DM db schema
5
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2008  Michael Casadevall <mcasadevall@debian.org>
8 @license: GNU General Public License version 2 or later
9 """
10
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
25 ################################################################################
26
27 # <tomv_w> really, if we want to screw ourselves, let's find a better way.
28 # <Ganneff> rm -rf /srv/ftp.debian.org
29
30 ################################################################################
31
32 import psycopg2
33 import time
34 from daklib.dak_exceptions import DBUpdateError
35
36 ################################################################################
37
38 def do_update(self):
39     print "Adding DM fields to database"
40
41     try:
42         c = self.db.cursor()
43         c.execute("ALTER TABLE source ADD COLUMN dm_upload_allowed BOOLEAN DEFAULT 'no' NOT NULL;")
44         c.execute("ALTER TABLE keyrings ADD COLUMN debian_maintainer BOOLEAN DEFAULT 'false' NOT NULL;")
45
46         print "Migrating DM data to source table. This might take some time ..."
47
48         c.execute("UPDATE source SET dm_upload_allowed = 't' WHERE id IN (SELECT source FROM src_uploaders);")
49         c.execute("UPDATE config SET value = '1' WHERE name = 'db_revision'")
50
51         print "Migrating DM uids to normal uids"
52         c.execute("SELECT uid FROM uid WHERE uid  LIKE 'dm:%'")
53         rows = c.fetchall()
54         for r in rows:
55             uid = r[0]
56             c.execute("UPDATE uid SET uid = '%s' WHERE uid = '%s'" % (uid[3:], uid))
57
58         self.db.commit()
59
60         print "IMPORTANT: Set the debian_maintainer flag in the config file for keyrings that are DMs!"
61         print "           Failure to do so will result in DM's having full upload abilities!"
62         print "REMINDER: Remember to run the updated byhand-dm crontab to update Debian Maintainer information"
63         print ""
64         print "Pausing for five seconds ..."
65         time.sleep (5)
66
67     except psycopg2.ProgrammingError as msg:
68         self.db.rollback()
69         raise DBUpdateError, "Unable to appy DM table updates, rollback issued. Error message : %s" % (str(msg))