diff options
-rw-r--r-- | tutorius/addon.py | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/tutorius/addon.py b/tutorius/addon.py index 6e3d8b9..18d225a 100644 --- a/tutorius/addon.py +++ b/tutorius/addon.py @@ -35,6 +35,10 @@ __action__ = { import os import re import logging +import sys +import traceback + +LOGGER = logging.getLogger('sugar.tutorius.addon') PREFIX = __name__+"s" PATH = re.sub("addon\\.py[c]$", "", __file__)+"addons" @@ -48,14 +52,23 @@ def _reload_addons(): global _cache _cache = {} for addon in filter(lambda x: x.endswith("py"), os.listdir(PATH)): - mod = __import__(PREFIX+'.'+re.sub("\\.py$", "", addon), {}, {}, [""]) - if hasattr(mod, "__action__"): - _cache[mod.__action__['name']] = mod.__action__ - mod.__action__['type'] = TYPE_ACTION - continue - if hasattr(mod, "__event__"): - _cache[mod.__event__['name']] = mod.__event__ - mod.__event__['type'] = TYPE_EVENT + + try: + mod_name = PREFIX+'.'+re.sub("\\.py$", "", addon) + mod = __import__(mod_name, {}, {}, [""]) + if hasattr(mod, "__action__"): + _cache[mod.__action__['name']] = mod.__action__ + mod.__action__['type'] = TYPE_ACTION + continue + if hasattr(mod, "__event__"): + _cache[mod.__event__['name']] = mod.__event__ + mod.__event__['type'] = TYPE_EVENT + except: + # fetch frame information to complement exception with traceback + type, value, tb = sys.exc_info() + formatted_tb = traceback.format_tb(tb) + LOGGER.error('Error loadin tutorius add-on [%s]:\n%s' % \ + (mod_name, '\n'.join(formatted_tb))) def create(name, *args, **kwargs): global _cache |