#!/usr/bin/env python
-# Debian Archive Kit Database Update Script
-# Copyright (C) 2008 Michael Casadevall <mcasadevall@debian.org>
-# Copyright (C) 2009 Joerg Jaspert <joerg@debian.org>
+"""
+Remove unused versioncmp
+
+@contact: Debian FTP Master <ftpmaster@debian.org>
+@copyright: 2008 Michael Casadevall <mcasadevall@debian.org>
+@copyright: 2009 Joerg Jaspert <joerg@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
################################################################################
-import psycopg2, time
+import psycopg2
+import time
+from daklib.dak_exceptions import DBUpdateError
################################################################################
try:
c = self.db.cursor()
- c.execute("DROP FUNCTION versioncmp(text, text);")
+ # The reason we try and check to see if it exists is that
+ # psycopg2 might leave the cursor invalid if the drop fails
+ c.execute("SELECT proname from pg_catalog.pg_proc WHERE proname = 'versioncmp'")
+ rows = c.fetchall()
+ if rows:
+ c.execute("DROP FUNCTION versioncmp(text, text);")
+ else:
+ print "function already does not exist"
+
c.execute("UPDATE config SET value = '3' WHERE name = 'db_revision'")
self.db.commit()
except psycopg2.ProgrammingError, msg:
self.db.rollback()
- print "FATAL: Unable to apply db update 3!"
- print "Error Message: " + str(msg)
- print "Database changes have been rolled back."
+ raise DBUpdateError, "Unable to appy versioncmp removal, rollback issued. Error message : %s" % (str(msg))