Files
tryton/trytond/backend/__init__.py
T
2019-11-25 14:50:33 +01:00

39 lines
985 B
Python

# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import importlib
import sys
import urllib.parse
try:
import pkg_resources
except ImportError:
pkg_resources = None
from trytond.config import config
__all__ = ['name', 'get']
_database_uri = config.get('database', 'uri', default='')
def name():
return urllib.parse.urlparse(_database_uri).scheme
def get(prop):
db_type = name()
modname = 'trytond.backend.%s' % db_type
try:
module = importlib.import_module(modname)
except ImportError:
if not pkg_resources:
raise
for ep in pkg_resources.iter_entry_points(
'trytond.backend', db_type):
try:
sys.modules[modname] = module = ep.load()
break
except ImportError:
continue
else:
raise
return getattr(module, prop)