]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update8.py
Merge commit 'godog/master' into merge
[dak.git] / dak / dakdb / update8.py
1 #!/usr/bin/env python
2 # coding=utf8
3
4 """
5 Debian Archive Kit Database Update Script
6 Copyright © 2008  Michael Casadevall <mcasadevall@debian.org>
7 Copyright © 2009  Joerg Jaspert <joerg@debian.org>
8
9 Debian Archive Kit Database Update Script 8
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 # * Ganneff ponders how to best write the text to -devel. (need to tell em in
29 #   case they find more bugs). "We fixed the fucking idiotic broken implementation
30 #   to be less so" is probably not the nicest, even if perfect valid, way to say so
31
32 ################################################################################
33
34 import psycopg2
35 import time
36 from daklib.dak_exceptions import DBUpdateError
37 from daklib.utils import get_conf
38
39 ################################################################################
40
41 def do_update(self):
42     print "Moving some more of the suite config into the DB"
43     Cnf = get_conf()
44
45     try:
46         c = self.db.cursor()
47
48         c.execute("ALTER TABLE suite ADD COLUMN copychanges TEXT;")
49         query = "UPDATE suite SET copychanges = %s WHERE suite_name = %s"  #: Update query
50         for suite in Cnf.SubTree("Suite").List():
51             copychanges = Cnf.Find("Suite::%s::CopyChanges" % (suite))
52             print "[CopyChanges] Processing suite %s" % (suite)
53             if not copychanges:
54                 continue
55             suite = suite.lower()
56             c.execute(query, [copychanges, suite])
57
58         c.execute("ALTER TABLE suite ADD COLUMN copydotdak TEXT;")
59         query = "UPDATE suite SET copydotdak = %s WHERE suite_name = %s"  #: Update query
60         for suite in Cnf.SubTree("Suite").List():
61             copydotdak = Cnf.Find("Suite::%s::CopyDotDak" % (suite))
62             print "[CopyDotDak] Processing suite %s" % (suite)
63             if not copydotdak:
64                 continue
65             suite = suite.lower()
66             c.execute(query, [copydotdak, suite])
67
68         c.execute("ALTER TABLE suite ADD COLUMN commentsdir TEXT;")
69         query = "UPDATE suite SET commentsdir = %s WHERE suite_name = %s"  #: Update query
70         for suite in Cnf.SubTree("Suite").List():
71             commentsdir = Cnf.Find("Suite::%s::CommentsDir" % (suite))
72             print "[CommentsDir] Processing suite %s" % (suite)
73             if not commentsdir:
74                 continue
75             suite = suite.lower()
76             c.execute(query, [commentsdir, suite])
77
78         c.execute("ALTER TABLE suite ADD COLUMN overridesuite TEXT;")
79         query = "UPDATE suite SET overridesuite = %s WHERE suite_name = %s"  #: Update query
80         for suite in Cnf.SubTree("Suite").List():
81             overridesuite = Cnf.Find("Suite::%s::OverrideSuite" % (suite))
82             print "[OverrideSuite] Processing suite %s" % (suite)
83             if not overridesuite:
84                 continue
85             suite = suite.lower()
86             c.execute(query, [overridesuite, suite])
87
88         c.execute("ALTER TABLE suite ADD COLUMN changelogbase TEXT;")
89         query = "UPDATE suite SET changelogbase = %s WHERE suite_name = %s"  #: Update query
90         for suite in Cnf.SubTree("Suite").List():
91             changelogbase = Cnf.Find("Suite::%s::ChangeLogBase" % (suite))
92             print "[ChangeLogBase] Processing suite %s" % (suite)
93             if not changelogbase:
94                 continue
95             suite = suite.lower()
96             c.execute(query, [changelogbase, suite])
97
98         c.execute("UPDATE config SET value = '8' WHERE name = 'db_revision'")
99         self.db.commit()
100
101     except psycopg2.ProgrammingError, msg:
102         self.db.rollback()
103         raise DBUpdateError, "Unable to apply suite config updates, rollback issued. Error message : %s" % (str(msg))