]> err.no Git - dak/commitdiff
Add print_exc(), debug traceback printing
authorJames Troup <james@nocrew.org>
Fri, 22 Nov 2002 04:06:34 +0000 (04:06 +0000)
committerJames Troup <james@nocrew.org>
Fri, 22 Nov 2002 04:06:34 +0000 (04:06 +0000)
utils.py

index 5970b6cc81aab9e4afcd145f04b3f0cf8a5c2331..ce9f4f4a973af1b1559c93fadecc345b25cfb751 100644 (file)
--- a/utils.py
+++ b/utils.py
@@ -2,7 +2,7 @@
 
 # Utility functions
 # Copyright (C) 2000, 2001, 2002  James Troup <james@nocrew.org>
-# $Id: utils.py,v 1.51 2002-10-16 02:47:32 troup Exp $
+# $Id: utils.py,v 1.52 2002-11-22 04:06:34 troup Exp $
 
 # 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
@@ -20,7 +20,7 @@
 
 ################################################################################
 
-import commands, os, pwd, re, socket, shutil, string, sys, tempfile;
+import commands, os, pwd, re, socket, shutil, string, sys, tempfile, traceback;
 import apt_pkg;
 import db_access;
 
@@ -616,6 +616,33 @@ def parse_args(Options):
 
 ################################################################################
 
+# Inspired(tm) by Bryn Keller's print_exc_plus (See
+# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52215)
+
+def print_exc():
+    tb = sys.exc_info()[2];
+    while tb.tb_next:
+        tb = tb.tb_next;
+    stack = [];
+    frame = tb.tb_frame;
+    while frame:
+        stack.append(frame);
+        frame = frame.f_back;
+    stack.reverse();
+    traceback.print_exc();
+    for frame in stack:
+        print "\nFrame %s in %s at line %s" % (frame.f_code.co_name,
+                                             frame.f_code.co_filename,
+                                             frame.f_lineno);
+        for key, value in frame.f_locals.items():
+            print "\t%20s = " % key,;
+            try:
+                print value;
+            except:
+                print "<unable to print>";
+
+################################################################################
+
 apt_pkg.init()
 
 Cnf = apt_pkg.newConfiguration();