74ee3214e14239fcee44ce5024c724a4daea779b
[swc-setup-windows-installer.git] / setup / swc-windows-installer.py
1 #!/usr/bin/env python
2
3 """Software Carpentry Windows Installer
4
5 Helps mimic a *nix environment on Windows with as little work as possible.
6
7 The script:
8 * Provides standard ipython operation for msysgit
9 * Provides standard nosetests behavior for msysgit
10 * Installs nano and makes it accessible from msysgit
11
12 To use:
13
14 1. Install Anaconda CE Python distribution
15    http://continuum.io/anacondace.html
16 2. Install msysgit
17    http://code.google.com/p/msysgit/downloads/list?q=full+installer+official+git
18 3. Run swc_windows_installer.py
19    You should be able to simply double click the file in Windows
20 """
21
22 try:  # Python 3
23     from io import BytesIO as _BytesIO
24 except ImportError:  # Python 2
25     from StringIO import StringIO as _BytesIO
26 import shutil
27 import os.path
28 import zipfile
29
30 import requests
31
32
33 def install_nano(python_scripts_directory):
34     """Download and install the nano text editor"""
35     url = "http://www.nano-editor.org/dist/v2.2/NT/nano-2.2.6.zip"
36     r = requests.get(url)
37     nano_zip_content = _BytesIO(r.content)
38     nano_zip = zipfile.ZipFile(nano_zip_content)
39     nano_files = ['nano.exe', 'cygwin1.dll', 'cygintl-8.dll',
40                   'cygiconv-2.dll', 'cyggcc_s-1.dll']
41     for file_name in nano_files:
42         nano_zip.extract(file_name, '.')
43         shutil.move(file_name, python_scripts_directory)
44
45 def create_ipython_entry_point(python_scripts_directory):
46     """Creates a terminal-based IPython entry point for msysgit"""
47     output_file = open(python_scripts_directory + 'ipython', 'w')
48     file_contents = """#!/usr/bin/env python
49 import sys
50 from IPython.frontend.html.notebook.notebookapp import launch_new_instance as launch_notebook
51 from IPython.frontend.terminal.ipapp import launch_new_instance as launch_ipython
52
53 def main():
54     if len(sys.argv) > 1 and sys.argv[1] == 'notebook':
55         sys.exit(launch_notebook())
56     else:
57         sys.exit(launch_ipython())
58
59 if __name__ == '__main__':
60     main()
61 """
62
63     output_file.write(file_contents)
64
65 def create_nosetests_entry_point(python_scripts_directory):
66     """Creates a terminal-based nosetests entry point for msysgit"""
67     output_file = open(python_scripts_directory + 'nosetests', 'w')
68     file_contents = """#!/usr/bin/env/ python
69 import sys
70 import nose
71
72 if __name__ == '__main__':
73     sys.exit(nose.core.main())
74 """
75     output_file.write(file_contents)
76
77 def main():
78     python_scripts_directory = "C:\\Anaconda\\Scripts\\"
79     #python_scripts_directory = "./scripts/"
80     create_ipython_entry_point(python_scripts_directory)
81     create_nosetests_entry_point(python_scripts_directory)
82     install_nano(python_scripts_directory)
83
84
85 if __name__ == '__main__':
86     main()