From e43fdf007de64f5b6ac26aa0a3966b2156e3b3ca Mon Sep 17 00:00:00 2001 From: agaffney Date: Sun, 7 Sep 2008 14:23:29 -0500 Subject: [PATCH] Create catalyst.util module with capture_traceback() and print_traceback() functions Capture and print traceback when build fails instead of letting python do it --- ChangeLog | 6 ++++++ catalyst | 5 +++-- modules/catalyst/util.py | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 modules/catalyst/util.py diff --git a/ChangeLog b/ChangeLog index 0fb54146..6f5c99d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ # Copyright 2002-2008 Gentoo Foundation; Distributed under the GPL v2 # $Id: $ + 07 Sep 2008; Andrew Gaffney catalyst, + +modules/catalyst/util.py: + Create catalyst.util module with capture_traceback() and print_traceback() + functions Capture and print traceback when build fails instead of letting + python do it + 07 Sep 2008; Andrew Gaffney catalyst, modules/catalyst/config.py, modules/catalyst_support.py: Switch commandline spec value parsing to use catalyst.config.ConfigParser diff --git a/catalyst b/catalyst index 08706063..c8b0a07d 100755 --- a/catalyst +++ b/catalyst @@ -10,6 +10,7 @@ import pdb sys.path.append("./modules") import catalyst.config +import catalyst.util __maintainer__="Chris Gianelloni " __version__="2.0.6" @@ -203,9 +204,9 @@ def build_target(addlargs, targetmap): mytarget.run() except: - # TODO: Capture traceback, so we can display this error after printing of the traceback + catalyst.util.print_traceback() print "!!! catalyst: Error encountered during run of target " + addlargs["target"] - raise + sys.exit(1) if __name__ == "__main__": targetmap={} diff --git a/modules/catalyst/util.py b/modules/catalyst/util.py new file mode 100644 index 00000000..ff12086d --- /dev/null +++ b/modules/catalyst/util.py @@ -0,0 +1,14 @@ +""" +Collection of utility functions for catalyst +""" + +import sys, traceback + +def capture_traceback(): + etype, value, tb = sys.exc_info() + s = [x.strip() for x in traceback.format_exception(etype, value, tb)] + return s + +def print_traceback(): + for x in capture_traceback(): + print x -- 2.26.2