def is_database_correctly_configured():
import peewee
import config
configured = False
cannot_connect_message = "Cannot connect to database. Please ensure database service is running and user access is properly configured in 'sentinel.conf'."
try:
db = config.db
db.connect()
configured = True
except (peewee.ImproperlyConfigured, peewee.OperationalError, ImportError) as e:
print("[error]: %s" % e)
print(cannot_connect_message)
sys.exit(1)
return configured
python类ImproperlyConfigured()的实例源码
def is_database_correctly_configured():
import peewee
import config
configured = False
cannot_connect_message = "Cannot connect to database. Please ensure database service is running and user access is properly configured in 'sentinel.conf'."
try:
db = config.db
db.connect()
configured = True
except (peewee.ImproperlyConfigured, peewee.OperationalError, ImportError) as e:
print("[error]: %s" % e)
print(cannot_connect_message)
sys.exit(1)
return configured
def _connect(self, database, **kwargs):
if not PYSQLITE_BERKELEYDB:
message = ('Your Python SQLite driver (%s) does not appear to '
'have been compiled against the BerkeleyDB SQLite '
'library.' % berkeleydb)
if LIBSQLITE_BERKELEYDB:
message += (' However, the libsqlite on your system is the '
'BerkeleyDB implementation. Try recompiling '
'pysqlite.')
else:
message += (' Additionally, the libsqlite on your system '
'does not appear to be the BerkeleyDB '
'implementation.')
raise ImproperlyConfigured(message)
conn = berkeleydb.connect(database, **kwargs)
conn.isolation_level = None
self._add_conn_hooks(conn)
return conn
def _connect(self, database, **kwargs):
if not PYSQLITE_BERKELEYDB:
message = ('Your Python SQLite driver (%s) does not appear to '
'have been compiled against the BerkeleyDB SQLite '
'library.' % berkeleydb)
if LIBSQLITE_BERKELEYDB:
message += (' However, the libsqlite on your system is the '
'BerkeleyDB implementation. Try recompiling '
'pysqlite.')
else:
message += (' Additionally, the libsqlite on your system '
'does not appear to be the BerkeleyDB '
'implementation.')
raise ImproperlyConfigured(message)
conn = berkeleydb.connect(database, **kwargs)
conn.isolation_level = None
self._add_conn_hooks(conn)
return conn
def _connect(self, database, **kwargs):
if not PYSQLITE_BERKELEYDB:
message = ('Your Python SQLite driver (%s) does not appear to '
'have been compiled against the BerkeleyDB SQLite '
'library.' % berkeleydb)
if LIBSQLITE_BERKELEYDB:
message += (' However, the libsqlite on your system is the '
'BerkeleyDB implementation. Try recompiling '
'pysqlite.')
else:
message += (' Additionally, the libsqlite on your system '
'does not appear to be the BerkeleyDB '
'implementation.')
raise ImproperlyConfigured(message)
conn = berkeleydb.connect(database, **kwargs)
conn.isolation_level = None
self._add_conn_hooks(conn)
return conn
def _connect(self, database, **kwargs):
if not mysql:
raise ImproperlyConfigured('MySQLdb or PyMySQL must be installed.')
conn_kwargs = {
'charset': 'utf8',
'use_unicode': True,
}
conn_kwargs.update(kwargs)
return await aiomysql.create_pool(db=database, **conn_kwargs)