From: Brian Warner Date: Tue, 1 Nov 2011 07:45:32 +0000 (-0700) Subject: show-tool-versions.py: condense output, hide file-not-found exceptions X-Git-Url: https://git.rkrishnan.org/pf/content/%22file:/frontends/configuration.txt?a=commitdiff_plain;h=4baffeed1d641085e49a4d9066e5267619820e77;p=tahoe-lafs%2Ftahoe-lafs.git show-tool-versions.py: condense output, hide file-not-found exceptions --- diff --git a/misc/build_helpers/show-tool-versions.py b/misc/build_helpers/show-tool-versions.py index 31430a8d..db231278 100644 --- a/misc/build_helpers/show-tool-versions.py +++ b/misc/build_helpers/show-tool-versions.py @@ -15,11 +15,13 @@ except ImportError: added_zetuptoolz_egg = True sys.path.insert(0, egg) -def foldlines(s): - return s.replace("\n", " ").replace("\r", "") +def foldlines(s, numlines=None): + lines = s.split("\n") + if numlines is not None: + lines = lines[:numlines] + return " ".join(lines).replace("\r", "") def print_platform(): - print try: import platform out = platform.platform() @@ -34,12 +36,10 @@ def print_platform(): pass def print_python_ver(): - print print "python:", foldlines(sys.version) print 'maxunicode: ' + str(sys.maxunicode) def print_python_encoding_settings(): - print print 'filesystem.encoding: ' + str(sys.getfilesystemencoding()) print 'locale.getpreferredencoding: ' + str(locale.getpreferredencoding()) try: @@ -48,22 +48,23 @@ def print_python_encoding_settings(): print 'got exception from locale.getdefaultlocale(): ', e print 'locale.locale: ' + str(locale.getlocale()) -def print_stdout(cmdlist, label=None): - print +def print_stdout(cmdlist, label=None, numlines=None): try: - res = subprocess.Popen(cmdlist, stdin=open(os.devnull), - stdout=subprocess.PIPE).communicate()[0] if label is None: label = cmdlist[0] - print label + ': ' + foldlines(res) - except EnvironmentError: + res = subprocess.Popen(cmdlist, stdin=open(os.devnull), + stdout=subprocess.PIPE).communicate()[0] + print label + ': ' + foldlines(res, numlines) + except EnvironmentError, e: + if isinstance(e, OSError) and e.errno == 2: + print label + ': no such file or directory' + return sys.stderr.write("\nGot exception invoking '%s'. Exception follows.\n" % (cmdlist[0],)) traceback.print_exc(file=sys.stderr) sys.stderr.flush() pass def print_as_ver(): - print if os.path.exists('a.out'): 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 @@ -80,7 +81,6 @@ def print_as_ver(): pass def print_setuptools_ver(): - print if added_zetuptoolz_egg: # it would be misleading to report the bundled version of zetuptoolz as the installed version print "setuptools: using bundled egg" @@ -98,7 +98,6 @@ def print_setuptools_ver(): def print_py_pkg_ver(pkgname, modulename=None): if modulename is None: modulename = pkgname - print try: import pkg_resources @@ -110,9 +109,7 @@ def print_py_pkg_ver(pkgname, modulename=None): sys.stderr.flush() pass except pkg_resources.DistributionNotFound: - sys.stderr.write("\npkg_resources reported no %s package installed. Exception follows.\n" % (pkgname,)) - traceback.print_exc(file=sys.stderr) - sys.stderr.flush() + print pkgname + ': DistributionNotFound' pass try: __import__(modulename) @@ -127,20 +124,20 @@ def print_py_pkg_ver(pkgname, modulename=None): pass print_platform() - +print print_python_ver() - +print print_stdout(['locale']) print_python_encoding_settings() - +print print_stdout(['buildbot', '--version']) print_stdout(['cl']) -print_stdout(['gcc', '--version']) -print_stdout(['g++', '--version']) +print_stdout(['gcc', '--version'], numlines=1) +print_stdout(['g++', '--version'], numlines=1) print_stdout(['cryptest', 'V']) print_stdout(['darcs', '--version']) print_stdout(['darcs', '--exact-version'], label='darcs-exact-version') -print_stdout(['7za']) +print_stdout(['7za'], numlines=3) print_stdout(['flappclient', '--version']) print_stdout(['valgrind', '--version'])