Mercurial > libervia-backend
comparison sat/tools/common/dynamic_import.py @ 3290:3ff952c042ae
tools (common/dynamic_import): log a warning if bridge can't be imported
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 01 Jun 2020 11:14:20 +0200 |
parents | 559a625a236b |
children | be6d91572633 |
comparison
equal
deleted
inserted
replaced
3289:9057713ab124 | 3290:3ff952c042ae |
---|---|
1 #!/usr/bin/env python3 | 1 #!/usr/bin/env python3 |
2 | 2 |
3 | 3 # SàT: an XMPP client |
4 # SàT: a XMPP | |
5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) | 4 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) |
6 | 5 |
7 # This program is free software: you can redistribute it and/or modify | 6 # 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 | 7 # 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 | 8 # the Free Software Foundation, either version 3 of the License, or |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 18 |
20 """ tools dynamic import """ | 19 """ tools dynamic import """ |
21 | 20 |
22 from importlib import import_module | 21 from importlib import import_module |
22 from sat.core.log import getLogger | |
23 | |
24 | |
25 log = getLogger(__name__) | |
23 | 26 |
24 | 27 |
25 def bridge(name, module_path="sat.bridge"): | 28 def bridge(name, module_path="sat.bridge"): |
26 """Import bridge module | 29 """Import bridge module |
27 | 30 |
32 try: | 35 try: |
33 bridge_module = import_module(module_path + "." + name) | 36 bridge_module = import_module(module_path + "." + name) |
34 except ImportError: | 37 except ImportError: |
35 try: | 38 try: |
36 bridge_module = import_module(module_path + "." + name + "_bridge") | 39 bridge_module = import_module(module_path + "." + name + "_bridge") |
37 except ImportError: | 40 except ImportError as e: |
41 log.warning(f"Can't import bridge {name!r}: {e}") | |
38 bridge_module = None | 42 bridge_module = None |
39 return bridge_module | 43 return bridge_module |