* conifer/syrup/views/_common.py: added @postmortem decorator
authorgfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Thu, 6 May 2010 01:24:37 +0000 (01:24 +0000)
committergfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Thu, 6 May 2010 01:24:37 +0000 (01:24 +0000)
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
conifer/syrup/views/_common.py

index b634ce8..74f5041 100644 (file)
@@ -9,3 +9,5 @@ xsip
 TAGS
 private_local_settings.py
 /conifer/.dired
+/conifer/local_settings.py
+*~
\ No newline at end of file
index d54d89d..9a77e4d 100644 (file)
@@ -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