[Distutils] dumb newbie...?

Scott Finnie scott.finnie at virgin.net
Tue Aug 22 21:52:54 CEST 2006

Please be gentle...

Newbie to distutils, trying to install django 0.95 egg 
(www.djangoproject.com) from behind a corporate windows firewall. 
django in turn tries to download and install setuptools - which fails 
due to firewall.  As per ez_setup.py error message, I downloaded the 
setuptools egg, put it in the same dir and re-ran: but got same message.

Took a look at the code and found out why (expects the egg to be in the 
temp dir, not same dir).

Strikes me it's most likely I was doing something wrong / missed an 
option / some other rudimentary mistake.  Assuming that's the case, 
could someone set me straight?

In the unlikely event I've found a bug I've attached a patched version 
below.  Note the patch is anything but elegant, driven by minimal change 
rather than elegant solution.  Very un-pythonic I know.

Like I said, please be gentle...

  - Scoot.
def download_setuptools(
     version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
     delay = 15
     """Download setuptools from a specified location and return its 

     `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 a '/'). `to_dir` is the directory where the egg will be 
     `delay` is the number of seconds to pause before an actual download 
     import urllib2, shutil
     egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3])
     saveto = os.path.join(to_dir, egg_name)
     #Change begins
     #Don't download if the egg is in the current dir.
     #This is a horrible hack; should check for existence
     #in calling routine and possibly skip temp dir creation
     #altogether - depends on whether it's used subsequently by
         shutil.copyfile(egg_name, saveto)
     # change ends (remainder indented though)
         url = download_base + egg_name
         src = dst = None
         if not os.path.exists(saveto):  # Avoid repeated downloads
                 from distutils import log
                 if delay:
     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.

     (Note: if this machine does not have network access, please obtain 
the file


     and place it in this directory before rerunning this script.)
                         version, download_base, delay, url
                     ); from time import sleep; sleep(delay)
                 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 = _validate_md5(egg_name, src.read())
                 dst = open(saveto,"wb"); dst.write(data)
                 if src: src.close()
                 if dst: dst.close()
     return os.path.realpath(saveto)

More information about the Distutils-SIG mailing list