]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update7.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / dakdb / update7.py
1 #!/usr/bin/env python
2 # coding=utf8
3
4 """
5 Moving suite config into DB
6
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2008  Michael Casadevall <mcasadevall@debian.org>
9 @copyright: 2009  Joerg Jaspert <joerg@debian.org>
10 @license: GNU General Public License version 2 or later
11
12 """
13
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
18
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
28 ################################################################################
29
30 # * Ganneff ponders how to best write the text to -devel. (need to tell em in
31 #   case they find more bugs). "We fixed the fucking idiotic broken implementation
32 #   to be less so" is probably not the nicest, even if perfect valid, way to say so
33
34 ################################################################################
35
36 import psycopg2
37 import time
38 from daklib.dak_exceptions import DBUpdateError
39 from daklib.utils import get_conf
40
41 ################################################################################
42
43 def do_update(self):
44     print "Moving some of the suite config into the DB"
45     Cnf = get_conf()
46
47     try:
48         c = self.db.cursor()
49
50         c.execute("ALTER TABLE suite ADD COLUMN untouchable BOOLEAN NOT NULL DEFAULT FALSE;")
51         query = "UPDATE suite SET untouchable = TRUE WHERE suite_name = %s"  #: Update query
52         for suite in Cnf.SubTree("Suite").List():
53             untouchable = Cnf.Find("Suite::%s::Untouchable" % (suite))
54             if not untouchable:
55                 continue
56             print "[Untouchable] Processing suite %s" % (suite)
57             suite = suite.lower()
58             c.execute(query, [suite])
59
60
61         c.execute("ALTER TABLE suite ADD COLUMN announce text NOT NULL DEFAULT 'debian-devel-changes@lists.debian.org';")
62         query = "UPDATE suite SET announce = %s WHERE suite_name = %s"  #: Update query
63         for suite in Cnf.SubTree("Suite").List():
64             announce_list = Cnf.Find("Suite::%s::Announce" % (suite))
65             print "[Announce] Processing suite %s" % (suite)
66             suite = suite.lower()
67             c.execute(query, [announce_list, suite])
68
69         c.execute("ALTER TABLE suite ADD COLUMN codename text;")
70         query = "UPDATE suite SET codename = %s WHERE suite_name = %s"  #: Update query
71         for suite in Cnf.SubTree("Suite").List():
72             codename = Cnf.Find("Suite::%s::CodeName" % (suite))
73             print "[Codename] Processing suite %s" % (suite)
74             suite = suite.lower()
75             c.execute(query, [codename, suite])
76
77         c.execute("ALTER TABLE suite ADD COLUMN overridecodename text;")
78         query = "UPDATE suite SET overridecodename = %s WHERE suite_name = %s"  #: Update query
79         for suite in Cnf.SubTree("Suite").List():
80             codename = Cnf.Find("Suite::%s::OverrideCodeName" % (suite))
81             print "[OverrideCodeName] Processing suite %s" % (suite)
82             suite = suite.lower()
83             c.execute(query, [codename, suite])
84
85         c.execute("ALTER TABLE suite ADD COLUMN validtime integer NOT NULL DEFAULT 604800;")
86         query = "UPDATE suite SET validtime = %s WHERE suite_name = %s"  #: Update query
87         for suite in Cnf.SubTree("Suite").List():
88             validtime = Cnf.Find("Suite::%s::ValidTime" % (suite))
89             print "[ValidTime] Processing suite %s" % (suite)
90             if not validtime:
91                 validtime = 0
92             suite = suite.lower()
93             c.execute(query, [validtime, suite])
94
95         c.execute("ALTER TABLE suite ADD COLUMN priority integer NOT NULL DEFAULT 0;")
96         query = "UPDATE suite SET priority = %s WHERE suite_name = %s"  #: Update query
97         for suite in Cnf.SubTree("Suite").List():
98             priority = Cnf.Find("Suite::%s::Priority" % (suite))
99             print "[Priority] Processing suite %s" % (suite)
100             if not priority:
101                 priority = 0
102             suite = suite.lower()
103             c.execute(query, [priority, suite])
104
105
106         c.execute("ALTER TABLE suite ADD COLUMN notautomatic BOOLEAN NOT NULL DEFAULT FALSE;")
107         query = "UPDATE suite SET notautomatic = TRUE WHERE suite_name = %s"  #: Update query
108         for suite in Cnf.SubTree("Suite").List():
109             notautomatic = Cnf.Find("Suite::%s::NotAutomatic" % (suite))
110             print "[NotAutomatic] Processing suite %s" % (suite)
111             if not notautomatic:
112                 continue
113             suite = suite.lower()
114             c.execute(query, [suite])
115
116         c.execute("UPDATE config SET value = '7' WHERE name = 'db_revision'")
117         self.db.commit()
118
119     except psycopg2.ProgrammingError as msg:
120         self.db.rollback()
121         raise DBUpdateError, "Unable to appy suite config updates, rollback issued. Error message : %s" % (str(msg))