]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update4.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / dakdb / update4.py
1 #!/usr/bin/env python
2 """
3 Get suite_architectures table use sane values
4
5 @contact: Debian FTP Master <ftpmaster@debian.org>
6 @copyright: 2009  Joerg Jaspert <joerg@debian.org>
7 @license: GNU General Public License version 2 or later
8 """
9
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.
14
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.
19
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
23
24 ################################################################################
25
26 import psycopg2
27 from daklib.dak_exceptions import DBUpdateError
28 from daklib.utils import get_conf
29
30 ################################################################################
31
32 suites = {}  #: Cache of existing suites
33 archs = {}   #: Cache of existing architectures
34
35 def do_update(self):
36     """ Execute the DB update """
37
38     print "Lets make suite_architecture table use sane values"
39     Cnf = get_conf()
40
41     query = "INSERT into suite_architectures (suite, architecture) VALUES (%s, %s)"  #: Update query
42     try:
43         c = self.db.cursor()
44         c.execute("DELETE FROM suite_architectures;")
45
46         c.execute("SELECT id, arch_string FROM architecture;")
47         a=c.fetchall()
48         for arch in a:
49             archs[arch[1]]=arch[0]
50
51         c.execute("SELECT id,suite_name FROM suite")
52         s=c.fetchall()
53         for suite in s:
54             suites[suite[1]]=suite[0]
55
56         for suite in Cnf.SubTree("Suite").List():
57             print "Processing suite %s" % (suite)
58             architectures = Cnf.SubTree("Suite::" + suite).ValueList("Architectures")
59             suite = suite.lower()
60             for arch in architectures:
61                 c.execute(query, [suites[suite], archs[arch]])
62
63         c.execute("UPDATE config SET value = '4' WHERE name = 'db_revision'")
64
65         self.db.commit()
66
67     except psycopg2.ProgrammingError as msg:
68         self.db.rollback()
69         raise DBUpdateError, "Unable to apply sanity to suite_architecture table, rollback issued. Error message : %s" % (str(msg))