Commits

jayven  committed 1b787fa

Start to add pretty_tb

  • Participants
  • Parent commits 44b7919
  • Branches add_traceback_html

Comments (0)

Files changed (3)

     if e > len(lines):
         e = len(lines)
 
-    return line, [(ln, l) for ln, line in izip(
+    return line, [(ln, l) for ln, l in izip(
         xrange(b + 1, e + 1), islice(lines, b, e))]
 
 
         for depth, filename, where, lineno, line, lines, local in \
                 codebase.iter_tracback(tb, lines_around):
 
-            w = len(str(lines[-1][0]))
-            lines = ''.join(("%*d%s %s" % (w, ln, 
-                (ln == lineno) and '>' or '.', l) for ln, l in lines))
+            if lines:
+                w = len(str(lines[-1][0]))
+                lines = ''.join(("%*d. %s" % (w, ln) for ln, l in lines))
+            else:
+                lines = ''
 
             tb_id = self.tb_obj.create(cr, uid, {'console': id,
                 'depth': depth,

File pretty_tb.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# vim: set ai et si ts=4 sts=4 sw=4:
+
+import codebase
+
+
+def pretty_tb(exc_type, exc_value, exc_tb):
+    res = []
+    res.append('<h1>%s</h1>' % exc_type)
+    res.append('<h2>%s</h2>' % exc_value)
+    res.append('<h2>Tracebacks</h2>')
+    res.append('<ul class="traceback">')
+
+    tb = exc_tb.tb_next # skip the first one
+    
+    for depth, filename, where, lineno, line, lines, local in \
+            codebase.iter_tracback(tb, 7):
+        res.append('<li class="tb">')
+        res.append('<code>%s</code> in <code>%s</code>' % (filename, where))
+        if lines:
+            res.append('<ol start="%d">' % lines[0][0])
+            for l in lines:
+                res.append('<li><code>%s</code></li>' % l[1])
+        else:
+            pass
+
+        res.append('</li>')
+
+    res.append('</ul>')
+    return '\n'.join(res)
+
+
+if __name__ == '__main__':
+    import sys
+    try:
+        import debugger
+    except:
+        sys.stdout.write(pretty_tb(*sys.exc_info()))
+
+