2016-01-18 14:48:14 +00:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
|
|
|
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
|
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
2015-10-20 07:03:18 +00:00
|
|
|
from flask import current_app
|
2016-06-21 13:12:14 +00:00
|
|
|
|
2015-10-20 07:03:18 +00:00
|
|
|
from .registry import DriverRegistry
|
|
|
|
|
|
|
|
|
2016-01-02 09:24:01 +00:00
|
|
|
def get_driver(type, app=None):
|
|
|
|
|
|
|
|
if app is not None:
|
|
|
|
DriverRegistry.load_drivers()
|
|
|
|
|
|
|
|
drivers = getattr(app or current_app, '_pgadmin_server_drivers', None)
|
2015-10-20 07:03:18 +00:00
|
|
|
|
|
|
|
if drivers is None or not isinstance(drivers, dict):
|
|
|
|
drivers = dict()
|
|
|
|
|
|
|
|
if type in drivers:
|
|
|
|
return drivers[type]
|
|
|
|
|
|
|
|
driver = DriverRegistry.create(type)
|
|
|
|
|
|
|
|
if driver is not None:
|
|
|
|
drivers[type] = driver
|
2016-01-02 09:24:01 +00:00
|
|
|
setattr(app or current_app, '_pgadmin_server_drivers', drivers)
|
2015-10-20 07:03:18 +00:00
|
|
|
|
|
|
|
return driver
|
|
|
|
|
|
|
|
def init_app(app):
|
|
|
|
drivers = dict()
|
|
|
|
|
|
|
|
setattr(app, '_pgadmin_server_drivers', drivers)
|
|
|
|
DriverRegistry.load_drivers()
|
|
|
|
|
2016-01-02 09:24:01 +00:00
|
|
|
return drivers
|
|
|
|
|
2015-10-20 07:03:18 +00:00
|
|
|
|
|
|
|
def ping():
|
|
|
|
drivers = getattr(current_app, '_pgadmin_server_drivers', None)
|
|
|
|
|
|
|
|
for type in drivers:
|
|
|
|
drivers[type].gc()
|