From: W. Trevor King Date: Wed, 20 Mar 2013 22:18:05 +0000 (-0400) Subject: swc-windows-installer.py: Avoid writing nano.zip to disk X-Git-Tag: v0.1~39 X-Git-Url: http://git.tremily.us/?p=swc-setup-windows-installer.git;a=commitdiff_plain;h=e27e7d30d21ee41f6b6e4cf49c620de61a592944 swc-windows-installer.py: Avoid writing nano.zip to disk It's already in memory, and we're going to use it again immediately. Avoiding the flush-to-disk is both more efficient, and easier to clean up. --- diff --git a/setup/swc-windows-installer.py b/setup/swc-windows-installer.py index fa4d09e..74ee321 100755 --- a/setup/swc-windows-installer.py +++ b/setup/swc-windows-installer.py @@ -19,9 +19,13 @@ To use: You should be able to simply double click the file in Windows """ +try: # Python 3 + from io import BytesIO as _BytesIO +except ImportError: # Python 2 + from StringIO import StringIO as _BytesIO import shutil +import os.path import zipfile -import os import requests @@ -30,16 +34,13 @@ def install_nano(python_scripts_directory): """Download and install the nano text editor""" url = "http://www.nano-editor.org/dist/v2.2/NT/nano-2.2.6.zip" r = requests.get(url) - output_file = open('nano.zip', 'wb') - output_file.write(r.content) - output_file.close() - nano_zip = zipfile.ZipFile('nano.zip') + nano_zip_content = _BytesIO(r.content) + nano_zip = zipfile.ZipFile(nano_zip_content) nano_files = ['nano.exe', 'cygwin1.dll', 'cygintl-8.dll', 'cygiconv-2.dll', 'cyggcc_s-1.dll'] for file_name in nano_files: nano_zip.extract(file_name, '.') shutil.move(file_name, python_scripts_directory) - os.remove('nano.zip') def create_ipython_entry_point(python_scripts_directory): """Creates a terminal-based IPython entry point for msysgit"""