X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=utils.py;h=f8ef92acaf3bd1d0c8b71c52a33f89949b510f13;hb=3ca8a114bb074ff029e99cf28d308550f74f4c4f;hp=5970b6cc81aab9e4afcd145f04b3f0cf8a5c2331;hpb=c846e77a848d60dd115f00faa0d9a854161d99eb;p=dak.git diff --git a/utils.py b/utils.py index 5970b6cc..f8ef92ac 100644 --- a/utils.py +++ b/utils.py @@ -2,7 +2,7 @@ # Utility functions # Copyright (C) 2000, 2001, 2002 James Troup -# $Id: utils.py,v 1.51 2002-10-16 02:47:32 troup Exp $ +# $Id: utils.py,v 1.54 2002-12-08 17:25:17 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,58 @@ 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 ""; + +################################################################################ + +def try_with_debug(function): + try: + function(); + except SystemExit: + raise; + except: + print_exc(); + +################################################################################ + +# Function for use in sorting lists of architectures. +# Sorts normally except that 'source' dominates all others. + +def arch_compare_sw (a, b): + if a == "source" and b == "source": + return 0; + elif a == "source": + return -1; + elif b == "source": + return 1; + + return cmp (a, b); + +################################################################################ + apt_pkg.init() Cnf = apt_pkg.newConfiguration();