forked from fengshao0907/pyinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyinfo.py
234 lines (206 loc) · 9.39 KB
/
pyinfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import os
import sys
import platform
import cgi
import socket
def application( environ, start_response ):
status = '200 OK'
output = pyinfo()
response_headers = [
( 'Content-Type', 'text/html' ),
( 'Content-Length', str( len( output ) ) )
]
start_response( status, response_headers )
return [output]
def pyinfo():
html = '<!DOCTYPE html>\n'
html += '<html><head><title>pyinfo()</title><meta name="robots" content="noindex,nofollow,noarchive,nosnippet">'
html += styles()
html += '</head>'
html += '<body><div class="center">' + section_title()
html += '<h2>System</h2>' + section_system()
html += '<h2>Python Internals</h2>' + section_py_internals()
html += '<h2>OS Internals</h2>' + section_os_internals()
html += '<h2>WSGI Environment</h2>' + section_environ()
html += '<h2>Database support</h2>' + section_database()
html += '<h2>Compression and archiving</h2>' + section_compression()
if 'ldap' in sys.modules:
html += '<h2>LDAP support</h2>' + section_ldap()
if 'socket' in sys.modules:
html += '<h2>Socket</h2>' + section_socket()
html += '<h2>Multimedia support</h2>' + section_multimedia()
html += '<h2>Copyright</h2>' + section_copyright()
html += '</div></body></html>'
return html
def styles():
css = '<style type="text/css">'
css += 'body{background-color:#fff;color:#000}'
css += 'body,td,th,h1,h2{font-family:sans-serif}'
css += 'pre{margin:0px;font-family:monospace}'
css += 'a:link{color:#009;text-decoration:none;background-color:#fff}'
css += 'a:hover{text-decoration:underline}'
css += 'table{border-collapse:collapse}'
css += '.center{text-align:center}'
css += '.center table{margin-left:auto;margin-right:auto;text-align:left}'
css += '.center th{text-align:center !important}'
css += 'td,th{border:1px solid #999999;font-size:75%;vertical-align:baseline}'
css += 'h1{font-size:150%}'
css += 'h2{font-size:125%}'
css += '.p{text-align:left}'
css += '.e{width:30%;background-color:#ffffcc;font-weight:bold;color:#000}'
css += '.h{background:url(\'http://python.org/images/header-bg2.png\') repeat-x;font-weight:bold;color:#000}'
css += '.v{background-color:#f2f2f2;color:#000}'
css += '.vr{background-color:#cccccc;text-align:right;color:#000}'
css += 'img{float:right;border:0px;}'
css += 'hr{width:600px;background-color:#ccc;border:0px;height:1px;color:#000}'
css += '</style>'
return css
def table( html ):
return '<table border="0" cellpadding="3" width="600">%s</table><br>' % html
def table_row( data ):
html = ''
while data:
html += '<tr><td class="e">%s</td><td class="v">%s</td></tr>' % ( data.pop( 0 ), data.pop( 0 ) )
return table( html )
def is_imported( module ):
if module in sys.modules:
return 'enabled'
return 'disabled'
def section_title():
html = '<tr class="h"><td>'
html += '<a href="http://python.org/"><img border="0" src="http://python.org/images/python-logo.gif"></a>'
html += '<h1 class="p">Python %s</h1>' % platform.python_version()
html += '</td></tr>'
return table( html )
def section_system():
data = []
if platform.dist()[0] != '' and platform.dist()[1] != '':
data += 'OS Version', '%s %s (%s %s)' % ( platform.system(), platform.release(), platform.dist()[0].capitalize(), platform.dist()[1] )
else:
data += 'OS Version', '%s %s' % ( platform.system(), platform.release() )
if hasattr( os, 'path' ): data += 'OS Path', os.environ['PATH']
if hasattr( sys, 'version' ): data += 'Python Version', ''.join( sys.version )
if hasattr( sys, 'subversion' ): data += 'Python Subversion', ', '.join( sys.subversion )
if hasattr( sys, 'prefix' ): data += 'Python Prefix', sys.prefix
if hasattr( sys, 'path' ): data += 'Python Path', sys.path
if hasattr( sys, 'executable' ): data += 'Python Executable', sys.executable
data += 'Build Date', platform.python_build()[1]
data += 'Compiler', platform.python_compiler()
if hasattr( sys, 'api_version' ): data += 'Python API', sys.api_version
return table_row( data )
def section_py_internals():
data = []
if hasattr( sys, 'builtin_module_names' ):
data += 'Built-in Modules', ', '.join( sys.builtin_module_names )
data += 'Byte Order', sys.byteorder + ' endian'
if hasattr( sys, 'getcheckinterval' ): data += 'Check Interval', sys.getcheckinterval()
if hasattr(sys, 'getfilesystemencoding'):
data += 'File System Encoding', sys.getfilesystemencoding()
data += 'Maximum Integer Size', str( sys.maxsize ) + ' (%s)' % str( hex( sys.maxsize ) ).upper().replace( "X", "x" )
if hasattr( sys, 'getrecursionlimit' ): data += 'Maximum Recursion Depth', sys.getrecursionlimit()
if hasattr( sys, 'tracebacklimit' ): tabdatale += 'Maximum Traceback Limit', sys.tracebacklimit
else:
data += 'Maximum Traceback Limit', '1000'
data += 'Maximum Unicode Code Point', sys.maxunicode
return table_row( data )
def section_os_internals():
data = []
if hasattr( os, 'getcwd' ): data += 'Current Working Directory', os.getcwd()
if hasattr( os, 'getegid' ): data += 'Effective Group ID', os.getegid()
if hasattr( os, 'geteuid' ): data += 'Effective User ID', os.geteuid()
if hasattr( os, 'getgid' ): data += 'Group ID', os.getgid()
if hasattr( os, 'getgroups' ): data += 'Group Membership', ', '.join( map( str, os.getgroups() ) )
if hasattr( os, 'linesep' ): data += 'Line Seperator', repr( os.linesep )[1:-1]
if hasattr( os, 'getloadavg' ): data += 'Load Average', ', '.join( map( str, map( lambda x: round( x, 2 ), os.getloadavg() ) ) )
if hasattr( os, 'pathsep' ): data += 'Path Seperator', os.pathsep
try:
if hasattr( os, 'getpid' ) and hasattr( os, 'getppid' ):
data += 'Process ID', ( '%s (parent: %s)' % ( os.getpid(), os.getppid() ) )
except:
pass
if hasattr( os, 'getuid' ): data += 'User ID', os.getuid()
return table_row( data )
def section_environ():
envvars = os.environ.keys()
envvars = sorted( envvars )
data = []
for envvar in envvars:
data += envvar, cgi.escape( str( os.environ[envvar] ) )
return table_row( data )
def section_database():
data = []
data += 'DB2/Informix (ibm_db)', is_imported( 'ibm_db' )
data += 'MSSQL (adodbapi)', is_imported( 'adodbapi' )
data += 'MySQL (MySQL-Python)', is_imported( 'MySQLdb' )
data += 'ODBC (mxODBC)', is_imported( 'mxODBC' )
data += 'Oracle (cx_Oracle)', is_imported( 'cx_Oracle' )
data += 'PostgreSQL (PyGreSQL)', is_imported( 'pgdb' )
data += 'Python Data Objects (PyDO)', is_imported( 'PyDO' )
data += 'SAP DB (sapdbapi)', is_imported( 'sapdbapi ')
data += 'SQLite3', is_imported( 'sqlite3' )
return table_row( data )
def section_compression():
data = []
data += 'Bzip2 Support', is_imported( 'bz2' )
data += 'Gzip Support', is_imported( 'gzip' )
data += 'Tar Support', is_imported( 'tarfile' )
data += 'Zip Support', is_imported( 'zipfile' )
data += 'Zlib Support', is_imported( 'zlib' )
return table_row( data )
def section_ldap():
data = []
data += 'Python-LDAP Version' % urls['Python-LDAP'], ldap.__version__
data += 'API Version', ldap.API_VERSION
data += 'Default Protocol Version', ldap.VERSION
data += 'Minimum Protocol Version', ldap.VERSION_MIN
data += 'Maximum Protocol Version', ldap.VERSION_MAX
data += 'SASL Support (Cyrus-SASL)', ldap.SASL_AVAIL
data += 'TLS Support (OpenSSL)', ldap.TLS_AVAIL
data += 'Vendor Version', ldap.VENDOR_VERSION
return table_row( data )
def section_socket():
data = []
data += 'Hostname', socket.gethostname()
data += 'Hostname (fully qualified)', socket.gethostbyaddr( socket.gethostname() )[0]
try:
data += 'IP Address', socket.gethostbyname( socket.gethostname() )
except:
pass
data += 'IPv6 Support', getattr( socket, 'has_ipv6', False )
data += 'SSL Support', hasattr( socket, 'ssl' )
return table_row( data )
def section_multimedia():
data = []
data += 'AIFF Support', is_imported( 'aifc' )
data += 'Color System Conversion Support', is_imported( 'colorsys' )
data += 'curses Support', is_imported( 'curses' )
data += 'IFF Chunk Support', is_imported( 'chunk' )
data += 'Image Header Support', is_imported( 'imghdr' )
data += 'OSS Audio Device Support', is_imported( 'ossaudiodev' )
data += 'Raw Audio Support', is_imported( 'audioop' )
data += 'Raw Image Support', is_imported( 'imageop' )
data += 'SGI RGB Support', is_imported( 'rgbimg' )
data += 'Sound Header Support', is_imported( 'sndhdr' )
data += 'Sun Audio Device Support', is_imported( 'sunaudiodev' )
data += 'Sun AU Support', is_imported( 'sunau' )
data += 'Wave Support', is_imported( 'wave' )
return table_row( data )
def section_copyright():
html = '<tr class="v"><td>%s</td></tr>' % sys.copyright.replace( '\n\n', '<br>' ).replace( '\r\n', '<br />' ).replace( '(c)', '©' )
return table( html )
optional_modules_list = [
'Cookie',
'zlib', 'gzip', 'bz2', 'zipfile', 'tarfile',
'ldap',
'socket',
'audioop', 'curses', 'imageop', 'aifc', 'sunau', 'wave', 'chunk', 'colorsys', 'rgbimg', 'imghdr', 'sndhdr', 'ossaudiodev', 'sunaudiodev',
'adodbapi', 'cx_Oracle', 'ibm_db', 'mxODBC', 'MySQLdb', 'pgdb', 'PyDO', 'sapdbapi', 'sqlite3'
]
for i in optional_modules_list:
try:
module = __import__( i )
sys.modules[i] = module
globals()[i] = module
except:
pass
#print( pyinfo() )