3 """Software Carpentry Windows Installer
5 Helps mimic a *nix environment on Windows with as little work as possible.
8 * Installs nano and makes it accessible from msysgit
12 1. Install Python, IPython, and Nose. An easy way to do this is with
13 the Anaconda CE Python distribution
14 http://continuum.io/anacondace.html
16 http://code.google.com/p/msysgit/downloads/list?q=full+installer+official+git
17 3. Run swc_windows_installer.py
18 You should be able to simply double click the file in Windows
23 from io import BytesIO as _BytesIO
24 except ImportError: # Python 2
25 from StringIO import StringIO as _BytesIO
28 from urllib.request import urlopen as _urlopen
29 except ImportError: # Python 2
30 from urllib2 import urlopen as _urlopen
34 def install_nano(install_directory):
35 """Download and install the nano text editor"""
36 url = "http://www.nano-editor.org/dist/v2.2/NT/nano-2.2.6.zip"
38 nano_zip_content = _BytesIO(r.read())
39 nano_zip = zipfile.ZipFile(nano_zip_content)
40 nano_files = ['nano.exe', 'cygwin1.dll', 'cygintl-8.dll',
41 'cygiconv-2.dll', 'cyggcc_s-1.dll']
42 os.makedirs(install_directory)
43 for file_name in nano_files:
44 nano_zip.extract(file_name, install_directory)
47 def update_bash_profile(extra_paths=()):
48 """Create or append to a .bash_profile for Software Carpentry
50 Adds nano to the path, sets the default editor to nano, and adds
51 additional paths for other executables.
55 '# Add paths for Software-Carpentry-installed scripts and executables',
56 'export PATH=$PATH:{}'.format(':'.join(
57 make_posix_path(path) for path in extra_paths),),
59 '# Make nano the default editor',
63 config_path = os.path.join(os.path.expanduser('~'), '.bash_profile')
64 with open(config_path, 'a') as f:
65 f.write('\n'.join(lines))
67 def make_posix_path(windows_path):
68 """Convert a Windows path to a posix path"""
69 return windows_path.replace('\\', '/').replace('C:', '/c')
73 swc_dir = os.path.join(os.path.expanduser('~'), '.swc')
74 nano_dir = os.path.join(swc_dir, 'lib', 'nano')
75 install_nano(installation_directory=nano_dir)
76 update_bash_profile(extra_paths=(nano_dir,))
79 if __name__ == '__main__':