From 64e380635d57e93eac6252026be3d8cb4ae044b3 Mon Sep 17 00:00:00 2001 From: Christophe Benz Date: Thu, 20 May 2010 16:26:29 +0200 Subject: [PATCH] display exceptions backtraces if debug mode enabled --- weboob/bcall.py | 7 +++++-- weboob/modules.py | 48 +++++++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/weboob/bcall.py b/weboob/bcall.py index 112ef300..88c13ab0 100644 --- a/weboob/bcall.py +++ b/weboob/bcall.py @@ -17,8 +17,9 @@ from __future__ import with_statement -from logging import debug from copy import copy +import logging +from logging import debug from threading import Thread, Event, RLock, Timer from .tools.misc import get_backtrace @@ -28,7 +29,9 @@ __all__ = ['BackendsCall', 'CallErrors'] class CallErrors(Exception): def __init__(self, errors): Exception.__init__(self, u'These errors have been raised in backend threads:\n%s' % ( - u'\n'.join((u' * %s: %s\n%s' % (backend, error, backtrace)) for backend, error, backtrace in errors))) + u'\n'.join((u' * %s: %s%s' % (backend, error, backtrace + '\n' + if logging.root.level == logging.DEBUG else '')) + for backend, error, backtrace in self.errors))) self.errors = copy(errors) def __iter__(self): diff --git a/weboob/modules.py b/weboob/modules.py index c0fc1b97..b761a4b1 100644 --- a/weboob/modules.py +++ b/weboob/modules.py @@ -1,30 +1,29 @@ # -*- coding: utf-8 -*- -""" -Copyright(C) 2010 Romain Bignon +# Copyright(C) 2010 Romain Bignon +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -""" from __future__ import with_statement -import re -import os -import stat from ConfigParser import SafeConfigParser -from logging import warning, debug +import logging +from logging import debug, error, exception, warning +import os +import re +import stat import weboob.backends from weboob.backend import BaseBackend @@ -146,8 +145,13 @@ class ModulesLoader(object): try: module = Module(name, __import__(name, fromlist=[str(name)])) except ImportError, e: - warning('Unable to load module "%s": %s' % (name, e)) - return + msg = 'Unable to load module "%s": %s' % (name, e) + if logging.root.level == logging.DEBUG: + exception(msg) + return + else: + error(msg) + return if name in self.modules: warning('Module "%s" is already loaded (%s)' % self.modules[name].module) return