diff options
author | PJ Eby <distutils-sig@python.org> | 2005-08-22 00:35:47 +0000 |
---|---|---|
committer | PJ Eby <distutils-sig@python.org> | 2005-08-22 00:35:47 +0000 |
commit | c7aa95495d889199acdb271debafbed3c7c0bcc1 (patch) | |
tree | 19e3fc5c6705d203eb6c21917f752d70e91c7925 /ez_setup.py | |
parent | 6a4b9bcc03328f620cedb640892ae995a6cd3d30 (diff) | |
download | external_python_setuptools-c7aa95495d889199acdb271debafbed3c7c0bcc1.tar.gz external_python_setuptools-c7aa95495d889199acdb271debafbed3c7c0bcc1.tar.bz2 external_python_setuptools-c7aa95495d889199acdb271debafbed3c7c0bcc1.zip |
Add hardcoded md5 checking to ez_setup. Also, don't delay and display
banner if ez_setup is run as a command-line script, since its whole purpose
in that case is to download setuptools. Running "ez_setup.py --md5update
FILE [FILE...]" will update the internal md5 checksum dictionary with new
or changed distributions. You should only do this if you are a setuptools
maintainer, however!
--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041218
Diffstat (limited to 'ez_setup.py')
-rwxr-xr-x | ez_setup.py | 82 |
1 files changed, 62 insertions, 20 deletions
diff --git a/ez_setup.py b/ez_setup.py index bcd21983..161dbcc7 100755 --- a/ez_setup.py +++ b/ez_setup.py @@ -13,27 +13,27 @@ the appropriate options to ``use_setuptools()``. This file can also be run as a script to install or upgrade setuptools. """ - DEFAULT_VERSION = "0.6a0" DEFAULT_URL = "http://www.python.org/packages/source/s/setuptools/" -import sys, os - - - - - - - - - - - - - - +md5_data = { + 'setuptools-0.5a13-py2.3.egg': '85edcf0ef39bab66e130d3f38f578c86', + 'setuptools-0.5a13-py2.4.egg': 'ede4be600e3890e06d4ee5e0148e092a', +} +import sys, os +def _validate_md5(egg_name, data): + if egg_name in md5_data: + from md5 import md5 + digest = md5(data).hexdigest() + if digest != md5_data[egg_name]: + print >>sys.stderr, ( + "md5 validation of %s failed! (Possible download problem?)" + % egg_name + ) + sys.exit(2) + return data @@ -103,7 +103,8 @@ def download_setuptools( 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 +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. ---------------------------------------------------------------------------""", @@ -114,7 +115,7 @@ I will start the download in %d seconds. 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() + data = _validate_md5(egg_name, src.read()) dst = open(saveto,"wb"); dst.write(data) finally: if src: src.close() @@ -130,7 +131,7 @@ def main(argv, version=DEFAULT_VERSION): import tempfile, shutil tmpdir = tempfile.mkdtemp(prefix="easy_install-") try: - egg = download_setuptools(version, to_dir=tmpdir) + egg = download_setuptools(version, to_dir=tmpdir, delay=0) sys.path.insert(0,egg) from setuptools.command.easy_install import main main(list(argv)+[egg]) @@ -159,6 +160,47 @@ def main(argv, version=DEFAULT_VERSION): else: print "Setuptools version",version,"or greater has been installed." print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' + + + +def update_md5(filenames): + """Update our built-in md5 registry""" + + import re + from md5 import md5 + + for name in filenames: + base = os.path.basename(name) + f = open(name,'rb') + md5_data[base] = md5(f.read()).hexdigest() + f.close() + + data = [" %r: %r,\n" % it for it in md5_data.items()] + data.sort() + repl = "".join(data) + + import inspect + srcfile = inspect.getsourcefile(sys.modules[__name__]) + f = open(srcfile); src = f.read(); f.close() + + match = re.search("\nmd5_data = {\n([^}]+)}", src) + if not match: + print >>sys.stderr, "Internal error!" + sys.exit(2) + + src = src[:match.start(1)] + repl + src[match.end(1):] + f = open(srcfile,'w') + f.write(src) + f.close() + + if __name__=='__main__': - main(sys.argv[1:]) + if len(sys.argv)>2 and sys.argv[1]=='--md5update': + update_md5(sys.argv[2:]) + else: + main(sys.argv[1:]) + + + + |