swc-installation-test.py: Add installation-testing script
authorKonrad Hinsen <research@khinsen.fastmail.net>
Sat, 29 Dec 2012 19:41:13 +0000 (14:41 -0500)
committerW. Trevor King <wking@tremily.us>
Sat, 29 Dec 2012 19:41:13 +0000 (14:41 -0500)
The content of this script was posted by Greg Wilson and attributed to
Konrad Hinsen [1].

[1]: https://github.com/swcarpentry/website/issues/38#issuecomment-11189525

swc-installation-test.py [new file with mode: 0644]

diff --git a/swc-installation-test.py b/swc-installation-test.py
new file mode 100644 (file)
index 0000000..4c76274
--- /dev/null
@@ -0,0 +1,60 @@
+# Run this as
+#
+#  python swc_installation_test.py
+#
+# If if says nothing, everything is fine!
+
+import os
+
+python_modules = ['nose']
+
+tools = ['bash',
+         ('easy_install', 'Python setuptools'),
+         ('hg', 'Mercurial'),
+         'make',
+         ('nosetests', 'Python nose'),
+         'sqlite3']
+
+# Check Python modules/packages
+
+def check_python_modules(module_names):
+    for module_name in module_names:
+        try:
+            __import__(module_name)
+        except ImportError:
+            print "Python module '%s' is missing" % module_name
+
+
+# Check command line tools
+
+def check_command_line_tools(tools):
+    shell_path = os.environ['PATH'].split(':')
+    for tool in tools:
+        if isinstance(tool, basestring):
+            command = tool
+            package = None
+        else:
+            command, package = tool
+        found = False
+        for directory in shell_path:
+            filename = os.path.join(directory, command)
+            if os.access(filename, os.X_OK) and not os.path.isdir(filename):
+                found = True
+                break
+        if not found:
+            if package is None:
+                print "Command line tool '%s' is missing" % command
+            else:
+                print "Command line tool '%s' " \
+                    "from package '%s' is missing" % (command, package)
+
+
+# Run all the checks
+
+def main():
+    check_python_modules(python_modules)
+    check_command_line_tools(tools)
+
+
+if __name__ == '__main__':
+    main()