Convert two common plugin errors from unhandled exceptions to warnings.

Missing translation for the current primary locale.
Import failure because of some missing dependency.

Note that these handlers can be overridded in the module itself; this is just a fallback.

(cherry picked from commit 80c58f46d3b7b845e8506b8df6f4935e4d2ab90a)
This commit is contained in:
John Ralls 2014-03-07 16:20:24 -08:00
parent 05de040e82
commit 9766d81bb8

View File

@ -41,6 +41,9 @@ from __future__ import print_function
import os
import sys
import re
import logging
LOG = logging.getLogger('.' + __name__)
LOG.progagate = True
from ..const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
@ -250,7 +253,12 @@ class BasePluginManager(object):
if pdata.fpath not in sys.path:
if pdata.mod_name:
sys.path.insert(0, pdata.fpath)
module = __import__(pdata.mod_name)
try:
module = __import__(pdata.mod_name)
except ValueError as err:
LOG.warning('Plugin error: %s', err)
except ImportError as err:
LOG.warning('Plugin error: %s', err)
sys.path.pop(0)
else:
print("WARNING: module cannot be loaded")