From 8b8699fffbbf8cb64861781f1da47f91b49a032a Mon Sep 17 00:00:00 2001 From: gfawcett Date: Thu, 6 May 2010 01:24:37 +0000 Subject: [PATCH] * conifer/syrup/views/_common.py: added @postmortem decorator When settings.DEBUG == True, a function decorated with @postmortem will drop the Python process into the interactive postmortem debugger if an uncaught exception is raised. (See the 'pdb' stdlib module for details.) git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@883 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- .gitignore | 2 ++ conifer/syrup/views/_common.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/.gitignore b/.gitignore index b634ce8..74f5041 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ xsip TAGS private_local_settings.py /conifer/.dired +/conifer/local_settings.py +*~ \ No newline at end of file diff --git a/conifer/syrup/views/_common.py b/conifer/syrup/views/_common.py index d54d89d..9a77e4d 100644 --- a/conifer/syrup/views/_common.py +++ b/conifer/syrup/views/_common.py @@ -1,6 +1,7 @@ import warnings from conifer.syrup import models from datetime import datetime +import django.conf from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User, SiteProfileNotAvailable @@ -23,6 +24,7 @@ from conifer.libsystems.z3950.marcxml import marcxml_to_dictionary, marcxml_dict from conifer.syrup.fuzzy_match import rank_pending_items from django.core.urlresolvers import reverse from conifer.here import HERE +import pdb #----------------------------------------------------------------------------- # Z39.50 Support @@ -224,3 +226,19 @@ def user_filters(user): 'instructors': (Q(member__course__access__in=('LOGIN','ANON')) | Q(member__course__member__user=user)), } return filters + +#------------------------------------------------------------ + +# decorator +def postmortem(func): + """Drop into a debugger if an error occurs in the decoratee.""" + def inner(*args, **kwargs): + try: + return func(*args, **kwargs) + except Exception, e: + print '!!!!!!', e + pdb.post_mortem() + if django.conf.settings.DEBUG: + return inner + else: + return func -- 2.11.0