]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update15.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / dakdb / update15.py
1 #!/usr/bin/env python
2 # coding=utf8
3
4 """
5 Adding table for allowed source formats
6
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2009  Raphael Hertzog <hertzog@debian.org>
9 @license: GNU General Public License version 2 or later
10 """
11
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
26 ################################################################################
27
28
29 ################################################################################
30
31 import psycopg2
32 import time
33 from daklib.dak_exceptions import DBUpdateError
34
35 ################################################################################
36
37 def do_update(self):
38     print "Adding tables listing allowed source formats"
39
40     try:
41         c = self.db.cursor()
42         c.execute("""
43             CREATE TABLE src_format (
44                     id SERIAL PRIMARY KEY,
45                     format_name TEXT NOT NULL,
46                     UNIQUE (format_name)
47             )
48         """)
49         c.execute("INSERT INTO src_format (format_name) VALUES('1.0')")
50         c.execute("INSERT INTO src_format (format_name) VALUES('3.0 (quilt)')")
51         c.execute("INSERT INTO src_format (format_name) VALUES('3.0 (native)')")
52
53         c.execute("""
54             CREATE TABLE suite_src_formats (
55                     suite INT4 NOT NULL REFERENCES suite(id),
56                     src_format INT4 NOT NULL REFERENCES src_format(id),
57                     PRIMARY KEY (suite, src_format)
58             )
59         """)
60
61         print "Authorize format 1.0 on all suites by default"
62         c.execute("SELECT id FROM suite")
63         suites = c.fetchall()
64         c.execute("SELECT id FROM src_format WHERE format_name = '1.0'")
65         formats = c.fetchall()
66         for s in suites:
67             for f in formats:
68                 c.execute("INSERT INTO suite_src_formats (suite, src_format) VALUES(%s, %s)", (s[0], f[0]))
69
70         print "Authorize all other formats on tpu, unstable & experimental by default"
71         c.execute("SELECT id FROM suite WHERE suite_name IN ('testing-proposed-updates', 'unstable', 'experimental')")
72         suites = c.fetchall()
73         c.execute("SELECT id FROM src_format WHERE format_name != '1.0'")
74         formats = c.fetchall()
75         for s in suites:
76             for f in formats:
77                 c.execute("INSERT INTO suite_src_formats (suite, src_format) VALUES(%s, %s)", (s[0], f[0]))
78
79         c.execute("UPDATE config SET value = '15' WHERE name = 'db_revision'")
80         self.db.commit()
81
82     except psycopg2.ProgrammingError as msg:
83         self.db.rollback()
84         raise DBUpdateError, "Unable to apply source format update 15, rollback issued. Error message : %s" % (str(msg))