1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | import locale, os, platform, subprocess, sys, traceback |
---|
4 | from importlib.metadata import version, PackageNotFoundError |
---|
5 | |
---|
6 | |
---|
7 | def foldlines(s, numlines=None): |
---|
8 | lines = s.split("\n") |
---|
9 | if numlines is not None: |
---|
10 | lines = lines[:numlines] |
---|
11 | return " ".join(lines).replace("\r", "") |
---|
12 | |
---|
13 | |
---|
14 | def print_platform(): |
---|
15 | try: |
---|
16 | import platform |
---|
17 | out = platform.platform() |
---|
18 | print("platform:", foldlines(out)) |
---|
19 | print("machine: ", platform.machine()) |
---|
20 | if hasattr(platform, 'linux_distribution'): |
---|
21 | print("linux_distribution:", repr(platform.linux_distribution())) |
---|
22 | except EnvironmentError: |
---|
23 | sys.stderr.write("\nGot exception using 'platform'. Exception follows\n") |
---|
24 | traceback.print_exc(file=sys.stderr) |
---|
25 | sys.stderr.flush() |
---|
26 | |
---|
27 | |
---|
28 | def print_python_ver(): |
---|
29 | print("python:", foldlines(sys.version)) |
---|
30 | print('maxunicode: ' + str(sys.maxunicode)) |
---|
31 | |
---|
32 | |
---|
33 | def print_python_encoding_settings(): |
---|
34 | print('filesystem.encoding: ' + str(sys.getfilesystemencoding())) |
---|
35 | print('locale.getpreferredencoding: ' + str(locale.getpreferredencoding())) |
---|
36 | try: |
---|
37 | print('locale.defaultlocale: ' + str(locale.getdefaultlocale())) |
---|
38 | except ValueError as e: |
---|
39 | print('got exception from locale.getdefaultlocale(): ', e) |
---|
40 | print('locale.locale: ' + str(locale.getlocale())) |
---|
41 | |
---|
42 | def print_stdout(cmdlist, label=None, numlines=None): |
---|
43 | try: |
---|
44 | if label is None: |
---|
45 | label = cmdlist[0] |
---|
46 | res = subprocess.Popen(cmdlist, stdin=open(os.devnull), |
---|
47 | stdout=subprocess.PIPE).communicate()[0] |
---|
48 | print(label + ': ' + foldlines(res.decode('utf-8'), numlines)) |
---|
49 | except EnvironmentError as e: |
---|
50 | if isinstance(e, OSError) and e.errno == 2: |
---|
51 | print(label + ': no such file or directory') |
---|
52 | return |
---|
53 | sys.stderr.write("\nGot exception invoking '%s'. Exception follows.\n" % (cmdlist[0],)) |
---|
54 | traceback.print_exc(file=sys.stderr) |
---|
55 | sys.stderr.flush() |
---|
56 | |
---|
57 | |
---|
58 | def print_as_ver(): |
---|
59 | if os.path.exists('a.out'): |
---|
60 | print("WARNING: a file named a.out exists, and getting the version of the 'as' assembler " |
---|
61 | "writes to that filename, so I'm not attempting to get the version of 'as'.") |
---|
62 | return |
---|
63 | try: |
---|
64 | stdout, stderr = subprocess.Popen(['as', '-version'], stdin=open(os.devnull), |
---|
65 | stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() |
---|
66 | print('as: ' + foldlines(stdout.decode('utf-8') + ' ' + stderr.decode('utf-8'))) |
---|
67 | if os.path.exists('a.out'): |
---|
68 | os.remove('a.out') |
---|
69 | except EnvironmentError: |
---|
70 | sys.stderr.write("\nGot exception invoking '%s'. Exception follows.\n" % ('as',)) |
---|
71 | traceback.print_exc(file=sys.stderr) |
---|
72 | sys.stderr.flush() |
---|
73 | |
---|
74 | def print_setuptools_ver(): |
---|
75 | try: |
---|
76 | print("setuptools:", version("setuptools")) |
---|
77 | except PackageNotFoundError: |
---|
78 | print('setuptools: DistributionNotFound') |
---|
79 | |
---|
80 | |
---|
81 | def print_py_pkg_ver(pkgname, modulename=None): |
---|
82 | if modulename is None: |
---|
83 | modulename = pkgname |
---|
84 | print() |
---|
85 | try: |
---|
86 | print(pkgname + ': ' + version(pkgname)) |
---|
87 | except PackageNotFoundError: |
---|
88 | print(pkgname + ': DistributionNotFound') |
---|
89 | try: |
---|
90 | __import__(modulename) |
---|
91 | except ImportError: |
---|
92 | pass |
---|
93 | else: |
---|
94 | modobj = sys.modules.get(modulename) |
---|
95 | print(pkgname + ' module: ' + str(modobj)) |
---|
96 | try: |
---|
97 | print(pkgname + ' __version__: ' + str(modobj.__version__)) |
---|
98 | except AttributeError: |
---|
99 | pass |
---|
100 | |
---|
101 | |
---|
102 | print_platform() |
---|
103 | print() |
---|
104 | print_python_ver() |
---|
105 | print_stdout(['virtualenv', '--version']) |
---|
106 | print_stdout(['tox', '--version']) |
---|
107 | print() |
---|
108 | print_stdout(['locale']) |
---|
109 | print_python_encoding_settings() |
---|
110 | print() |
---|
111 | print_stdout(['buildbot', '--version']) |
---|
112 | print_stdout(['buildslave', '--version']) |
---|
113 | if 'windows' in platform.system().lower(): |
---|
114 | print_stdout(['cl']) |
---|
115 | print_stdout(['gcc', '--version'], numlines=1) |
---|
116 | print_stdout(['g++', '--version'], numlines=1) |
---|
117 | print_stdout(['cryptest', 'V']) |
---|
118 | print_stdout(['git', '--version']) |
---|
119 | print_stdout(['openssl', 'version']) |
---|
120 | print_stdout(['flappclient', '--version']) |
---|
121 | print_stdout(['valgrind', '--version']) |
---|
122 | |
---|
123 | print_as_ver() |
---|
124 | |
---|
125 | print_setuptools_ver() |
---|
126 | |
---|
127 | print_py_pkg_ver('cffi') |
---|
128 | print_py_pkg_ver('coverage') |
---|
129 | print_py_pkg_ver('cryptography') |
---|
130 | print_py_pkg_ver('foolscap') |
---|
131 | print_py_pkg_ver('mock') |
---|
132 | print_py_pkg_ver('pyasn1') |
---|
133 | print_py_pkg_ver('pycparser') |
---|
134 | print_py_pkg_ver('cryptography') |
---|
135 | print_py_pkg_ver('pyflakes') |
---|
136 | print_py_pkg_ver('pyOpenSSL', 'OpenSSL') |
---|
137 | print_py_pkg_ver('six') |
---|
138 | print_py_pkg_ver('trialcoverage') |
---|
139 | print_py_pkg_ver('Twisted', 'twisted') |
---|
140 | print_py_pkg_ver('TwistedCore', 'twisted.python') |
---|
141 | print_py_pkg_ver('TwistedWeb', 'twisted.web') |
---|
142 | print_py_pkg_ver('TwistedConch', 'twisted.conch') |
---|
143 | print_py_pkg_ver('zfec') |
---|
144 | print_py_pkg_ver('zope.interface') |
---|