forked from Helioviewer-Project/helioviewer.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_info.py
239 lines (193 loc) · 6.71 KB
/
system_info.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
235
236
237
238
239
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""
Helioviewer.org System Information
Author: Keith Hughitt <keith.hughitt@nasa.gov>
Displays relevant system information that may be useful during installation
and trouble-shooting.
"""
import sys
import os
import re
import platform
import datetime
import subprocess
def main():
"""Helioviewer.org System Diagnostics"""
print_greeting()
check_platform()
check_apache()
check_mysql()
check_php()
check_python()
check_kakadu()
check_ffmpeg()
def check_platform():
"""Checks platform"""
print("###########")
print(" Platform")
print("###########")
system = platform.system()
proc = platform.processor()
# OS and architecture information
if system == "Linux":
distro = " ".join(platform.linux_distribution())
print("OS: %s (Linux %s %s)" % (distro, platform.release(), proc))
elif system == "Darwin":
print("OS: Mac OS X %s (%s)" % (platform.mac_ver()[0], proc))
elif system == "Windows":
print("OS: Windows %s %s (%s)" % (platform.release(),
platform.version(), proc))
else:
print ("Unknown OS (%s)" % proc)
print ""
def check_apache():
"""Checks Apache version"""
print("###########")
print(" Apache")
print("###########")
if which("apache2") is not None:
apache_name = "apache2"
elif which("httpd") is not None:
apache_name = "httpd"
else:
print "Apache: NOT FOUND\n"
return
p = subprocess.Popen([apache_name, "-v"], stdout=subprocess.PIPE)
out, err = p.communicate()
print out.split("\n")[0] + "\n"
def check_mysql():
"""Checks MySQL version"""
print("###########")
print(" MySQL")
print("###########")
p = subprocess.Popen(["mysql", "--version"], stdout=subprocess.PIPE)
out, err = p.communicate()
print out
def check_php():
"""Prints PHP support information"""
print("###########")
print(" PHP")
print("###########")
p = subprocess.Popen(["php", "-version"], stdout=subprocess.PIPE)
out, err = p.communicate()
print out.split("\n")[0]
p = subprocess.Popen(["php", "-i"], stdout=subprocess.PIPE)
phpinfo, err = p.communicate()
pattern = re.compile("imagick module version => ([\d\.]*)")
print ("Imagick: %s" % pattern.search(phpinfo).group(1))
pattern = re.compile("GD Version => ([\d\.]*)")
print ("GD: %s" % pattern.search(phpinfo).group(1))
if phpinfo.find('mysqli') != -1:
print("MySQLi: SUPPORTED\n")
else:
print("MySQLi: NOT FOUND\n")
# Zend Gdata?
def check_ffmpeg():
"""Prints FFmpeg support information"""
print("###########")
print(" FFmpeg")
print("###########")
p = subprocess.Popen(["ffmpeg", "-version"], stdout=subprocess.PIPE,
stderr=open('/dev/null'))
out, err = p.communicate()
version = out[:out.find(":")]
print(version)
p = subprocess.Popen(["ffmpeg", "-codecs"], stdout=subprocess.PIPE,
stderr=open('/dev/null'))
out, err = p.communicate()
# H.264
libx264 = [i for i in out.split('\n') if "libx264" in i]
if len(libx264) > 0 and "E" in libx264[0][:8]:
print("libx264: SUPPORTED")
else:
print("libx264: NOT SUPPORTED")
# VP8
libvp8 = [i for i in out.split('\n') if "libvpx" in i]
if len(libvp8) > 0 and "E" in libvp8[0][:8]:
print("libvpx: SUPPORTED")
else:
print("libvpx: NOT SUPPORTED")
def check_python():
"""Checks Python support"""
print("###########")
print(" Python")
print("###########")
# Python version
arch = platform.architecture()[0]
print("Python %s (%s)" % (platform.python_version(), arch))
try:
from MySQLdb import __version__ as mysqldb_version
except ImportError:
mysqldb_version = "NOT INSTALLED"
try:
from numpy import __version__ as numpy_version
except ImportError:
numpy_version = "NOT INSTALLED"
try:
from scipy import __version__ as scipy_version
except ImportError:
scipy_version = "NOT INSTALLED"
try:
from matplotlib import __version__ as matplotlib_version
except ImportError:
matplotlib_version = "NOT INSTALLED"
try:
from PyQt4.QtCore import PYQT_VERSION_STR as pyqt_version
except ImportError:
pyqt_version = "NOT INSTALLED"
print("MySQLdb: %s" % mysqldb_version)
print("NumPy: %s" % numpy_version)
print("SciPy: %s" % scipy_version)
print("Matplotlib: %s" % matplotlib_version)
print("PyQt: %s\n" % pyqt_version)
def check_kakadu():
"""Checks Kakadu support"""
print("###########")
print(" Kakadu")
print("###########")
if os.name is "nt":
kdu_expand = "kdu_expand.exe"
kdu_merge = "kdu_merge.exe"
else:
kdu_expand = "kdu_expand"
kdu_merge = "kdu_merge"
pattern = re.compile("v[\d\.]+")
if which(kdu_expand) is None:
kdu_expand_version = "NOT FOUND"
else:
p = subprocess.Popen([kdu_expand, "-version"], stdout=subprocess.PIPE)
out, err = p.communicate()
kdu_expand_version = pattern.search(out).group(0)
if which(kdu_merge) is None:
kdu_merge_version = "NOT FOUND"
else:
p = subprocess.Popen([kdu_merge, "-version"], stdout=subprocess.PIPE)
out, err = p.communicate()
kdu_merge_version = pattern.search(out).group(0)
print("kdu_expand: %s" % kdu_expand_version)
print("kdu_merge: %s\n" % kdu_merge_version)
def print_greeting():
"""Prints greeting banner"""
print("==========================================================")
print(" Helioviewer.org System Information\n")
print(" " + datetime.datetime.utcnow().strftime("%A, %d. %B %Y %I:%M%p UT"))
print("==========================================================\n")
def which(program):
"""Checks for existence of executable
Source: http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python/377028#377028
"""
def is_exe(fpath):
return os.path.exists(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program) #pylint: disable=W0612
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
if __name__ == "__main__":
sys.exit(main());