jp (base): improved module import:

module import now display a warning were suitable on import issue
This commit is contained in:
Goffi 2017-02-21 21:01:40 +01:00
commit c4c57e7d42

View file

@ -22,7 +22,7 @@ from sat.core.i18n import _
### logging ###
import logging as log
log.basicConfig(level=log.DEBUG,
format='%(message)s')
format='%(message)s')
###
import sys
@ -112,8 +112,8 @@ if sys.version_info < (2, 7, 3):
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 @@ class Jp(object):
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