Skip to content

Commit

Permalink
addition of progress bar callback to core see #21
Browse files Browse the repository at this point in the history
  • Loading branch information
clemcazorla committed Jun 28, 2018
1 parent 16167f4 commit 81e8b3f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions eodag/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from eodag.config import SimpleYamlProxyConfig
from eodag.plugins.instances_manager import PluginInstancesManager
from eodag.utils.exceptions import PluginImplementationError, UnsupportedProvider

from eodag.utils import ProgressCallback

logger = logging.getLogger('eodag.core')

Expand Down Expand Up @@ -239,19 +239,21 @@ def sort_by_extent(searches):
for extent_as_wkb_hex in products_grouped_by_extent
]

def download_all(self, search_result):
def download_all(self, search_result, progress_callback=None):
"""Download all products resulting from a search.
:param search_result: A collection of EO products resulting from a search
:type search_result: :class:`~eodag.api.search_result.SearchResult`
:param progress_callback: progress bar
:type progress_callback: class:`eodag.utils.ProgressCallback`
:returns: A collection of the absolute paths to the downloaded products
:rtype: list
"""
paths = []
if search_result:
with tqdm(search_result, unit='product', desc='Downloading products') as bar:
for product in bar:
paths.append(self.download(product))
paths.append(self.download(product), progress_callback=progress_callback)
else:
print('Empty search result, nothing to be downloaded !')
return paths
Expand Down Expand Up @@ -283,7 +285,7 @@ def deserialize(filename):
with open(filename, 'r') as fh:
return SearchResult.from_geojson(geojson.load(fh))

def download(self, product):
def download(self, product, progress_callback=None):
"""Download a single product.
.. warning::
Expand All @@ -294,11 +296,16 @@ def download(self, product):
:param product: The EO product to download
:type product: :class:`~eodag.api.product.EOProduct`
:param progress_callback: progress bar
:type progress_callback: class:`eodag.utils.ProgressCallback`
:returns: The absolute path to the downloaded product in the local filesystem
:rtype: str or unicode
:raises: :class:`~eodag.utils.exceptions.PluginImplementationError`
:raises: :class:`RuntimeError`
"""
if progress_callback is None:
progress_callback = ProgressCallback()

download_plugin = self._build_download_plugin(product)
logger.debug('Using download plugin: %s for provider: %s', download_plugin.name, download_plugin.instance_name)
try:
Expand All @@ -310,7 +317,7 @@ def download(self, product):
logger.debug('On site usage detected. Authentication for download skipped !')
if auth:
auth = auth.authenticate()
product_location = download_plugin.download(product, auth=auth)
product_location = download_plugin.download(product, auth=auth, progress_callback=progress_callback)
if product_location is None:
logger.warning('The download method of a Download plugin should return the absolute path to the '
'downloaded resource')
Expand Down

0 comments on commit 81e8b3f

Please sign in to comment.