Improve `files.download` by preferring curl always and handle errors.
Also cleans up after a failed wget, if curl isn't available.
@@ -30,7 +30,7 @@ def download(
sha256sum=None, sha1sum=None, md5sum=None,
):
'''
- Download files from remote locations.
+ Download files from remote locations using curl or wget.
+ source_url: source URL of the file
+ destination: where to save the file
@@ -43,8 +43,6 @@ def download(
+ sha1sum: sha1 hash to checksum the downloaded file against
+ md5sum: md5 hash to checksum the downloaded file against
- Note: Assumes wget is installed.
-
Example:
.. code:: python
@@ -84,7 +82,11 @@ def download(
# If we download, always do user/group/mode as SSH user may be different
if download:
- yield 'curl -s {0} -o {1} 2> /dev/null || wget -q {0} -O {1}'.format(
+ # Only use wget if we don't find curl but do find wget, default to curl
+ if host.fact.which('curl') or not host.fact.which('wget'):
+ yield 'curl -sSf {0} -o {1}'.format(source_url, destination)
+ else:
+ yield 'wget -q {0} -O {1} || rm -f {1}; exit 1'.format(
source_url, destination,
)
