From 66a0604c715728cc1a98de54d34c500f809d6a55 Mon Sep 17 00:00:00 2001 From: david-sarah Date: Tue, 3 Aug 2010 03:11:28 -0700 Subject: [PATCH] misc/build_helpers/show-tool-versions.py: get sys.std{out,err}.encoding and 'as' version correctly, and improve formatting. --- misc/build_helpers/show-tool-versions.py | 79 ++++++++++++------------ 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/misc/build_helpers/show-tool-versions.py b/misc/build_helpers/show-tool-versions.py index 5d33ca22..86594da1 100644 --- a/misc/build_helpers/show-tool-versions.py +++ b/misc/build_helpers/show-tool-versions.py @@ -2,12 +2,15 @@ import locale, os, subprocess, sys +def foldlines(s): + return s.replace("\n", " ").replace("\r", "") + def print_platform(): + print try: import platform out = platform.platform() - print - print "platform:", out.replace("\n", " ") + print "platform:", foldlines(out) if hasattr(platform, 'linux_distribution'): print "linux_distribution:", repr(platform.linux_distribution()) except EnvironmentError, le: @@ -16,52 +19,52 @@ def print_platform(): def print_python_ver(): print - print "python:", sys.version.replace("\n", " "), - print ', maxunicode: ' + str(sys.maxunicode), + print "python:", foldlines(sys.version) + print 'maxunicode: ' + str(sys.maxunicode) + +def print_python_encoding_settings(): + print_stderr([sys.executable, '-c', 'import sys; print >>sys.stderr, sys.stdout.encoding'], label='sys.stdout.encoding') + print_stdout([sys.executable, '-c', 'import sys; print sys.stderr.encoding'], label='sys.stderr.encoding') + print + print 'filesystem.encoding: ' + str(sys.getfilesystemencoding()) + print 'locale.getpreferredencoding: ' + str(locale.getpreferredencoding()) + print 'os.path.supports_unicode_filenames: ' + str(os.path.supports_unicode_filenames) + print 'locale.defaultlocale: ' + str(locale.getdefaultlocale()) + print 'locale.locale: ' + str(locale.getlocale()) -def print_locale(): - cmdlist = ['locale'] +def print_stdout(cmdlist, label=None): + print try: res = subprocess.Popen(cmdlist, stdin=open(os.devnull), stdout=subprocess.PIPE).communicate()[0] - print - print "locale: ", res.replace("\n", " ") + if label is None: + label = cmdlist[0] + print label + ': ' + foldlines(res) except EnvironmentError, le: sys.stderr.write("Got exception invoking '%s': %s\n" % (cmdlist[0], le,)) pass -def print_python_encoding_settings(): +def print_stderr(cmdlist, label=None): print - print 'stdout.encoding: ' + str(sys.stdout.encoding), - print ', stdin.encoding: ' + str(sys.stdin.encoding), - print ', filesystem.encoding: ' + str(sys.getfilesystemencoding()), - print ', locale.getpreferredencoding: ' + str(locale.getpreferredencoding()), - print ', os.path.supports_unicode_filenames: ' + str(os.path.supports_unicode_filenames), - print ', locale.defaultlocale: ' + str(locale.getdefaultlocale()), - print ', locale.locale: ' + str(locale.getlocale()) - -def print_cmd_ver(cmdlist, label=None): try: res = subprocess.Popen(cmdlist, stdin=open(os.devnull), - stdout=subprocess.PIPE).communicate()[0] + stderr=subprocess.PIPE).communicate()[1] if label is None: label = cmdlist[0] - print - print label + ': ' + res.replace("\n", " ") + print label + ': ' + foldlines(res) except EnvironmentError, le: sys.stderr.write("Got exception invoking '%s': %s\n" % (cmdlist[0], le,)) pass def print_as_ver(): + print if os.path.exists('a.out'): - print print "WARNING: a file named a.out exists, and getting the version of the 'as' assembler writes to that filename, so I'm not attempting to get the version of 'as'." return try: res = subprocess.Popen(['as', '-version'], stdin=open(os.devnull), - stderr=subprocess.PIPE).communicate()[1] - print - print 'as: ' + res.replace("\n", " ") + stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() + print 'as: ' + foldlines(res[0]+' '+res[1]) if os.path.exists('a.out'): os.remove('a.out') except EnvironmentError, le: @@ -69,21 +72,21 @@ def print_as_ver(): pass def print_setuptools_ver(): + print try: import pkg_resources out = str(pkg_resources.require("setuptools")) - print - print "setuptools:", out.replace("\n", " ") + print "setuptools:", foldlines(out) except (ImportError, EnvironmentError), le: sys.stderr.write("Got exception using 'pkg_resources' to get the version of setuptools: %s\n" % (le,)) pass def print_py_pkg_ver(pkgname): + print try: import pkg_resources out = str(pkg_resources.require(pkgname)) - print - print pkgname + ': ' + out.replace("\n", " ") + print pkgname + ': ' + foldlines(out) except (ImportError, EnvironmentError), le: sys.stderr.write("Got exception using 'pkg_resources' to get the version of %s: %s\n" % (pkgname, le,)) pass @@ -95,17 +98,17 @@ print_platform() print_python_ver() -print_locale() +print_stdout(['locale']) print_python_encoding_settings() -print_cmd_ver(['buildbot', '--version']) -print_cmd_ver(['cl']) -print_cmd_ver(['gcc', '--version']) -print_cmd_ver(['g++', '--version']) -print_cmd_ver(['cryptest', 'V']) -print_cmd_ver(['darcs', '--version']) -print_cmd_ver(['darcs', '--exact-version'], label='darcs-exact-version') -print_cmd_ver(['7za']) +print_stdout(['buildbot', '--version']) +print_stdout(['cl']) +print_stdout(['gcc', '--version']) +print_stdout(['g++', '--version']) +print_stdout(['cryptest', 'V']) +print_stdout(['darcs', '--version']) +print_stdout(['darcs', '--exact-version'], label='darcs-exact-version') +print_stdout(['7za']) print_as_ver() -- 2.45.2