comparison 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
comparison
equal deleted inserted replaced
2161:62dfa6e02f54 2162:c9a67eb5bf72
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 21
22 ### logging ### 22 ### logging ###
23 import logging as log 23 import logging as log
24 log.basicConfig(level=log.DEBUG, 24 log.basicConfig(level=log.DEBUG,
25 format='%(message)s') 25 format='%(message)s')
26 ### 26 ###
27 27
28 import sys 28 import sys
29 import locale 29 import locale
30 import os.path 30 import os.path
110 shlex.split = new_split 110 shlex.split = new_split
111 111
112 try: 112 try:
113 import progressbar 113 import progressbar
114 except ImportError: 114 except ImportError:
115 log.info (_(u'ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar')) 115 log.warning(_(u'ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar'))
116 log.info (_(u'Progress bar deactivated\n--\n')) 116 log.warning(_(u'Progress bar deactivated\n--\n'))
117 progressbar=None 117 progressbar=None
118 118
119 #consts 119 #consts
120 PROG_NAME = u"jp" 120 PROG_NAME = u"jp"
121 DESCRIPTION = """This software is a command line tool for XMPP. 121 DESCRIPTION = """This software is a command line tool for XMPP.
326 path = os.path.dirname(sat_frontends.jp.__file__) 326 path = os.path.dirname(sat_frontends.jp.__file__)
327 # XXX: outputs must be imported before commands as they are used for arguments 327 # XXX: outputs must be imported before commands as they are used for arguments
328 for type_, pattern in ((C.PLUGIN_OUTPUT, 'output_*.py'), (C.PLUGIN_CMD, 'cmd_*.py')): 328 for type_, pattern in ((C.PLUGIN_OUTPUT, 'output_*.py'), (C.PLUGIN_CMD, 'cmd_*.py')):
329 modules = (os.path.splitext(module)[0] for module in map(os.path.basename, iglob(os.path.join(path, pattern)))) 329 modules = (os.path.splitext(module)[0] for module in map(os.path.basename, iglob(os.path.join(path, pattern))))
330 for module_name in modules: 330 for module_name in modules:
331 module = import_module("sat_frontends.jp."+module_name) 331 module_path = "sat_frontends.jp." + module_name
332 try: 332 try:
333 module = import_module(module_path)
333 self.import_plugin_module(module, type_) 334 self.import_plugin_module(module, type_)
334 except ImportError: 335 except ImportError:
336 log.warning(_(u"Can't import {} plugin, ignoring it".format(module_path)))
337 except exceptions.CancelError:
335 continue 338 continue
339 except exceptions.MissingModule as e:
340 log.warning(_(u"Missing module for plugin {name}: {missing}".format(
341 name = module_path,
342 missing = e)))
343
336 344
337 def import_plugin_module(self, module, type_): 345 def import_plugin_module(self, module, type_):
338 """add commands or outpus from a module to jp 346 """add commands or outpus from a module to jp
339 347
340 @param module: module containing commands or outputs 348 @param module: module containing commands or outputs