58c1b29b78899609ca6f224e6ba20209645f6a43
[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     contents = '\n'.join([
46             '#!/usr/bin/env python',
47             'from IPython.frontend.terminal.ipapp import launch_new_instance',
48             'launch_new_instance()',
49             '',
50             ])
51     with open(os.path.join(python_scripts_directory, 'ipython'), 'w') as f:
52         f.write(contents)
53
54 def create_nosetests_entry_point(python_scripts_directory):
55     """Creates a terminal-based nosetests entry point for msysgit"""
56     contents = '\n'.join([
57             '#!/usr/bin/env/ python',
58             'import sys',
59             'import nose',
60             "if __name__ == '__main__':",
61             '    sys.exit(nose.core.main())',
62             '',
63             ])
64     with open(os.path.join(python_scripts_directory, 'nosetests'), 'w') as f:
65         f.write(contents)
66
67
68 def main():
69     python_scripts_directory = "C:\\Anaconda\\Scripts\\"
70     #python_scripts_directory = "./scripts/"
71     create_ipython_entry_point(python_scripts_directory)
72     create_nosetests_entry_point(python_scripts_directory)
73     install_nano(python_scripts_directory)
74
75
76 if __name__ == '__main__':
77     main()