3 import errno, locale, os, platform, subprocess, sys, traceback
5 def foldlines(s, numlines=None):
7 if numlines is not None:
8 lines = lines[:numlines]
9 return " ".join(lines).replace("\r", "")
14 out = platform.platform()
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)
26 def print_python_ver():
27 print "python:", foldlines(sys.version)
28 print 'maxunicode: ' + str(sys.maxunicode)
30 def print_python_encoding_settings():
31 print 'filesystem.encoding: ' + str(sys.getfilesystemencoding())
32 print 'locale.getpreferredencoding: ' + str(locale.getpreferredencoding())
34 print 'locale.defaultlocale: ' + str(locale.getdefaultlocale())
36 print 'got exception from locale.getdefaultlocale(): ', e
37 print 'locale.locale: ' + str(locale.getlocale())
39 def print_stdout(cmdlist, label=None, numlines=None):
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'
50 sys.stderr.write("\n%s: Got exception invoking '%s'. Exception follows.\n" % (label, cmdlist[0],))
51 traceback.print_exc(file=sys.stderr)
55 def print_stderr(cmdlist, label=None):
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'
66 sys.stderr.write("\n%s: Got exception invoking '%s'. Exception follows.\n" % (label, cmdlist[0],))
67 traceback.print_exc(file=sys.stderr)
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'."
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'):
82 except EnvironmentError:
83 sys.stderr.write("\nGot exception invoking '%s'. Exception follows.\n" % ('as',))
84 traceback.print_exc(file=sys.stderr)
88 def print_setuptools_ver():
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)
98 except pkg_resources.DistributionNotFound:
99 print 'setuptools: DistributionNotFound'
102 def print_py_pkg_ver(pkgname, modulename=None):
103 if modulename is None:
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)
115 except pkg_resources.DistributionNotFound:
116 print pkgname + ': DistributionNotFound'
119 __import__(modulename)
123 modobj = sys.modules.get(modulename)
124 print pkgname + ' module: ' + str(modobj)
126 print pkgname + ' __version__: ' + str(modobj.__version__)
127 except AttributeError:
134 print_stdout(['locale'])
135 print_python_encoding_settings()
137 print_stdout(['buildbot', '--version'])
138 print_stdout(['buildslave', '--version'])
139 if 'windows' in platform.system().lower():
141 print_stdout(['cc', '--version'], numlines=1)
142 print_stdout(['gcc', '--version'], numlines=1)
143 print_stdout(['git', '--version'])
144 print_stdout(['openssl', 'version'])
145 print_stdout(['darcs', '--version'])
146 print_stdout(['darcs', '--exact-version'], label='darcs-exact-version')
147 print_stdout(['flappclient', '--version'])
148 print_stdout(['valgrind', '--version'])
150 print_setuptools_ver()
152 print_py_pkg_ver('coverage')
153 print_py_pkg_ver('pyflakes')
154 print_py_pkg_ver('Twisted', 'twisted')
155 print_py_pkg_ver('TwistedCore', 'twisted.python')