diff src/core/sat_main.py @ 1145:4e1a0a1523f1

core: more robust plugins importation
author Goffi <goffi@goffi.org>
date Mon, 01 Sep 2014 11:05:27 +0200
parents adea30ca0b51
children 8cdb97e89d9b
line wrap: on
line diff
--- a/src/core/sat_main.py	Wed Aug 27 01:27:24 2014 +0200
+++ b/src/core/sat_main.py	Mon Sep 01 11:05:27 2014 +0200
@@ -130,6 +130,7 @@
         ui_contact_list.ContactList(self)
         ui_profile_manager.ProfileManager(self)
         self._initialised.callback(None)
+        log.info(_("Backend is ready"))
 
     def _import_plugins(self):
         """Import all plugins found in plugins directory"""
@@ -139,7 +140,11 @@
         __plugins_to_import = {}  # plugins we still have to import
         for plug in plug_lst:
             plugin_path = 'sat.plugins.' + plug
-            __import__(plugin_path)
+            try:
+                __import__(plugin_path)
+            except ImportError as e:
+                log.error(_("Can't import plugin [%(path)s]: %(error)s") % {'path': plugin_path, 'error':e})
+                continue
             mod = sys.modules[plugin_path]
             plugin_info = mod.PLUGIN_INFO
             __plugins_to_import[plugin_info['import_name']] = (plugin_path, mod, plugin_info)
@@ -173,7 +178,11 @@
         for to_import in dependencies + recommendations:
             if to_import not in self.plugins:
                 log.debug('Recursively import dependency of [%s]: [%s]' % (import_name, to_import))
-                self._import_plugins_from_dict(plugins_to_import, to_import, to_import not in dependencies)
+                try:
+                    self._import_plugins_from_dict(plugins_to_import, to_import, to_import not in dependencies)
+                except ImportError as e:
+                    log.error(_("Can't import plugin %(name)s: %(error)s") % {'name':plugin_info['name'], 'error':e})
+                    return
         log.info(_("importing plugin: %s") % plugin_info['name'])
         self.plugins[import_name] = getattr(mod, plugin_info['main'])(self)
         if 'handler' in plugin_info and plugin_info['handler'] == 'yes':