3 """Software Carpentry Nano Installer for Windows
5 Installs nano and makes it the default editor in msysgit
11 http://code.google.com/p/msysgit/downloads/list?q=full+installer+official+git
12 3. Run swc_nano_installer.py
13 You should be able to simply double click the file in Windows
15 This is a stripped down version of swc_windows_installer.py
16 originally written by Ethan White and W. Trevor Price.
21 from io import BytesIO as _BytesIO
22 except ImportError: # Python 2
23 from StringIO import StringIO as _BytesIO
26 from urllib.request import urlopen as _urlopen
27 except ImportError: # Python 2
28 from urllib2 import urlopen as _urlopen
32 def install_nano(install_dir):
33 """Download and install the nano text editor"""
34 url = "http://www.nano-editor.org/dist/v2.2/NT/nano-2.2.6.zip"
36 nano_zip_content = _BytesIO(r.read())
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_dir)
43 def make_bash_profile(home_dir, nano_dir):
44 """Creates a .bash_profile file for nano setup
46 Adds nano to the path and sets the default editor to nano
50 nano_path = make_posix_path(nano_dir)
51 contents = '\n'.join(['',
52 '# Add nano to path and set as default editor',
53 '# Added by the Software Carpentry nano installer',
54 'export PATH=$PATH:%s' % nano_path,
57 with open(os.path.join(home_dir, '.bash_profile'), 'a') as f:
60 def make_posix_path(windows_path):
61 """Convert a Windows path to a posix path"""
62 return windows_path.replace('\\', '/').replace('C:', '/c')
65 home_dir = os.path.expanduser("~")
66 nano_dir = os.path.join(home_dir, '.nano')
67 #home_dir = "/home/ethan/swc-nano-test"
68 if not os.path.exists(nano_dir):
70 install_nano(nano_dir)
71 make_bash_profile(home_dir, nano_dir)
73 if __name__ == '__main__':