Allow to import backend from entry points

issue4841
review20301002
This commit is contained in:
Cédric Krier
2015-07-09 15:40:21 +02:00
parent 390aebef15
commit e4c8f59b80
2 changed files with 18 additions and 1 deletions
+1
View File
@@ -1,3 +1,4 @@
* Allow to import backend from entry points
* Add reversed operators to PYSON expressions
* Use CURRENT_TIMESTAMP instead of now
* Use Constraint instance in ModelSQL._sql_constraints
+17 -1
View File
@@ -2,6 +2,12 @@
# this repository contains the full copyright notices and license terms.
import sys
import urlparse
import os
import imp
try:
import pkg_resources
except ImportError:
pkg_resources = None
from trytond.config import config
@@ -15,6 +21,16 @@ def name():
def get(prop):
db_type = name()
modname = 'trytond.backend.%s' % db_type
__import__(modname)
if modname not in sys.modules:
try:
__import__(modname)
except ImportError:
if not pkg_resources:
raise
ep, = pkg_resources.iter_entry_points('trytond.backend', db_type)
mod_path = os.path.join(ep.dist.location,
*ep.module_name.split('.')[:-1])
fp, pathname, description = imp.find_module(db_type, [mod_path])
imp.load_module(modname, fp, pathname, description)
module = sys.modules[modname]
return getattr(module, prop)