Generalize portage_util.dump_traceback() and make use of it if importing
authorJason Stubbs <jstubbs@gentoo.org>
Fri, 23 Dec 2005 02:46:03 +0000 (02:46 -0000)
committerJason Stubbs <jstubbs@gentoo.org>
Fri, 23 Dec 2005 02:46:03 +0000 (02:46 -0000)
a cache module fails.

svn path=/main/trunk/; revision=2439

pym/portage.py
pym/portage_util.py

index 536795ecc6dc0f17a66f71a92ce588a9fe1c3cde..851dab39ccf8ba49cae964ef8af01492365e2811 100644 (file)
@@ -1284,7 +1284,7 @@ class config:
                try:
                        mod = load_mod(best_mod)
                except:
-                       writemsg(red("!!! Failed to import module '%s'\n") % best_mod)
+                       dump_traceback(red("Error: Failed to import module '%s'") % best_mod, noiselevel=0)
                        sys.exit(1)
                return mod
 
@@ -2426,7 +2426,7 @@ def doebuild(myebuild,mydo,myroot,mysettings,debug=0,listonly=0,fetchonly=0,clea
        global db, actionmap_deps
 
        if not tree:
-               dump_traceback("tree not specified to doebuild")
+               dump_traceback("Warning: tree not specified to doebuild")
                tree = "porttree"
 
        ebuild_path = os.path.abspath(myebuild)
index 9c521ab8adc8320223be0bd02490cdeeaa034861..090ce673543bdd3987452cdc74698d39239a78d3 100644 (file)
@@ -456,11 +456,19 @@ def unique_array(array):
        return mya
 
 
-def dump_traceback(msg):
+def dump_traceback(msg, noiselevel=1):
        import sys, traceback
-       writemsg("\n====================================\n", noiselevel=1)
-       writemsg("Warning: %s\n" % msg, noiselevel=1)
-       for line in traceback.format_list(traceback.extract_stack()[:-1]):
-               writemsg(line, noiselevel=1)
-       writemsg("Please file a bug for %s\n" % sys.argv[0], noiselevel=1)
-       writemsg("====================================\n\n", noiselevel=1)
+       info = sys.exc_info()
+       if not info[2]:
+               stack = traceback.extract_stack()[:-1]
+               error = None
+       else:
+               stack = traceback.extract_tb(info[2])
+               error = str(info[1])
+       writemsg("\n====================================\n", noiselevel=noiselevel)
+       writemsg("%s\n\n" % msg, noiselevel=noiselevel)
+       for line in traceback.format_list(stack):
+               writemsg(line, noiselevel=noiselevel)
+       if error:
+               writemsg(error+"\n", noiselevel=noiselevel)
+       writemsg("====================================\n\n", noiselevel=noiselevel)