From 5a9445cd57c60bb47451d8a88ec12a7a865013b7 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Wed, 15 Jun 2005 02:19:42 +0000 Subject: Add bootstrap installation support that "hitches a ride" on other packages being installed via the normal distutils "setup.py install". Also, don't repeatedly download the setuptools egg if it's already in the target location. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041069 --- ez_setup.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'ez_setup.py') diff --git a/ez_setup.py b/ez_setup.py index 887c4dcc..c59baf06 100755 --- a/ez_setup.py +++ b/ez_setup.py @@ -63,8 +63,10 @@ def use_setuptools( sys.exit(2) except ImportError: - sys.path.insert(0, download_setuptools(version, download_base, to_dir)) - + egg = download_setuptools(version, download_base, to_dir) + sys.path.insert(0, egg) + import setuptools; setuptools.bootstrap_install_from = egg + import pkg_resources try: pkg_resources.require("setuptools>="+version) @@ -78,8 +80,6 @@ def use_setuptools( ) % version sys.exit(2) - - def download_setuptools( version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir ): @@ -95,13 +95,19 @@ def download_setuptools( saveto = os.path.join(to_dir, egg_name) src = dst = None - try: - src = urllib2.urlopen(url) - dst = open(saveto,"wb") - shutil.copyfileobj(src,dst) - finally: - if src: src.close() - if dst: dst.close() + if not os.path.exists(saveto): # Avoid repeated downloads + try: + from distutils import log + log.warn("Downloading %s", url) + src = urllib2.urlopen(url) + # Read/write all in one block, so we don't create a corrupt file + # if the download is interrupted. + data = src.read() + dst = open(saveto,"wb") + dst.write(data) + finally: + if src: src.close() + if dst: dst.close() return os.path.realpath(saveto) @@ -115,12 +121,6 @@ def download_setuptools( - - - - - - def main(argv, version=DEFAULT_VERSION): """Install or upgrade setuptools and EasyInstall""" -- cgit v1.2.1