]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - misc/build_helpers/show-tool-versions.py
14b9024df2e88de3bda198b3682377c008298111
[tahoe-lafs/tahoe-lafs.git] / misc / build_helpers / show-tool-versions.py
1 #! /usr/bin/env python
2
3 import locale, os, subprocess, sys, traceback
4
5 added_zetuptoolz_egg = False
6 try:
7     import pkg_resources
8 except ImportError:
9     import glob
10     eggz = glob.glob('setuptools-*.egg')
11     if len(eggz) > 0:
12         egg = os.path.realpath(eggz[0])
13         print >>sys.stderr, "Inserting egg on sys.path: %r" % (egg,)
14         added_zetuptoolz_egg = True
15         sys.path.insert(0, egg)
16
17 def foldlines(s):
18     return s.replace("\n", " ").replace("\r", "")
19
20 def print_platform():
21     print
22     try:
23         import platform
24         out = platform.platform()
25         print "platform:", foldlines(out)
26         print "machine: ", platform.machine()
27         if hasattr(platform, 'linux_distribution'):
28             print "linux_distribution:", repr(platform.linux_distribution())
29     except EnvironmentError:
30         sys.stderr.write("\nGot exception using 'platform'. Exception follows\n")
31         traceback.print_exc(file=sys.stderr)
32         sys.stderr.flush()
33         pass
34
35 def print_python_ver():
36     print
37     print "python:", foldlines(sys.version)
38     print 'maxunicode: ' + str(sys.maxunicode)
39
40 def print_python_encoding_settings():
41     print_stderr([sys.executable, '-c', 'import sys; print >>sys.stderr, sys.stdout.encoding'], label='sys.stdout.encoding')
42     print_stdout([sys.executable, '-c', 'import sys; print sys.stderr.encoding'], label='sys.stderr.encoding')
43     print
44     print 'filesystem.encoding: ' + str(sys.getfilesystemencoding())
45     print 'locale.getpreferredencoding: ' + str(locale.getpreferredencoding())
46     print 'os.path.supports_unicode_filenames: ' + str(os.path.supports_unicode_filenames)
47     try:
48         print 'locale.defaultlocale: ' + str(locale.getdefaultlocale())
49     except ValueError, e:
50         print 'got exception from locale.getdefaultlocale(): ', e
51     print 'locale.locale: ' + str(locale.getlocale())
52
53 def print_stdout(cmdlist, label=None):
54     print
55     try:
56         res = subprocess.Popen(cmdlist, stdin=open(os.devnull),
57                                stdout=subprocess.PIPE).communicate()[0]
58         if label is None:
59             label = cmdlist[0]
60         print label + ': ' + foldlines(res)
61     except EnvironmentError:
62         sys.stderr.write("\nGot exception invoking '%s'. Exception follows.\n" % (cmdlist[0],))
63         traceback.print_exc(file=sys.stderr)
64         sys.stderr.flush()
65         pass
66
67 def print_stderr(cmdlist, label=None):
68     print
69     try:
70         res = subprocess.Popen(cmdlist, stdin=open(os.devnull),
71                                stderr=subprocess.PIPE).communicate()[1]
72         if label is None:
73             label = cmdlist[0]
74         print label + ': ' + foldlines(res)
75     except EnvironmentError:
76         sys.stderr.write("\nGot exception invoking '%s'. Exception follows\n" % (cmdlist[0],))
77         traceback.print_exc(file=sys.stderr)
78         sys.stderr.flush()
79         pass
80
81 def print_as_ver():
82     print
83     if os.path.exists('a.out'):
84         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'."
85         return
86     try:
87         res = subprocess.Popen(['as', '-version'], stdin=open(os.devnull),
88                                stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
89         print 'as: ' + foldlines(res[0]+' '+res[1])
90         if os.path.exists('a.out'):
91             os.remove('a.out')
92     except EnvironmentError:
93         sys.stderr.write("\nGot exception invoking '%s'. Exception follows.\n" % ('as',))
94         traceback.print_exc(file=sys.stderr)
95         sys.stderr.flush()
96         pass
97
98 def print_setuptools_ver():
99     print
100     if added_zetuptoolz_egg:
101         # it would be misleading to report the bundled version of zetuptoolz as the installed version
102         print "setuptools: using bundled egg"
103         return
104     try:
105         import pkg_resources
106         out = str(pkg_resources.require("setuptools"))
107         print "setuptools:", foldlines(out)
108     except (ImportError, EnvironmentError):
109         sys.stderr.write("\nGot exception using 'pkg_resources' to get the version of setuptools. Exception follows\n")
110         traceback.print_exc(file=sys.stderr)
111         sys.stderr.flush()
112         pass
113
114 def print_py_pkg_ver(pkgname, modulename=None):
115     if modulename is None:
116         modulename = pkgname
117
118     print
119     try:
120         import pkg_resources
121         out = str(pkg_resources.require(pkgname))
122         print pkgname + ': ' + foldlines(out)
123     except (ImportError, EnvironmentError):
124         sys.stderr.write("\nGot exception using 'pkg_resources' to get the version of %s. Exception follows.\n" % (pkgname,))
125         traceback.print_exc(file=sys.stderr)
126         sys.stderr.flush()
127         pass
128     except pkg_resources.DistributionNotFound:
129         sys.stderr.write("\npkg_resources reported no %s package installed. Exception follows.\n" % (pkgname,))
130         traceback.print_exc(file=sys.stderr)
131         sys.stderr.flush()
132         pass
133     try:
134         __import__(modulename)
135     except ImportError:
136         pass
137     else:
138         modobj = sys.modules.get(modulename)
139         print pkgname + ' module: ' + str(modobj)
140         try:
141             print pkgname + ' __version__: ' + str(modobj.__version__)
142         except AttributeError:
143             pass
144
145 print_platform()
146
147 print_python_ver()
148
149 print_stdout(['locale'])
150 print_python_encoding_settings()
151
152 print_stdout(['buildbot', '--version'])
153 print_stdout(['cl'])
154 print_stdout(['gcc', '--version'])
155 print_stdout(['g++', '--version'])
156 print_stdout(['cryptest', 'V'])
157 print_stdout(['darcs', '--version'])
158 print_stdout(['darcs', '--exact-version'], label='darcs-exact-version')
159 print_stdout(['7za'])
160 print_stdout(['flappclient', '--version'])
161
162 print_as_ver()
163
164 print_setuptools_ver()
165
166 print_py_pkg_ver('coverage')
167 print_py_pkg_ver('trialcoverage')
168 print_py_pkg_ver('setuptools_trial')
169 print_py_pkg_ver('pyflakes')
170 print_py_pkg_ver('zope.interface')
171 print_py_pkg_ver('setuptools_darcs')
172 print_py_pkg_ver('darcsver')
173 print_py_pkg_ver('Twisted', 'twisted')
174 print_py_pkg_ver('TwistedCore', 'twisted.python')
175 print_py_pkg_ver('TwistedWeb', 'twisted.web')
176 print_py_pkg_ver('TwistedConch', 'twisted.conch')