Gracefully disable the mysql module if MySQLdb isn't available

This commit is contained in:
Jeff Schroeder 2012-03-17 09:21:40 -07:00
parent feed585380
commit a5631f9a65

View File

@ -14,11 +14,17 @@ might look like::
You can also use a defaults file::
mysql.default_file: '/etc/mysql/debian.cnf'
Required python modules: MySQLdb
'''
import logging
try:
import MySQLdb
import MySQLdb.cursors
has_mysqldb = True
except ImportError:
has_mysqldb = True
log = logging.getLogger(__name__)
__opts__ = {}
@ -28,6 +34,7 @@ def __virtual__():
Only load this module if the mysql config is set
'''
if any(k.startswith('mysql.') for k in __opts__.keys()):
if has_mysqldb:
return 'mysql'
return False