comparison src/tools/common/dynamic_import.py @ 2088:c02f96756d5c

core: bridge can now be changed in conf by default DBus bridge is used, but this can be changed in sat.conf's DEFAULT section using "bridge" option. bridge can be "dbus" (or equivalent "dbus_bridge") or embedded at the moment. Bridge name used is saved in SAT.bridge_name, and load_bridge method can be used by frontends.
author Goffi <goffi@goffi.org>
date Sun, 04 Dec 2016 18:16:37 +0100
parents
children 8b37a62336c3
comparison
equal deleted inserted replaced
2087:159250d66407 2088:c02f96756d5c
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3
4 # SàT: a XMPP
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 """ tools dynamic import """
21
22 from importlib import import_module
23
24
25 def bridge(name, module_path='sat.bridge'):
26 """Import bridge module
27
28 @param module_path(str): path of the module to import
29 @param name(str): name of the bridge to import (e.g.: dbus)
30 @return (module, None): imported module or None if nothing is found
31 """
32 try:
33 bridge_module = import_module(module_path + '.' + name)
34 except ImportError:
35 try:
36 bridge_module = import_module(module_path + '.' + name + '_bridge')
37 except ImportError:
38 bridge_module = None
39 return bridge_module