Commit 478fd8f9 authored by PJ Eby's avatar PJ Eby

Display a download warning in ez_setup, so that people won't be caught

off-guard by the setuptools download (which only occurs if setuptools isn't
locally available, of course).

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041216
parent 040f032a
...@@ -40,18 +40,19 @@ import sys, os ...@@ -40,18 +40,19 @@ import sys, os
def use_setuptools( def use_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
download_delay=15
): ):
"""Automatically find/download setuptools and make it available on sys.path """Automatically find/download setuptools and make it available on sys.path
`version` should be a valid setuptools version number that is available `version` should be a valid setuptools version number that is available
as an egg for download under the `download_base` URL (which should end with as an egg for download under the `download_base` URL (which should end with
a '/'). `to_dir` is the directory where setuptools will be downloaded, if a '/'). `to_dir` is the directory where setuptools will be downloaded, if
it is not already available. it is not already available. If `download_delay` is specified, it should
be the number of seconds that will be paused before initiating a download,
If an older version of setuptools is installed, this will print a message should one be required. If an older version of setuptools is installed,
to ``sys.stderr`` and raise SystemExit in an attempt to abort the calling this routine will print a message to ``sys.stderr`` and raise SystemExit in
script. an attempt to abort the calling script.
""" """
try: try:
import setuptools import setuptools
...@@ -61,9 +62,8 @@ def use_setuptools( ...@@ -61,9 +62,8 @@ def use_setuptools(
"remove it from your system entirely before rerunning this script." "remove it from your system entirely before rerunning this script."
) )
sys.exit(2) sys.exit(2)
except ImportError: except ImportError:
egg = download_setuptools(version, download_base, to_dir) egg = download_setuptools(version, download_base, to_dir, dl_delay)
sys.path.insert(0, egg) sys.path.insert(0, egg)
import setuptools; setuptools.bootstrap_install_from = egg import setuptools; setuptools.bootstrap_install_from = egg
...@@ -81,46 +81,46 @@ def use_setuptools( ...@@ -81,46 +81,46 @@ def use_setuptools(
sys.exit(2) sys.exit(2)
def download_setuptools( def download_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
delay = 15
): ):
"""Download setuptools from a specified location and return its filename """Download setuptools from a specified location and return its filename
`version` should be a valid setuptools version number that is available `version` should be a valid setuptools version number that is available
as an egg for download under the `download_base` URL (which should end as an egg for download under the `download_base` URL (which should end
with a '/'). `to_dir` is the directory where the egg will be downloaded. with a '/'). `to_dir` is the directory where the egg will be downloaded.
`delay` is the number of seconds to pause before an actual download attempt.
""" """
import urllib2, shutil import urllib2, shutil
egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3])
url = download_base + egg_name + '.zip' # XXX url = download_base + egg_name
saveto = os.path.join(to_dir, egg_name) saveto = os.path.join(to_dir, egg_name)
src = dst = None src = dst = None
if not os.path.exists(saveto): # Avoid repeated downloads if not os.path.exists(saveto): # Avoid repeated downloads
try: try:
from distutils import log from distutils import log
if delay:
log.warn("""
---------------------------------------------------------------------------
This script requires setuptools version %s to run (even to display
help). I will attempt to download it for you from %s, but
you may need to enable firewall access for this script first.
I will start the download in %d seconds.
---------------------------------------------------------------------------""",
version, download_base, delay
)
from time import sleep; sleep(delay)
log.warn("Downloading %s", url) log.warn("Downloading %s", url)
src = urllib2.urlopen(url) src = urllib2.urlopen(url)
# Read/write all in one block, so we don't create a corrupt file # Read/write all in one block, so we don't create a corrupt file
# if the download is interrupted. # if the download is interrupted.
data = src.read() data = src.read()
dst = open(saveto,"wb") dst = open(saveto,"wb"); dst.write(data)
dst.write(data)
finally: finally:
if src: src.close() if src: src.close()
if dst: dst.close() if dst: dst.close()
return os.path.realpath(saveto) return os.path.realpath(saveto)
def main(argv, version=DEFAULT_VERSION): def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall""" """Install or upgrade setuptools and EasyInstall"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment