Skip to content
This repository has been archived by the owner on Jan 3, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' into bc-namespaced
Browse files Browse the repository at this point in the history
* master:
  swc-windows-installer.py: Use regular expressions to POSIX-ify paths
  swc-windows-installer.py: Only create the python-scripts dir if it doesn't exist
  swc-windows-installer.py: Split out zip_install into its own function
  • Loading branch information
wking committed Nov 13, 2013
2 parents f9d76c4 + 70c97fc commit 18098fe
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions setup/swc-windows-installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,42 @@
"""

import hashlib
try: # Python 3
from io import BytesIO as _BytesIO
except ImportError: # Python 2
from StringIO import StringIO as _BytesIO
import os
import re
try: # Python 3
from urllib.request import urlopen as _urlopen
except ImportError: # Python 2
from urllib2 import urlopen as _urlopen
import zipfile


def zip_install(url, sha1, install_directory):
"""Download and install a zipped bundle of compiled software"""
r = _urlopen(url)
zip_bytes = r.read()
download_sha1 = hashlib.sha1(zip_bytes).hexdigest()
if download_sha1 != sha1:
raise ValueError(
'downloaded {!r} has the wrong SHA1 hash: {} != {}'.format(
url, downloaded_sha1, sha1))
zip_io = _BytesIO(zip_bytes)
zip_file = zipfile.ZipFile(zip_io)
if not os.path.isdir(install_directory):
os.makedirs(install_directory)
zip_file.extractall(install_directory)


def install_nano(install_directory):
"""Download and install the nano text editor"""
url = "http://www.nano-editor.org/dist/v2.2/NT/nano-2.2.6.zip"
r = _urlopen(url)
nano_zip_content = _BytesIO(r.read())
nano_zip = zipfile.ZipFile(nano_zip_content)
nano_files = ['nano.exe', 'cygwin1.dll', 'cygintl-8.dll',
'cygiconv-2.dll', 'cyggcc_s-1.dll']
os.makedirs(install_directory)
for file_name in nano_files:
nano_zip.extract(file_name, install_directory)
zip_install(
url='http://www.nano-editor.org/dist/v2.2/NT/nano-2.2.6.zip',
sha1='f5348208158157060de0a4df339401f36250fe5b',
install_directory=install_directory)


def create_nosetests_entry_point(python_scripts_directory):
Expand All @@ -55,6 +68,8 @@ def create_nosetests_entry_point(python_scripts_directory):
' sys.exit(nose.core.main())',
'',
])
if not os.path.isdir(python_scripts_directory):
os.makedirs(python_scripts_directory)
with open(os.path.join(python_scripts_directory, 'nosetests'), 'w') as f:
f.write(contents)

Expand All @@ -79,17 +94,23 @@ def update_bash_profile(extra_paths=()):
with open(config_path, 'a') as f:
f.write('\n'.join(lines))


def make_posix_path(windows_path):
"""Convert a Windows path to a posix path"""
return windows_path.replace('\\', '/').replace('C:', '/c')
for regex, sub in [
(re.compile(r'\\'), '/'),
(re.compile('^[Cc]:'), '/c'),
]:
windows_path = regex.sub(sub, windows_path)
return windows_path


def main():
swc_dir = os.path.join(os.path.expanduser('~'), '.swc')
bin_dir = os.path.join(swc_dir, 'bin')
create_nosetests_entry_point(python_scripts_directory=bin_dir)
nano_dir = os.path.join(swc_dir, 'lib', 'nano')
install_nano(installation_directory=nano_dir)
install_nano(install_directory=nano_dir)
update_bash_profile(extra_paths=(nano_dir, bin_dir))


Expand Down

0 comments on commit 18098fe

Please sign in to comment.