From f6c9f9030dc2ff9df215768991283c25f7a6021c Mon Sep 17 00:00:00 2001
From: Rob Austein <sra@hactrn.net>
Date: Tue, 12 Jan 2010 05:04:04 +0000
Subject: Suppress deprecation warnings when loading MySQLdb in Python 2.6;
 suppress gratuitous failure when dropping database that doesn't exist.

svn path=/myrpki/setup-sql.py; revision=2939
---
 myrpki/setup-sql.py | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

(limited to 'myrpki/setup-sql.py')

diff --git a/myrpki/setup-sql.py b/myrpki/setup-sql.py
index d64c81d5..638404d9 100644
--- a/myrpki/setup-sql.py
+++ b/myrpki/setup-sql.py
@@ -19,8 +19,19 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 PERFORMANCE OF THIS SOFTWARE.
 """
 
-import os, getopt, sys, time, rpki.config, getpass
-import MySQLdb,  warnings, _mysql_exceptions
+from __future__ import with_statement
+
+import os, getopt, sys, time, rpki.config, getpass, warnings
+
+# Silence warning while loading MySQLdb in Python 2.6, sigh
+if hasattr(warnings, "catch_warnings"):
+  with warnings.catch_warnings():
+    warnings.simplefilter("ignore", DeprecationWarning)
+    import MySQLdb
+else:
+  import MySQLdb
+
+import _mysql_exceptions
 
 warnings.simplefilter("error", _mysql_exceptions.Warning)
 
@@ -50,7 +61,10 @@ def sql_setup(name):
 
   print "Creating database", database
   cur = rootdb.cursor()
-  cur.execute("DROP DATABASE IF EXISTS %s" %  database)
+  try:
+    cur.execute("DROP DATABASE IF EXISTS %s" %  database)
+  except:
+    pass
   cur.execute("CREATE DATABASE %s" % database)
   cur.execute("GRANT ALL ON %s.* TO %s@localhost IDENTIFIED BY %%s" % (database, username), (password,))
   rootdb.commit()
-- 
cgit v1.2.3