]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update8.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / dakdb / update8.py
1 #!/usr/bin/env python
2 # coding=utf8
3
4 """
5 More suite config into the 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 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
17
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
27 ################################################################################
28
29 # * Ganneff ponders how to best write the text to -devel. (need to tell em in
30 #   case they find more bugs). "We fixed the fucking idiotic broken implementation
31 #   to be less so" is probably not the nicest, even if perfect valid, way to say so
32
33 ################################################################################
34
35 import psycopg2
36 import time
37 from daklib.dak_exceptions import DBUpdateError
38 from daklib.utils import get_conf
39
40 ################################################################################
41
42 def do_update(self):
43     print "Moving some more of the suite config into the DB"
44     Cnf = get_conf()
45
46     try:
47         c = self.db.cursor()
48
49         c.execute("ALTER TABLE suite ADD COLUMN copychanges TEXT;")
50         query = "UPDATE suite SET copychanges = %s WHERE suite_name = %s"  #: Update query
51         for suite in Cnf.SubTree("Suite").List():
52             copychanges = Cnf.Find("Suite::%s::CopyChanges" % (suite))
53             print "[CopyChanges] Processing suite %s" % (suite)
54             if not copychanges:
55                 continue
56             suite = suite.lower()
57             c.execute(query, [copychanges, suite])
58
59         c.execute("ALTER TABLE suite ADD COLUMN copydotdak TEXT;")
60         query = "UPDATE suite SET copydotdak = %s WHERE suite_name = %s"  #: Update query
61         for suite in Cnf.SubTree("Suite").List():
62             copydotdak = Cnf.Find("Suite::%s::CopyDotDak" % (suite))
63             print "[CopyDotDak] Processing suite %s" % (suite)
64             if not copydotdak:
65                 continue
66             suite = suite.lower()
67             c.execute(query, [copydotdak, suite])
68
69         c.execute("ALTER TABLE suite ADD COLUMN commentsdir TEXT;")
70         query = "UPDATE suite SET commentsdir = %s WHERE suite_name = %s"  #: Update query
71         for suite in Cnf.SubTree("Suite").List():
72             commentsdir = Cnf.Find("Suite::%s::CommentsDir" % (suite))
73             print "[CommentsDir] Processing suite %s" % (suite)
74             if not commentsdir:
75                 continue
76             suite = suite.lower()
77             c.execute(query, [commentsdir, suite])
78
79         c.execute("ALTER TABLE suite ADD COLUMN overridesuite TEXT;")
80         query = "UPDATE suite SET overridesuite = %s WHERE suite_name = %s"  #: Update query
81         for suite in Cnf.SubTree("Suite").List():
82             overridesuite = Cnf.Find("Suite::%s::OverrideSuite" % (suite))
83             print "[OverrideSuite] Processing suite %s" % (suite)
84             if not overridesuite:
85                 continue
86             suite = suite.lower()
87             c.execute(query, [overridesuite, suite])
88
89         c.execute("ALTER TABLE suite ADD COLUMN changelogbase TEXT;")
90         query = "UPDATE suite SET changelogbase = %s WHERE suite_name = %s"  #: Update query
91         for suite in Cnf.SubTree("Suite").List():
92             changelogbase = Cnf.Find("Suite::%s::ChangeLogBase" % (suite))
93             print "[ChangeLogBase] Processing suite %s" % (suite)
94             if not changelogbase:
95                 continue
96             suite = suite.lower()
97             c.execute(query, [changelogbase, suite])
98
99         c.execute("UPDATE config SET value = '8' WHERE name = 'db_revision'")
100         self.db.commit()
101
102     except psycopg2.ProgrammingError as msg:
103         self.db.rollback()
104         raise DBUpdateError, "Unable to apply suite config updates, rollback issued. Error message : %s" % (str(msg))