source: trunk/misc/build_helpers/show-tool-versions.py

Last change on this file was a408487, checked in by zooko <zooko@…>, 12 years ago

show-tool-versions: print openssl version

Ignore-this: 27867f3173d8e311d95fda70c671a8ab

darcs-hash:c2572302d60b87252db5734ce463d2845815a7b1

  • Property mode set to 100755
File size: 5.5 KB
Line 
1#! /usr/bin/env python
2
3import errno, locale, os, platform, subprocess, sys, traceback
4
5def foldlines(s, numlines=None):
6    lines = s.split("\n")
7    if numlines is not None:
8        lines = lines[:numlines]
9    return " ".join(lines).replace("\r", "")
10
11def print_platform():
12    try:
13        import platform
14        out = platform.platform()
15        print
16        print "platform:", foldlines(out)
17        print "machine: ", platform.machine()
18        if hasattr(platform, 'linux_distribution'):
19            print "linux_distribution:", repr(platform.linux_distribution())
20    except EnvironmentError:
21        sys.stderr.write("Got exception using 'platform'. Exception follows\n")
22        traceback.print_exc(file=sys.stderr)
23        sys.stderr.flush()
24        pass
25
26def print_python_ver():
27    print "python:", foldlines(sys.version)
28    print 'maxunicode: ' + str(sys.maxunicode)
29
30def print_python_encoding_settings():
31    print 'filesystem.encoding: ' + str(sys.getfilesystemencoding())
32    print 'locale.getpreferredencoding: ' + str(locale.getpreferredencoding())
33    try:
34        print 'locale.defaultlocale: ' + str(locale.getdefaultlocale())
35    except ValueError, e:
36        print 'got exception from locale.getdefaultlocale(): ', e
37    print 'locale.locale: ' + str(locale.getlocale())
38
39def print_stdout(cmdlist, label=None, numlines=None):
40    if label is None:
41        label = cmdlist[0]
42    try:
43        res = subprocess.Popen(cmdlist, stdin=open(os.devnull),
44                               stdout=subprocess.PIPE).communicate()[0]
45        print label + ': ' + foldlines(res, numlines)
46    except EnvironmentError, e:
47        if isinstance(e, OSError) and e.errno == errno.ENOENT:
48            print str(label) + ': ' + str(cmdlist[0]) + ': no such file or directory'
49            return
50        sys.stderr.write("\n%s: Got exception invoking '%s'. Exception follows.\n" % (label, cmdlist[0],))
51        traceback.print_exc(file=sys.stderr)
52        sys.stderr.flush()
53        pass
54
55def print_stderr(cmdlist, label=None):
56    if label is None:
57        label = cmdlist[0]
58    try:
59        res = subprocess.Popen(cmdlist, stdin=open(os.devnull),
60                               stderr=subprocess.PIPE).communicate()[1]
61        print label + ': ' + foldlines(res)
62    except EnvironmentError, e:
63        if isinstance(e, OSError) and e.errno == errno.ENOENT:
64            print str(label) + ': ' + str(cmdlist[0]) + ': no such file or directory'
65            return
66        sys.stderr.write("\n%s: Got exception invoking '%s'. Exception follows.\n" % (label, cmdlist[0],))
67        traceback.print_exc(file=sys.stderr)
68        sys.stderr.flush()
69        pass
70
71
72def print_as_ver():
73    if os.path.exists('a.out'):
74        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'."
75        return
76    try:
77        res = subprocess.Popen(['as', '-version'], stdin=open(os.devnull),
78                               stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
79        print 'as: ' + foldlines(res[0]+' '+res[1])
80        if os.path.exists('a.out'):
81            os.remove('a.out')
82    except EnvironmentError:
83        sys.stderr.write("\nGot exception invoking '%s'. Exception follows.\n" % ('as',))
84        traceback.print_exc(file=sys.stderr)
85        sys.stderr.flush()
86        pass
87
88def print_setuptools_ver():
89    try:
90        import pkg_resources
91        out = str(pkg_resources.require("setuptools"))
92        print "setuptools:", foldlines(out)
93    except (ImportError, EnvironmentError):
94        sys.stderr.write("\nGot exception using 'pkg_resources' to get the version of setuptools. Exception follows\n")
95        traceback.print_exc(file=sys.stderr)
96        sys.stderr.flush()
97        pass
98    except pkg_resources.DistributionNotFound:
99        print 'setuptools: DistributionNotFound'
100        pass
101
102def print_py_pkg_ver(pkgname, modulename=None):
103    if modulename is None:
104        modulename = pkgname
105    print
106    try:
107        import pkg_resources
108        out = str(pkg_resources.require(pkgname))
109        print pkgname + ': ' + foldlines(out)
110    except (ImportError, EnvironmentError):
111        sys.stderr.write("\nGot exception using 'pkg_resources' to get the version of %s. Exception follows.\n" % (pkgname,))
112        traceback.print_exc(file=sys.stderr)
113        sys.stderr.flush()
114        pass
115    except pkg_resources.DistributionNotFound:
116        print pkgname + ': DistributionNotFound'
117        pass
118    try:
119        __import__(modulename)
120    except ImportError:
121        pass
122    else:
123        modobj = sys.modules.get(modulename)
124        print pkgname + ' module: ' + str(modobj)
125        try:
126            print pkgname + ' __version__: ' + str(modobj.__version__)
127        except AttributeError:
128            pass
129
130print_platform()
131print
132print_python_ver()
133print
134print_stdout(['locale'])
135print_python_encoding_settings()
136print
137print_stdout(['buildbot', '--version'])
138print_stdout(['buildslave', '--version'])
139if 'windows' in platform.system().lower():
140    print_stderr(['cl'])
141print_stdout(['cc', '--version'], numlines=1)
142print_stdout(['gcc', '--version'], numlines=1)
143print_stdout(['git', '--version'])
144print_stdout(['openssl', 'version'])
145print_stdout(['darcs', '--version'])
146print_stdout(['darcs', '--exact-version'], label='darcs-exact-version')
147print_stdout(['flappclient', '--version'])
148print_stdout(['valgrind', '--version'])
149
150print_setuptools_ver()
151
152print_py_pkg_ver('coverage')
153print_py_pkg_ver('pyflakes')
154print_py_pkg_ver('Twisted', 'twisted')
155print_py_pkg_ver('TwistedCore', 'twisted.python')
Note: See TracBrowser for help on using the repository browser.