use module imp instead of __import__
This commit is contained in:
parent
681c97440d
commit
aa0084a37d
1 changed files with 12 additions and 9 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import imp
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
@ -132,18 +133,20 @@ class ModulesLoader(object):
|
||||||
raise ModuleLoadError(module_name, 'Module is not installed')
|
raise ModuleLoadError(module_name, 'Module is not installed')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sys.path.append(minfo.path)
|
fp, pathname, description = imp.find_module(module_name, [minfo.path])
|
||||||
try:
|
try:
|
||||||
module = Module(__import__(module_name, fromlist=[str(module_name)]))
|
module = Module(imp.load_module(module_name, fp, pathname, description))
|
||||||
except Exception, e:
|
finally:
|
||||||
if logging.root.level == logging.DEBUG:
|
if fp:
|
||||||
self.logger.exception(e)
|
fp.close()
|
||||||
raise ModuleLoadError(module_name, e)
|
except Exception, e:
|
||||||
finally:
|
if logging.root.level == logging.DEBUG:
|
||||||
sys.path.remove(minfo.path)
|
self.logger.exception(e)
|
||||||
|
raise ModuleLoadError(module_name, e)
|
||||||
|
|
||||||
if module.version != self.repositories.version:
|
if module.version != self.repositories.version:
|
||||||
raise ModuleLoadError(module_name, "Module requires Weboob %s, but you use Weboob %s" % (module.version, self.repositories.version))
|
raise ModuleLoadError(module_name, "Module requires Weboob %s, but you use Weboob %s. Hint: use 'weboob-config update'"
|
||||||
|
% (module.version, self.repositories.version))
|
||||||
|
|
||||||
self.loaded[module_name] = module
|
self.loaded[module_name] = module
|
||||||
self.logger.debug('Loaded module "%s" from %s' % (module_name, module.package.__path__[0]))
|
self.logger.debug('Loaded module "%s" from %s' % (module_name, module.package.__path__[0]))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue