]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update23.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / dakdb / update23.py
1 #!/usr/bin/env python
2
3 """
4 Add view for new generate_filelist command.
5
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2009  Torsten Werner <twerner@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 import psycopg2
26
27 def do_update(self):
28     print "Add views for generate_filelist to database."
29
30     try:
31         c = self.db.cursor()
32
33         print "Drop old views."
34         c.execute("DROP VIEW IF EXISTS binfiles_suite_component_arch CASCADE")
35         c.execute("DROP VIEW IF EXISTS srcfiles_suite_component CASCADE")
36
37         print "Create new views."
38         c.execute("""
39 CREATE VIEW binfiles_suite_component_arch AS
40   SELECT files.filename, binaries.type, location.path, location.component,
41          bin_associations.suite, binaries.architecture
42     FROM binaries
43     JOIN bin_associations ON binaries.id = bin_associations.bin
44     JOIN files ON binaries.file = files.id
45     JOIN location ON files.location = location.id;
46             """)
47         c.execute("""
48 CREATE VIEW srcfiles_suite_component AS
49   SELECT files.filename, location.path, location.component,
50          src_associations.suite
51     FROM source
52     JOIN src_associations ON source.id = src_associations.source
53     JOIN files ON source.file = files.id
54     JOIN location ON files.location = location.id;
55             """)
56
57         print "Committing"
58         c.execute("UPDATE config SET value = '23' WHERE name = 'db_revision'")
59         self.db.commit()
60
61     except psycopg2.InternalError as msg:
62         self.db.rollback()
63         raise DBUpdateError, "Database error, rollback issued. Error message : %s" % (str(msg))
64