aboutsummaryrefslogtreecommitdiff
path: root/rpkid
diff options
context:
space:
mode:
Diffstat (limited to 'rpkid')
-rw-r--r--rpkid/rpki-sql-setup.py14
-rw-r--r--rpkid/rpki/irdbd.py10
-rw-r--r--rpkid/rpki/myrpki.py9
-rw-r--r--rpkid/rpki/mysql_import.py61
-rw-r--r--rpkid/rpki/sql.py19
-rw-r--r--rpkid/tests/smoketest.py10
6 files changed, 66 insertions, 57 deletions
diff --git a/rpkid/rpki-sql-setup.py b/rpkid/rpki-sql-setup.py
index dc463620..a7fb2d25 100644
--- a/rpkid/rpki-sql-setup.py
+++ b/rpkid/rpki-sql-setup.py
@@ -19,21 +19,9 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
"""
-from __future__ import with_statement
-
import os, getopt, sys, 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)
+from rpki.mysql_import import MySQLdb
schema_dir = os.path.normpath(sys.path[0])
diff --git a/rpkid/rpki/irdbd.py b/rpkid/rpki/irdbd.py
index 46d4ebe1..d092d810 100644
--- a/rpkid/rpki/irdbd.py
+++ b/rpkid/rpki/irdbd.py
@@ -34,19 +34,11 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
"""
-from __future__ import with_statement
-
import sys, os, time, getopt, urlparse, warnings
import rpki.http, rpki.config, rpki.resource_set, rpki.relaxng
import rpki.exceptions, rpki.left_right, rpki.log, rpki.x509
-# 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
+from rpki.mysql_import import MySQLdb
class main(object):
diff --git a/rpkid/rpki/myrpki.py b/rpkid/rpki/myrpki.py
index 6f23f7c6..2cd2a318 100644
--- a/rpkid/rpki/myrpki.py
+++ b/rpkid/rpki/myrpki.py
@@ -53,8 +53,6 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
"""
-from __future__ import with_statement
-
import subprocess, csv, re, os, getopt, sys, base64, time, glob, copy, warnings
import rpki.config, rpki.cli, rpki.sundial, rpki.log, rpki.oids
@@ -899,12 +897,7 @@ class IRDB(object):
information from a rpki.config.parser object.
"""
- if hasattr(warnings, "catch_warnings"):
- with warnings.catch_warnings():
- warnings.simplefilter("ignore", DeprecationWarning)
- import MySQLdb
- else:
- import MySQLdb
+ from rpki.mysql_import import MySQLdb
irdbd_cfg = rpki.config.parser(cfg.get("irdbd_conf", cfg.filename), "irdbd")
diff --git a/rpkid/rpki/mysql_import.py b/rpkid/rpki/mysql_import.py
new file mode 100644
index 00000000..ac2b580d
--- /dev/null
+++ b/rpkid/rpki/mysql_import.py
@@ -0,0 +1,61 @@
+"""
+Import wrapper for MySQLdb.
+
+MySQLdb is an independent package, not part of Python, and has some
+minor version skew issues with respect to Python itself, which we want
+to suppress so that they don't annoy the user. None of this is
+particularly hard, but the maze of whacky incantations required to do
+this in multiple version of Python on multiple platforms is somewhat
+tedious, and turns out to cause other problems when combined with the
+way we construct executable Python scripts containing a standard
+header indicating the location of our config file.
+
+So it turns out to be easier just to put all of the import voodoo
+here, and have other modules that need MySQLdb import the MySQL module
+object from this module. Looks kind of strange, but seems to work.
+
+$Id$
+
+Copyright (C) 2011 Internet Systems Consortium ("ISC")
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS. IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT,
+INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+"""
+
+from __future__ import with_statement
+
+import warnings
+
+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)
diff --git a/rpkid/rpki/sql.py b/rpkid/rpki/sql.py
index b7acf562..b6be65b6 100644
--- a/rpkid/rpki/sql.py
+++ b/rpkid/rpki/sql.py
@@ -32,19 +32,8 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
"""
-from __future__ import with_statement
+from rpki.mysql_import import (MySQLdb, _mysql_exceptions)
-import 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
import rpki.x509, rpki.resource_set, rpki.sundial, rpki.log
class session(object):
@@ -52,14 +41,8 @@ class session(object):
SQL session layer.
"""
- _exceptions_enabled = False
-
def __init__(self, cfg):
- if not self._exceptions_enabled:
- warnings.simplefilter("error", _mysql_exceptions.Warning)
- self.__class__._exceptions_enabled = True
-
self.username = cfg.get("sql-username")
self.database = cfg.get("sql-database")
self.password = cfg.get("sql-password")
diff --git a/rpkid/tests/smoketest.py b/rpkid/tests/smoketest.py
index 38e0d110..7ee6f4af 100644
--- a/rpkid/tests/smoketest.py
+++ b/rpkid/tests/smoketest.py
@@ -46,19 +46,11 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
"""
-from __future__ import with_statement
-
import os, yaml, warnings, subprocess, signal, time, getopt, sys
import rpki.resource_set, rpki.sundial, rpki.x509, rpki.http
import rpki.log, rpki.left_right, rpki.config, rpki.publication, rpki.async
-# 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
+from rpki.mysql_import import MySQLdb
os.environ["TZ"] = "UTC"
time.tzset()