Commit a90e5409 authored by jim's avatar jim

Added an option to install only from a download cache.


git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@73338 62d5b8a3-27da-0310-9561-8e5933582275
parent d70911ad
......@@ -104,11 +104,11 @@ _easy_install_cmd = _safe_arg(
'from setuptools.command.easy_install import main; main()'
)
class Installer:
_versions = {}
_download_cache = None
_install_from_cache = False
def __init__(self,
dest=None,
......@@ -121,6 +121,14 @@ class Installer:
versions=None,
):
self._dest = dest
if self._install_from_cache:
if not self._download_cache:
raise ValueError("install_from_cache set to true with no"
" download cache")
links = ()
index = 'file://' + self._download_cache
self._links = links = list(links)
if self._download_cache and (self._download_cache not in links):
links.insert(0, self._download_cache)
......@@ -453,7 +461,9 @@ class Installer:
# XXX Need test for this
for dist in dists:
if dist.has_metadata('dependency_links.txt'):
if (dist.has_metadata('dependency_links.txt')
and not self._install_from_cache
):
for link in dist.get_metadata_lines('dependency_links.txt'):
link = link.strip()
if link not in self._links:
......@@ -625,7 +635,6 @@ class Installer:
if tmp != self._download_cache:
shutil.rmtree(tmp)
def default_versions(versions=None):
old = Installer._versions
if versions is not None:
......@@ -635,9 +644,17 @@ def default_versions(versions=None):
def download_cache(path=-1):
old = Installer._download_cache
if path != -1:
if path:
path = os.path.abspath(path)
Installer._download_cache = path
return old
def install_from_cache(setting=None):
old = Installer._install_from_cache
if setting is not None:
Installer._install_from_cache = bool(setting)
return old
def install(specs, dest,
links=(), index=None,
executable=sys.executable, always_unzip=False,
......
......@@ -919,7 +919,62 @@ Now when we install the distributions:
Note that we didn't download the distributions from the link server.
If we remove the restriction on demo, we'll download a newer version
from the link server:
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest,
... links=[link_server], index=link_server+'index/',
... always_unzip=True)
GET 200 /demo-0.3-py2.4.egg
Normally, the download cache is the prefered source of downloads, but
not the only one.
Installing solely from a download cache
A download cache can be used as the basis of application sources
releases. In an application source release, we want to distribute an
application that can be built without making any network accesses. In
this case, we distribute a download cache and tell the easy_install
module to install from the download cache only, without making network
accesses. The install_from_cache function can be used to signal that
packages should be installed only from the download cache. The
function always returns the previous setting. Calling it with no
arguments returns the current setting without changing it:
>>> zc.buildout.easy_install.install_from_cache()
False
Calling it with a boolean value changes the setting and returns the
previous setting:
>>> zc.buildout.easy_install.install_from_cache(True)
False
Let's remove demo-0.3-py2.4.egg from the cache, clear the index cache,
recreate the destination directory, and reinstall demo:
>>> remove(cache, 'demo-0.3-py2.4.egg')
>>> zc.buildout.easy_install.clear_index_cache()
>>> remove(dest)
>>> dest = tmpdir('sample-install')
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest,
... links=[link_server], index=link_server+'index/',
... always_unzip=True)
>>> ls(dest)
d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg
This time, we didn't download from or even query the link server.
.. Disable the download cache:
>>> zc.buildout.easy_install.download_cache(None)
'/cache'
>>> zc.buildout.easy_install.install_from_cache(False)
True
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