Commit 78c58c2b authored by Sebastian Wehrmann's avatar Sebastian Wehrmann

Restore compatibility to Windows XP and Python2.4.

parent 6278119a
...@@ -1262,7 +1262,8 @@ def _open(base, filename, seen, dl_options, override): ...@@ -1262,7 +1262,8 @@ def _open(base, filename, seen, dl_options, override):
if filename in seen: if filename in seen:
if is_temp: if is_temp:
os.unlink(path) fp.close()
os.remove(path)
raise zc.buildout.UserError("Recursive file include", seen, filename) raise zc.buildout.UserError("Recursive file include", seen, filename)
root_config_file = not seen root_config_file = not seen
...@@ -1274,7 +1275,8 @@ def _open(base, filename, seen, dl_options, override): ...@@ -1274,7 +1275,8 @@ def _open(base, filename, seen, dl_options, override):
parser.optionxform = lambda s: s parser.optionxform = lambda s: s
parser.readfp(fp) parser.readfp(fp)
if is_temp: if is_temp:
os.unlink(path) fp.close()
os.remove(path)
extends = extended_by = None extends = extended_by = None
for section in parser.sections(): for section in parser.sections():
......
...@@ -21,6 +21,7 @@ from zc.buildout.easy_install import realpath ...@@ -21,6 +21,7 @@ from zc.buildout.easy_install import realpath
import logging import logging
import os import os
import os.path import os.path
import re
import shutil import shutil
import tempfile import tempfile
import urllib import urllib
...@@ -148,6 +149,8 @@ class Download(object): ...@@ -148,6 +149,8 @@ class Download(object):
returned and the client code is responsible for cleaning it up. returned and the client code is responsible for cleaning it up.
""" """
if re.match(r"^[A-Za-z]:\\", url):
url = 'file:' + url
parsed_url = urlparse.urlparse(url, 'file') parsed_url = urlparse.urlparse(url, 'file')
url_scheme, _, url_path = parsed_url[:3] url_scheme, _, url_path = parsed_url[:3]
if url_scheme == 'file': if url_scheme == 'file':
...@@ -171,11 +174,11 @@ class Download(object): ...@@ -171,11 +174,11 @@ class Download(object):
if not check_md5sum(tmp_path, md5sum): if not check_md5sum(tmp_path, md5sum):
raise ChecksumError( raise ChecksumError(
'MD5 checksum mismatch downloading %r' % url) 'MD5 checksum mismatch downloading %r' % url)
finally:
os.close(handle)
except: except:
os.remove(tmp_path) os.remove(tmp_path)
raise raise
finally:
os.close(handle)
if path: if path:
shutil.move(tmp_path, path) shutil.move(tmp_path, path)
...@@ -190,12 +193,23 @@ class Download(object): ...@@ -190,12 +193,23 @@ class Download(object):
if self.hash_name: if self.hash_name:
return md5(url).hexdigest() return md5(url).hexdigest()
else: else:
parsed = urlparse.urlparse(url) if re.match(r"^[A-Za-z]:\\", url):
url = 'file:' + url
parsed = urlparse.urlparse(url, 'file')
url_path = parsed[2] url_path = parsed[2]
for name in reversed(url_path.split('/')):
if parsed[0] == 'file':
while True:
url_path, name = os.path.split(url_path)
if name: if name:
return name return name
if not url_path:
break
else: else:
for name in reversed(url_path.split('/')):
if name:
return name
url_host, url_port = parsed[-2:] url_host, url_port = parsed[-2:]
return '%s:%s' % (url_host, url_port) return '%s:%s' % (url_host, url_port)
......
...@@ -121,7 +121,7 @@ scheme will still work: ...@@ -121,7 +121,7 @@ scheme will still work:
>>> cat(download(join(server_data, 'foo.txt'))[0]) >>> cat(download(join(server_data, 'foo.txt'))[0])
This is a foo text. This is a foo text.
>>> cat(download('file://%s/foo.txt' % server_data)[0]) >>> cat(download('file:' + join(server_data, 'foo.txt'))[0])
This is a foo text. This is a foo text.
>>> remove(path) >>> remove(path)
...@@ -231,7 +231,7 @@ sometimes used to create source distributions: ...@@ -231,7 +231,7 @@ sometimes used to create source distributions:
>>> write(server_data, 'foo.txt', 'This is a foo text.') >>> write(server_data, 'foo.txt', 'This is a foo text.')
>>> download = Download(cache=cache) >>> download = Download(cache=cache)
>>> cat(download('file://' + join(server_data, 'foo.txt'), path=path)[0]) >>> cat(download('file:' + join(server_data, 'foo.txt'), path=path)[0])
This is a foo text. This is a foo text.
>>> ls(cache) >>> ls(cache)
- foo.txt - foo.txt
...@@ -260,7 +260,7 @@ as a directory in the file system yet: ...@@ -260,7 +260,7 @@ as a directory in the file system yet:
>>> Download(cache=join(cache, 'non-existent'))(server_url+'foo.txt') >>> Download(cache=join(cache, 'non-existent'))(server_url+'foo.txt')
Traceback (most recent call last): Traceback (most recent call last):
UserError: The directory: UserError: The directory:
'/tmp/tmpZ2cwCfbuildoutSetUp/_TEST_/download-cache/non-existent' '/download-cache/non-existent'
to be used as a download cache doesn't exist. to be used as a download cache doesn't exist.
Using namespace sub-directories of the download cache Using namespace sub-directories of the download cache
...@@ -337,7 +337,7 @@ checksum since we don't know which port the server happens to listen at when ...@@ -337,7 +337,7 @@ checksum since we don't know which port the server happens to listen at when
the test is run, so we don't actually know the full URL of the file. Let's the test is run, so we don't actually know the full URL of the file. Let's
check that the checksum actually belongs to the particular URL used: check that the checksum actually belongs to the particular URL used:
>>> path == join(cache, md5(server_url+'foo.txt').hexdigest()) >>> path.lower() == join(cache, md5(server_url+'foo.txt').hexdigest()).lower()
True True
The cached copy is used when downloading the file again: The cached copy is used when downloading the file again:
...@@ -359,7 +359,7 @@ cache under a different name: ...@@ -359,7 +359,7 @@ cache under a different name:
/download-cache/537b6d73267f8f4447586989af8c470e /download-cache/537b6d73267f8f4447586989af8c470e
>>> path == path2 >>> path == path2
False False
>>> path2 == join(cache, md5(server_url+'other/foo.txt').hexdigest()) >>> path2.lower() == join(cache, md5(server_url+'other/foo.txt').hexdigest()).lower()
True True
>>> cat(path) >>> cat(path)
This is a foo text. This is a foo text.
......
...@@ -2818,7 +2818,7 @@ def test_suite(): ...@@ -2818,7 +2818,7 @@ def test_suite():
tearDown=zc.buildout.testing.buildoutTearDown, tearDown=zc.buildout.testing.buildoutTearDown,
optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS, optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS,
checker=renormalizing.RENormalizing([ checker=renormalizing.RENormalizing([
(re.compile('0x[0-9a-f]+'), '<MEM ADDRESS>'), (re.compile('0x[0-9a-fA-F]+'), '<MEM ADDRESS>'),
(re.compile('http://localhost:[0-9]{4,5}/'), (re.compile('http://localhost:[0-9]{4,5}/'),
'http://localhost/'), 'http://localhost/'),
(re.compile('[0-9a-f]{32}'), '<MD5 CHECKSUM>'), (re.compile('[0-9a-f]{32}'), '<MD5 CHECKSUM>'),
......
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