Commit 6fd43ee6 authored by Lucas Carvalho's avatar Lucas Carvalho

Moved fetch_from_network_cache into zc.buildout.easy_install.Installer._fetch.

Signed-off-by: default avatarLucas Carvalho <lucas@nexedi.com>
parent 771bd6f4
...@@ -18,8 +18,9 @@ It doesn't install scripts. It uses setuptools and requires it to be ...@@ -18,8 +18,9 @@ It doesn't install scripts. It uses setuptools and requires it to be
installed. installed.
""" """
from zc.buildout.networkcache import fetch_from_network_cache, \ from zc.buildout.networkcache import get_filename_from_url, \
upload_network_cached upload_network_cached, \
download_network_cached
import distutils.errors import distutils.errors
import fnmatch import fnmatch
import glob import glob
...@@ -706,9 +707,11 @@ class Installer: ...@@ -706,9 +707,11 @@ class Installer:
and (realpath(os.path.dirname(dist.location)) == download_cache) and (realpath(os.path.dirname(dist.location)) == download_cache)
): ):
return dist return dist
new_location = fetch_from_network_cache(self._network_cache,
dist.location, tmp, logger) filename = get_filename_from_url(dist.location)
if new_location is None: new_location = os.path.join(tmp, filename)
if not download_network_cached(self._network_cache, new_location,
dist.location, logger):
new_location = self._index.download(dist.location, tmp) new_location = self._index.download(dist.location, tmp)
upload_network_cached(self._network_cache, upload_network_cached(self._network_cache,
dist.location, new_location, logger) dist.location, new_location, logger)
......
...@@ -161,7 +161,7 @@ def upload_network_cached(network_cache, external_url, path, logger): ...@@ -161,7 +161,7 @@ def upload_network_cached(network_cache, external_url, path, logger):
return True return True
def _get_filename_from_url(url): def get_filename_from_url(url):
"""Inspired how pip get filename from url. """Inspired how pip get filename from url.
""" """
url = url.split('#', 1)[0] url = url.split('#', 1)[0]
...@@ -171,19 +171,3 @@ def _get_filename_from_url(url): ...@@ -171,19 +171,3 @@ def _get_filename_from_url(url):
assert name, ( assert name, (
'URL %r produced no filename' % url) 'URL %r produced no filename' % url)
return name return name
def fetch_from_network_cache(network_cache, location, tmp, logger):
""" Try to download from a network cache and preserve
original filename.
"""
if network_cache in (None, ''):
return None
filename = _get_filename_from_url(location)
path = os.path.join(tmp, filename)
is_downloaded = download_network_cached(network_cache, path, location, logger)
if is_downloaded:
return path
return None
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