swc-windows-installer.py: Extract nano directly to the install directory
[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 os.path
27 import zipfile
28
29 import requests
30
31
32 def install_nano(install_directory):
33     """Download and install the nano text editor"""
34     url = "http://www.nano-editor.org/dist/v2.2/NT/nano-2.2.6.zip"
35     r = requests.get(url)
36     nano_zip_content = _BytesIO(r.content)
37     nano_zip = zipfile.ZipFile(nano_zip_content)
38     nano_files = ['nano.exe', 'cygwin1.dll', 'cygintl-8.dll',
39                   'cygiconv-2.dll', 'cyggcc_s-1.dll']
40     for file_name in nano_files:
41         nano_zip.extract(file_name, install_directory)
42
43 def create_ipython_entry_point(python_scripts_directory):
44     """Creates a terminal-based IPython entry point for msysgit"""
45     output_file = open(python_scripts_directory + 'ipython', 'w')
46     file_contents = """#!/usr/bin/env python
47 import sys
48 from IPython.frontend.html.notebook.notebookapp import launch_new_instance as launch_notebook
49 from IPython.frontend.terminal.ipapp import launch_new_instance as launch_ipython
50
51 def main():
52     if len(sys.argv) > 1 and sys.argv[1] == 'notebook':
53         sys.exit(launch_notebook())
54     else:
55         sys.exit(launch_ipython())
56
57 if __name__ == '__main__':
58     main()
59 """
60
61     output_file.write(file_contents)
62
63 def create_nosetests_entry_point(python_scripts_directory):
64     """Creates a terminal-based nosetests entry point for msysgit"""
65     output_file = open(python_scripts_directory + 'nosetests', 'w')
66     file_contents = """#!/usr/bin/env/ python
67 import sys
68 import nose
69
70 if __name__ == '__main__':
71     sys.exit(nose.core.main())
72 """
73     output_file.write(file_contents)
74
75 def main():
76     python_scripts_directory = "C:\\Anaconda\\Scripts\\"
77     #python_scripts_directory = "./scripts/"
78     create_ipython_entry_point(python_scripts_directory)
79     create_nosetests_entry_point(python_scripts_directory)
80     install_nano(python_scripts_directory)
81
82
83 if __name__ == '__main__':
84     main()