Merge Konrad Hinsen and Fernando Perez's installation-testing scripts
[swc-setup-installation-test.git] / swc-installation-test.py
1 # Run this as
2 #
3 #  python swc_installation_test.py
4 #
5 # If if says nothing, everything is fine!
6
7 import os
8
9 python_modules = ['nose']
10
11 tools = ['bash',
12          ('easy_install', 'Python setuptools'),
13          ('hg', 'Mercurial'),
14          'make',
15          ('nosetests', 'Python nose'),
16          'sqlite3']
17
18 # Check Python modules/packages
19
20 def check_python_modules(module_names):
21     for module_name in module_names:
22         try:
23             __import__(module_name)
24         except ImportError:
25             print "Python module '%s' is missing" % module_name
26
27
28 # Check command line tools
29
30 def check_command_line_tools(tools):
31     shell_path = os.environ['PATH'].split(':')
32     for tool in tools:
33         if isinstance(tool, basestring):
34             command = tool
35             package = None
36         else:
37             command, package = tool
38         found = False
39         for directory in shell_path:
40             filename = os.path.join(directory, command)
41             if os.access(filename, os.X_OK) and not os.path.isdir(filename):
42                 found = True
43                 break
44         if not found:
45             if package is None:
46                 print "Command line tool '%s' is missing" % command
47             else:
48                 print "Command line tool '%s' " \
49                     "from package '%s' is missing" % (command, package)
50
51
52 # Run all the checks
53
54 def main():
55     check_python_modules(python_modules)
56     check_command_line_tools(tools)
57
58
59 if __name__ == '__main__':
60     main()