[SCM] morituri/master: * task.py: Pull in getExceptionMessage privately.

js at users.alioth.debian.org js at users.alioth.debian.org
Sun Oct 19 20:09:33 UTC 2014


The following commit has been merged in the master branch:
commit bc62f92ce4657ea08df2fa19d112a80c1af213e5
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date:   Mon Aug 8 11:35:35 2011 +0000

    	* task.py:
    	  Pull in getExceptionMessage privately.

diff --git a/morituri/extern/task/ChangeLog b/morituri/extern/task/ChangeLog
index d1ce6ce..d5f8ba2 100644
--- a/morituri/extern/task/ChangeLog
+++ b/morituri/extern/task/ChangeLog
@@ -1,3 +1,8 @@
+2011-08-08  Thomas Vander Stichele  <thomas at apestaart dot org>
+
+	* task.py:
+	  Pull in getExceptionMessage privately.
+
 2011-08-05  Thomas Vander Stichele  <thomas at apestaart dot org>
 
 	* gstreamer.py:
diff --git a/morituri/extern/task/task.py b/morituri/extern/task/task.py
index b0bf6f2..1d012f9 100644
--- a/morituri/extern/task/task.py
+++ b/morituri/extern/task/task.py
@@ -36,6 +36,36 @@ class TaskException(Exception):
         self.exceptionMessage = message
         self.args = (exception, message, )
 
+# lifted from flumotion log module
+def _getExceptionMessage(exception, frame=-1, filename=None):
+    """
+    Return a short message based on an exception, useful for debugging.
+    Tries to find where the exception was triggered.
+    """
+    import traceback
+
+    stack = traceback.extract_tb(sys.exc_info()[2])
+    if filename:
+        stack = [f for f in stack if f[0].find(filename) > -1]
+
+    # badly raised exceptions can come without a stack
+    if stack:
+        (filename, line, func, text) = stack[frame]
+    else:
+        (filename, line, func, text) = ('no stack', 0, 'none', '')
+
+    filename = scrubFilename(filename)
+    exc = exception.__class__.__name__
+    msg = ""
+    # a shortcut to extract a useful message out of most exceptions
+    # for now
+    if str(exception):
+        msg = ": %s" % str(exception)
+    return "exception %(exc)s at %(filename)s:%(line)s: %(func)s()%(msg)s" \
+        % locals()
+
+
+
 class Task(object):
     """
     I wrap a task in an asynchronous interface.
@@ -170,7 +200,7 @@ class Task(object):
         import traceback
 
         self.exception = exception
-        self.exceptionMessage = log.getExceptionMessage(exception)
+        self.exceptionMessage = _getExceptionMessage(exception)
         self.exceptionTraceback = traceback.format_exc()
         self.debug('set exception, %r, %r' % (
             exception, self.exceptionMessage))

-- 
morituri packaging



More information about the pkg-multimedia-commits mailing list