setup: make show-tool-versions report entire verbose exception stack traces when it fails to find a Python package

This commit is contained in:
Zooko O'Whielacronx
2010-09-18 18:15:54 -07:00
parent a5ebcfa4df
commit 0cc0d19f57

View File

@ -1,6 +1,6 @@
#! /usr/bin/env python #! /usr/bin/env python
import locale, os, subprocess, sys import locale, os, subprocess, sys, traceback
def foldlines(s): def foldlines(s):
return s.replace("\n", " ").replace("\r", "") return s.replace("\n", " ").replace("\r", "")
@ -13,9 +13,10 @@ def print_platform():
print "platform:", foldlines(out) print "platform:", foldlines(out)
if hasattr(platform, 'linux_distribution'): if hasattr(platform, 'linux_distribution'):
print "linux_distribution:", repr(platform.linux_distribution()) print "linux_distribution:", repr(platform.linux_distribution())
except EnvironmentError, le: except EnvironmentError:
sys.stderr.write("Got exception using 'platform': %s\n" % (le,)) sys.stderr.write("Got exception using 'platform'. Exception follows\n")
pass traceback.print_exc(file=sys.stderr)
pass
def print_python_ver(): def print_python_ver():
print print
@ -40,8 +41,9 @@ def print_stdout(cmdlist, label=None):
if label is None: if label is None:
label = cmdlist[0] label = cmdlist[0]
print label + ': ' + foldlines(res) print label + ': ' + foldlines(res)
except EnvironmentError, le: except EnvironmentError:
sys.stderr.write("Got exception invoking '%s': %s\n" % (cmdlist[0], le,)) sys.stderr.write("Got exception invoking '%s'. Exception follows.\n" % (cmdlist[0],))
traceback.print_exc(file=sys.stderr)
pass pass
def print_stderr(cmdlist, label=None): def print_stderr(cmdlist, label=None):
@ -52,8 +54,9 @@ def print_stderr(cmdlist, label=None):
if label is None: if label is None:
label = cmdlist[0] label = cmdlist[0]
print label + ': ' + foldlines(res) print label + ': ' + foldlines(res)
except EnvironmentError, le: except EnvironmentError:
sys.stderr.write("Got exception invoking '%s': %s\n" % (cmdlist[0], le,)) sys.stderr.write("Got exception invoking '%s'. Exception follows\n" % (cmdlist[0],))
traceback.print_exc(file=sys.stderr)
pass pass
def print_as_ver(): def print_as_ver():
@ -67,8 +70,9 @@ def print_as_ver():
print 'as: ' + foldlines(res[0]+' '+res[1]) print 'as: ' + foldlines(res[0]+' '+res[1])
if os.path.exists('a.out'): if os.path.exists('a.out'):
os.remove('a.out') os.remove('a.out')
except EnvironmentError, le: except EnvironmentError:
sys.stderr.write("Got exception invoking '%s': %s\n" % ('as', le,)) sys.stderr.write("Got exception invoking '%s'. Exception follows.\n" % ('as',))
traceback.print_exc(file=sys.stderr)
pass pass
def print_setuptools_ver(): def print_setuptools_ver():
@ -77,8 +81,9 @@ def print_setuptools_ver():
import pkg_resources import pkg_resources
out = str(pkg_resources.require("setuptools")) out = str(pkg_resources.require("setuptools"))
print "setuptools:", foldlines(out) print "setuptools:", foldlines(out)
except (ImportError, EnvironmentError), le: except (ImportError, EnvironmentError):
sys.stderr.write("Got exception using 'pkg_resources' to get the version of setuptools: %s\n" % (le,)) sys.stderr.write("Got exception using 'pkg_resources' to get the version of setuptools. Exception follows\n")
traceback.print_exc(file=sys.stderr)
pass pass
def print_py_pkg_ver(pkgname): def print_py_pkg_ver(pkgname):
@ -87,11 +92,13 @@ def print_py_pkg_ver(pkgname):
import pkg_resources import pkg_resources
out = str(pkg_resources.require(pkgname)) out = str(pkg_resources.require(pkgname))
print pkgname + ': ' + foldlines(out) print pkgname + ': ' + foldlines(out)
except (ImportError, EnvironmentError), le: except (ImportError, EnvironmentError):
sys.stderr.write("Got exception using 'pkg_resources' to get the version of %s: %s\n" % (pkgname, le,)) sys.stderr.write("Got exception using 'pkg_resources' to get the version of %s. Exception follows.\n" % (pkgname,))
traceback.print_exc(file=sys.stderr)
pass pass
except pkg_resources.DistributionNotFound, le: except pkg_resources.DistributionNotFound:
sys.stderr.write("pkg_resources reported no %s package installed: %s\n" % (pkgname, le,)) sys.stderr.write("pkg_resources reported no %s package installed. Exception follows.\n" % (pkgname,))
traceback.print_exc(file=sys.stderr)
pass pass
print_platform() print_platform()