]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update20.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / dakdb / update20.py
1 #!/usr/bin/env python
2 # coding=utf8
3
4 """
5 Add policy queue handling support
6
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2009  Mark Hymers <mhy@debian.org>
9 @license: GNU General Public License version 2 or later
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
29 ################################################################################
30
31 import psycopg2
32 import time
33 import os
34 import datetime
35 import traceback
36
37 from daklib.dak_exceptions import DBUpdateError
38 from daklib.config import Config
39
40 ################################################################################
41
42 def do_update(self):
43     print "Updating use of queue table"
44
45     try:
46         c = self.db.cursor()
47
48         cnf = Config()
49
50         print "Adding path to queue table"
51         c.execute("ALTER TABLE queue ADD COLUMN path TEXT")
52         c.execute("SELECT * FROM queue")
53         rows = c.fetchall()
54         seenqueues = {}
55         for row in rows:
56             dir = cnf["Dir::Queue::%s" % row[1]].rstrip('/')
57             seenqueues[row[1].lower()] = 1
58             print "Setting %s queue to use path %s" % (row[1], dir)
59             c.execute("UPDATE queue SET path = %s WHERE id = %s", (dir, row[0]))
60
61         print "Adding missing queues to the queue table"
62         for q in cnf.SubTree("Dir::Queue").keys():
63             qname = q.lower()
64             if qname in seenqueues.keys():
65                 continue
66             if qname in ["done", "holding", "reject", "newstage", "btsversiontrack"]:
67                 print "Skipping queue %s" % qname
68                 continue
69             pth = cnf["Dir::Queue::%s" % qname].rstrip('/')
70             if not os.path.exists(pth):
71                 print "Skipping %s as %s does not exist" % (qname, pth)
72                 continue
73
74             print "Adding %s queue with path %s" % (qname, pth)
75             c.execute("INSERT INTO queue (queue_name, path) VALUES (%s, %s)", (qname, pth))
76             seenqueues[qname] = 1
77
78         print "Adding queue and approved_for columns to known_changes"
79         c.execute("ALTER TABLE known_changes ADD COLUMN in_queue INT4 REFERENCES queue(id) DEFAULT NULL")
80         c.execute("ALTER TABLE known_changes ADD COLUMN approved_for INT4 REFERENCES queue(id) DEFAULT NULL")
81
82         print "Adding policy queue column to suite table"
83         c.execute("ALTER TABLE suite DROP COLUMN policy_engine")
84         c.execute("ALTER TABLE suite ADD COLUMN policy_queue_id INT4 REFERENCES queue(id) DEFAULT NULL")
85         # Handle some of our common cases automatically
86         if seenqueues.has_key('proposedupdates'):
87             c.execute("""UPDATE suite SET policy_queue_id = (SELECT id FROM queue WHERE queue_name = 'proposedupdates')
88                                       WHERE suite_name = 'proposed-updates'""")
89
90         if seenqueues.has_key('oldproposedupdates'):
91             c.execute("""UPDATE suite SET policy_queue_id = (SELECT id FROM queue WHERE queue_name = 'oldproposedupdates')
92                                       WHERE suite_name = 'oldstable-proposed-updates'""")
93
94         print "Committing"
95         c.execute("UPDATE config SET value = '20' WHERE name = 'db_revision'")
96         self.db.commit()
97
98     except psycopg2.InternalError as msg:
99         self.db.rollback()
100         raise DBUpdateError, "Unable to apply debversion update 20, rollback issued. Error message : %s" % (str(msg))