diff frontends/src/jp/base.py @ 2162:c9a67eb5bf72

jp (base): improved module import: module import now display a warning were suitable on import issue
author Goffi <goffi@goffi.org>
date Tue, 21 Feb 2017 21:01:40 +0100
parents 62dfa6e02f54
children 255830fdb80b
line wrap: on
line diff
--- a/frontends/src/jp/base.py	Tue Feb 21 21:01:40 2017 +0100
+++ b/frontends/src/jp/base.py	Tue Feb 21 21:01:40 2017 +0100
@@ -22,7 +22,7 @@
 ### logging ###
 import logging as log
 log.basicConfig(level=log.DEBUG,
-                    format='%(message)s')
+                format='%(message)s')
 ###
 
 import sys
@@ -112,8 +112,8 @@
 try:
     import progressbar
 except ImportError:
-    log.info (_(u'ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar'))
-    log.info (_(u'Progress bar deactivated\n--\n'))
+    log.warning(_(u'ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar'))
+    log.warning(_(u'Progress bar deactivated\n--\n'))
     progressbar=None
 
 #consts
@@ -328,11 +328,19 @@
         for type_, pattern in ((C.PLUGIN_OUTPUT, 'output_*.py'), (C.PLUGIN_CMD, 'cmd_*.py')):
             modules = (os.path.splitext(module)[0] for module in map(os.path.basename, iglob(os.path.join(path, pattern))))
             for module_name in modules:
-                module = import_module("sat_frontends.jp."+module_name)
+                module_path = "sat_frontends.jp." + module_name
                 try:
+                    module = import_module(module_path)
                     self.import_plugin_module(module, type_)
                 except ImportError:
+                    log.warning(_(u"Can't import {} plugin, ignoring it".format(module_path)))
+                except exceptions.CancelError:
                     continue
+                except exceptions.MissingModule as e:
+                    log.warning(_(u"Missing module for plugin {name}: {missing}".format(
+                        name = module_path,
+                        missing = e)))
+
 
     def import_plugin_module(self, module, type_):
         """add commands or outpus from a module to jp