]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update7.py
Merge branch 'master' into bugfixes
[dak.git] / dak / dakdb / update7.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 7
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 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 untouchable BOOLEAN NOT NULL DEFAULT FALSE;")
49         query = "UPDATE suite SET untouchable = TRUE WHERE suite_name = %s"  #: Update query
50         for suite in Cnf.SubTree("Suite").List():
51             untouchable = Cnf.Find("Suite::%s::Untouchable" % (suite))
52             if not untouchable:
53                 continue
54             print "[Untouchable] Processing suite %s" % (suite)
55             suite = suite.lower()
56             c.execute(query, [suite])
57
58
59         c.execute("ALTER TABLE suite ADD COLUMN announce text NOT NULL DEFAULT 'debian-devel-changes@lists.debian.org';")
60         query = "UPDATE suite SET announce = %s WHERE suite_name = %s"  #: Update query
61         for suite in Cnf.SubTree("Suite").List():
62             announce_list = Cnf.Find("Suite::%s::Announce" % (suite))
63             print "[Announce] Processing suite %s" % (suite)
64             suite = suite.lower()
65             c.execute(query, [announce_list, suite])
66
67         c.execute("ALTER TABLE suite ADD COLUMN codename text;")
68         query = "UPDATE suite SET codename = %s WHERE suite_name = %s"  #: Update query
69         for suite in Cnf.SubTree("Suite").List():
70             codename = Cnf.Find("Suite::%s::CodeName" % (suite))
71             print "[Codename] Processing suite %s" % (suite)
72             suite = suite.lower()
73             c.execute(query, [codename, suite])
74
75         c.execute("ALTER TABLE suite ADD COLUMN overridecodename text;")
76         query = "UPDATE suite SET overridecodename = %s WHERE suite_name = %s"  #: Update query
77         for suite in Cnf.SubTree("Suite").List():
78             codename = Cnf.Find("Suite::%s::OverrideCodeName" % (suite))
79             print "[OverrideCodeName] Processing suite %s" % (suite)
80             suite = suite.lower()
81             c.execute(query, [codename, suite])
82
83         c.execute("ALTER TABLE suite ADD COLUMN validtime integer NOT NULL DEFAULT 604800;")
84         query = "UPDATE suite SET validtime = %s WHERE suite_name = %s"  #: Update query
85         for suite in Cnf.SubTree("Suite").List():
86             validtime = Cnf.Find("Suite::%s::ValidTime" % (suite))
87             print "[ValidTime] Processing suite %s" % (suite)
88             if not validtime:
89                 validtime = 0
90             suite = suite.lower()
91             c.execute(query, [validtime, suite])
92
93         c.execute("ALTER TABLE suite ADD COLUMN priority integer NOT NULL DEFAULT 0;")
94         query = "UPDATE suite SET priority = %s WHERE suite_name = %s"  #: Update query
95         for suite in Cnf.SubTree("Suite").List():
96             priority = Cnf.Find("Suite::%s::Priority" % (suite))
97             print "[Priority] Processing suite %s" % (suite)
98             if not priority:
99                 priority = 0
100             suite = suite.lower()
101             c.execute(query, [priority, suite])
102
103
104         c.execute("ALTER TABLE suite ADD COLUMN notautomatic BOOLEAN NOT NULL DEFAULT FALSE;")
105         query = "UPDATE suite SET notautomatic = TRUE WHERE suite_name = %s"  #: Update query
106         for suite in Cnf.SubTree("Suite").List():
107             notautomatic = Cnf.Find("Suite::%s::NotAutomatic" % (suite))
108             print "[NotAutomatic] Processing suite %s" % (suite)
109             if not notautomatic:
110                 continue
111             suite = suite.lower()
112             c.execute(query, [suite])
113
114         c.execute("UPDATE config SET value = '7' WHERE name = 'db_revision'")
115         self.db.commit()
116
117     except psycopg2.ProgrammingError, msg:
118         self.db.rollback()
119         raise DBUpdateError, "Unable to appy suite config updates, rollback issued. Error message : %s" % (str(msg))