1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | import errno, locale, os, platform, subprocess, sys, traceback |
---|
4 | |
---|
5 | def 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 | |
---|
11 | def 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 | |
---|
26 | def print_python_ver(): |
---|
27 | print "python:", foldlines(sys.version) |
---|
28 | print 'maxunicode: ' + str(sys.maxunicode) |
---|
29 | |
---|
30 | def 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 | |
---|
39 | def 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 | |
---|
55 | def 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 | |
---|
72 | def 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 | |
---|
88 | def 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 | |
---|
102 | def 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 | |
---|
130 | print_platform() |
---|
131 | print |
---|
132 | print_python_ver() |
---|
133 | print |
---|
134 | print_stdout(['locale']) |
---|
135 | print_python_encoding_settings() |
---|
136 | print |
---|
137 | print_stdout(['buildbot', '--version']) |
---|
138 | print_stdout(['buildslave', '--version']) |
---|
139 | if 'windows' in platform.system().lower(): |
---|
140 | print_stderr(['cl']) |
---|
141 | print_stdout(['g++', '--version'], numlines=1) |
---|
142 | print_stdout(['cryptest', 'V']) |
---|
143 | print_stdout(['git', '--version']) |
---|
144 | print_stdout(['openssl', 'version']) |
---|
145 | print_stdout(['flappclient', '--version']) |
---|
146 | print_stdout(['valgrind', '--version']) |
---|
147 | |
---|
148 | print_as_ver() |
---|
149 | |
---|
150 | print_setuptools_ver() |
---|
151 | |
---|
152 | print_py_pkg_ver('pyutil') |
---|
153 | print_py_pkg_ver('coverage') |
---|
154 | print_py_pkg_ver('pyflakes') |
---|
155 | print_py_pkg_ver('Twisted', 'twisted') |
---|
156 | print_py_pkg_ver('TwistedCore', 'twisted.python') |
---|
157 | print_py_pkg_ver('pyOpenSSL', 'OpenSSL') |
---|
158 | print_py_pkg_ver('pycryptopp') |
---|
159 | print_py_pkg_ver('crpyto') |
---|