[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master 02/29] Add list of allowed source formats in the database



* Add dak/dakdb/update15.py to update the database.
* Update required_database_schema to 15 in dak/update_db.py.
---
 dak/dakdb/update15.py |   75 +++++++++++++++++++++++++++++++++++++++++++++++++
 dak/update_db.py      |    2 +-
 2 files changed, 76 insertions(+), 1 deletions(-)
 create mode 100644 dak/dakdb/update15.py

diff --git a/dak/dakdb/update15.py b/dak/dakdb/update15.py
new file mode 100644
index 0000000..6cf86cc
--- /dev/null
+++ b/dak/dakdb/update15.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+# coding=utf8
+
+"""
+Adding table for allowed source formats
+
+@contact: Debian FTP Master <ftpmaster@debian.org>
+@copyright: 2009  Raphael Hertzog <hertzog@debian.org>
+@license: GNU General Public License version 2 or later
+"""
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+################################################################################
+
+
+################################################################################
+
+import psycopg2
+import time
+from daklib.dak_exceptions import DBUpdateError
+
+################################################################################
+
+def do_update(self):
+    print "Adding tables listing allowed source formats"
+
+    try:
+        c = self.db.cursor()
+        c.execute("""
+            CREATE TABLE src_format (
+                    id SERIAL PRIMARY KEY,
+                    format_name TEXT NOT NULL,
+                    unique (format_name)
+            )
+        """)
+        c.execute("INSERT INTO src_format (format_name) VALUES('1.0')")
+        c.execute("INSERT INTO src_format (format_name) VALUES('3.0 (quilt)')")
+        c.execute("INSERT INTO src_format (format_name) VALUES('3.0 (native)')")
+
+        c.execute("""
+            CREATE TABLE suite_src_formats (
+                    suite INT4 NOT NULL,
+                    src_format INT4 NOT NULL,
+                    unique (suite, src_format)
+            )
+        """)
+
+        print "Authorize all formats on all suites by default"
+        c.execute("SELECT id FROM suite")
+        suites = c.fetchall()
+        c.execute("SELECT id FROM src_format")
+        formats = c.fetchall()
+        for s in suites:
+            for f in formats:
+                c.execute("INSERT INTO suite_src_formats (suite, src_format) VALUES('%s', '%s')" % (s[0], f[0]))
+
+        c.execute("UPDATE config SET value = '15' WHERE name = 'db_revision'")
+        self.db.commit()
+
+    except psycopg2.ProgrammingError, msg:
+        self.db.rollback()
+        raise DBUpdateError, "Unable to apply source format update 15, rollback issued. Error message : %s" % (str(msg))
diff --git a/dak/update_db.py b/dak/update_db.py
index 4999af3..ecf5cd2 100755
--- a/dak/update_db.py
+++ b/dak/update_db.py
@@ -44,7 +44,7 @@ from daklib.dak_exceptions import DBUpdateError
 ################################################################################
 
 Cnf = None
-required_database_schema = 14
+required_database_schema = 15
 
 ################################################################################
 
-- 
1.6.3.3



Reply to: