pgadmin4/web/pgadmin/utils/driver/__init__.py

50 lines
1.1 KiB
Python
Raw Normal View History

2016-01-18 08:48:14 -06:00
##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
2018-01-05 04:42:49 -06:00
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
2016-01-18 08:48:14 -06:00
# This software is released under the PostgreSQL Licence
#
##########################################################################
from flask import current_app
2016-06-21 08:12:14 -05:00
from .registry import DriverRegistry
def get_driver(type, app=None):
if app is not None:
DriverRegistry.load_drivers()
drivers = getattr(app or current_app, '_pgadmin_server_drivers', None)
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
setattr(app or current_app, '_pgadmin_server_drivers', drivers)
return driver
2016-06-21 08:21:06 -05:00
def init_app(app):
drivers = dict()
setattr(app, '_pgadmin_server_drivers', drivers)
DriverRegistry.load_drivers()
return drivers
def ping():
drivers = getattr(current_app, '_pgadmin_server_drivers', None)
for type in drivers:
drivers[type].gc()