From d43f2fbc1ae1f0afa24c2cce864cdc644bb04a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dutrieux?= Date: Wed, 31 Oct 2018 15:46:24 +0100 Subject: [PATCH] Integrate unpack option to download_all_complete method --- lsru/__init__.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lsru/__init__.py b/lsru/__init__.py index 0041545..70b1528 100644 --- a/lsru/__init__.py +++ b/lsru/__init__.py @@ -12,7 +12,7 @@ import requests -from .utils import url_retrieve +from .utils import url_retrieve, url_retrieve_and_unpack __version__ = "0.4.3" @@ -442,11 +442,13 @@ def cancel(self): cancel_request = {"orderid": self.orderid, "status": "cancelled"} return self._request('order', verb='put', body=cancel_request) - def download_all_complete(self, path, overwrite=False, check_complete=True): + def download_all_complete(self, path, unpack=False, overwrite=False, + check_complete=True): """Download all completed scenes of the order to a folder Args: path (str): Directory where data are to be downloaded + unpack (bool): Unpack downloaded archives on the fly overwrite (bool): Force overwriting existing files even when they already exist? Defaults to False check_complete (bool): When local files exist and overwrite is set @@ -456,15 +458,19 @@ def download_all_complete(self, path, overwrite=False, check_complete=True): checking file size takes time (a few millisecons probably), so that you'll save time setting this argument to ``False`` in case you're sure previous downloads are complete + Note that this option does not work when ``unpack`` is set to True Returns: Used for its side effect of batch downloading data, no return """ for url in self.urls_completed: filename = url.split('/')[-1] - dst = os.path.join(path, filename) print('Downloading %s' % filename) - url_retrieve(url, dst, overwrite=overwrite, - check_complete=check_complete) + if unpack: + url_retrieve_and_unpack(url, path, overwrite=overwrite) + else: + dst = os.path.join(path, filename) + url_retrieve(url, dst, overwrite=overwrite, + check_complete=check_complete)