aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2010-01-12 05:04:04 +0000
committerRob Austein <sra@hactrn.net>2010-01-12 05:04:04 +0000
commitf6c9f9030dc2ff9df215768991283c25f7a6021c (patch)
tree7b3dcbbdb8993bd57db2ed3e1bfda088b50d6513
parent1da63d3c3d6d1baedfe38cb49cc1846097546d24 (diff)
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
-rw-r--r--myrpki/setup-sql.py20
1 files changed, 17 insertions, 3 deletions
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()