This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
/
check_dependencies.py
153 lines (128 loc) · 4.11 KB
/
check_dependencies.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
#!/usr/bin/env python
import sys
import os
import subprocess
PYTHON_INFO = """
Nimbus requires Python 2.5 or later on the service node.
However, the Python 3.x line is not yet supported.
If you have a supported Python installed but it is not first in your PATH, you
can set a PYTHON environment variable with the path the the python binary and
re-run this program.
"""
SQLITE_PYTHON_INFO = """
Your Python must have the sqlite3 module available.
"""
JAVA_INFO = """
Nimbus requires Java 1.5 or later. GCJ is not supported.
"""
JAVA_VERSION_UNKNOWN = """
You appear to have Java available but its version could not be determined.
Please verify it on your own.
"""
ANT_INFO = """
Apache Ant 1.6.2 or later is required.
You must also have the propertyfile task available which is usually installed
separately from Ant itself. On Redhat-compatible systems this is often a
package called ant-nodeps. On Debian/Ubuntu the package is ant-optional. To be
sure, you can check for the presence of a library called ant-nodeps.jar in your
Ant installation.
"""
LINE = """
--------------------------------------------------------------------------------
""".strip()
def problem(msg):
print >>sys.stderr, LINE
print >>sys.stderr, msg
def run_cmd(args):
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return proc.communicate()
def check_java():
java_home = os.environ.get('JAVA_HOME')
if java_home:
java_bin = os.path.join(java_home, 'bin/java')
javac_bin = os.path.join(java_home, 'bin/javac')
else:
# find these on path
java_bin = 'java'
javac_bin = 'javac'
try:
out,err = run_cmd([java_bin, '-version'])
except OSError:
return "Could not run java executable: " + java_bin + JAVA_INFO
output = out or err
version = parse_java_version(output)
if not version:
return JAVA_VERSION_UNKNOWN + JAVA_INFO
if version < (1, 5) or output.lower().find('gcj') != -1:
return "Found Java: %s\n%s" % (output, JAVA_INFO)
def parse_java_version(output):
if not output.startswith('java'):
return None
topline = output.splitlines()[0]
ver = topline.split()[-1].strip('"')
parts = ver.split('.')
if len(parts) < 3:
return None
try:
return(int(parts[0]), int(parts[1]))
except ValueError:
return None
def check_python():
version = sys.version_info
if version < (2, 5) or version >= (3,):
return "Found Python %s\n%s%s" % (sys.version, PYTHON_INFO,
SQLITE_PYTHON_INFO)
else:
# only check for py modules if the Python is recent enough
try:
import sqlite3
except ImportError:
return SQLITE_PYTHON_INFO
def check_ant():
try:
out, err = run_cmd(['ant', '-version'])
except OSError:
return "Could not run ant.\n" + ANT_INFO
def check_nimbus_dependencies():
problems = []
for check in (check_python, check_java, check_ant):
prob = check()
if prob:
if getattr(prob, '__iter__', False):
problems.extend(prob)
else:
problems.append(prob)
if not problems:
print "Found no dependency problems."
return 0
if len(problems) > 1:
s = 's'
else:
s = ''
print "\nFound %s dependency problem%s:\n" % (len(problems), s)
for problem in problems:
print LINE
print problem
return len(problems)
def main():
try:
return check_nimbus_dependencies()
except SystemExit:
raise
except KeyboardInterrupt:
return 5
except:
exception_type = sys.exc_type
try:
exceptname = exception_type.__name__
except AttributeError:
exceptname = exception_type
name = str(exceptname)
err = str(sys.exc_value)
errmsg = "\n==> Uncaught problem, please report all following output:\n %s: %s" % (name, err)
print >>sys.stderr, errmsg
import traceback
traceback.print_tb(sys.exc_info()[2])
return 97
if __name__ == '__main__':
sys.exit(main())