eodag 4.0.0a3__py3-none-any.whl → 4.0.0a5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,7 @@ import logging
22
22
  import os
23
23
  import re
24
24
  import tempfile
25
+ from datetime import datetime
25
26
  from typing import TYPE_CHECKING, Any, Optional, Union
26
27
 
27
28
  import requests
@@ -60,6 +61,7 @@ from eodag.utils.exceptions import DownloadError, MisconfiguredError, Validation
60
61
  from eodag.utils.repr import dict_to_html_table
61
62
 
62
63
  if TYPE_CHECKING:
64
+ from concurrent.futures import ThreadPoolExecutor
63
65
  from shapely.geometry.base import BaseGeometry
64
66
 
65
67
  from eodag.api.product.drivers.base import DatasetDriver
@@ -119,6 +121,10 @@ class EOProduct:
119
121
  filename: str
120
122
  #: Product search keyword arguments, stored during search
121
123
  search_kwargs: Any
124
+ #: Datetime for download next try
125
+ next_try: datetime
126
+ #: Stream for requests
127
+ _stream: requests.Response
122
128
 
123
129
  def __init__(
124
130
  self, provider: str, properties: dict[str, Any], **kwargs: Any
@@ -334,6 +340,7 @@ class EOProduct:
334
340
  def download(
335
341
  self,
336
342
  progress_callback: Optional[ProgressCallback] = None,
343
+ executor: Optional[ThreadPoolExecutor] = None,
337
344
  wait: float = DEFAULT_DOWNLOAD_WAIT,
338
345
  timeout: float = DEFAULT_DOWNLOAD_TIMEOUT,
339
346
  **kwargs: Unpack[DownloadConf],
@@ -350,6 +357,8 @@ class EOProduct:
350
357
  size as inputs and handle progress bar
351
358
  creation and update to give the user a
352
359
  feedback on the download progress
360
+ :param executor: (optional) An executor to download assets of the product in parallel if it has any. If ``None``
361
+ , a default executor will be created
353
362
  :param wait: (optional) If download fails, wait time in minutes between
354
363
  two download tries
355
364
  :param timeout: (optional) If download fails, maximum time in minutes
@@ -374,17 +383,26 @@ class EOProduct:
374
383
  )
375
384
 
376
385
  progress_callback, close_progress_callback = self._init_progress_bar(
377
- progress_callback
386
+ progress_callback, executor
378
387
  )
388
+
379
389
  fs_path = self.downloader.download(
380
390
  self,
381
391
  auth=auth,
382
392
  progress_callback=progress_callback,
393
+ executor=executor,
383
394
  wait=wait,
384
395
  timeout=timeout,
385
396
  **kwargs,
386
397
  )
387
398
 
399
+ # shutdown executor if it was not created during parallel product downloads
400
+ if (
401
+ executor is not None
402
+ and executor._thread_name_prefix != "eodag-download-all"
403
+ ):
404
+ executor.shutdown(wait=True)
405
+
388
406
  # close progress bar if needed
389
407
  if close_progress_callback:
390
408
  progress_callback.close()
@@ -405,15 +423,22 @@ class EOProduct:
405
423
  return fs_path
406
424
 
407
425
  def _init_progress_bar(
408
- self, progress_callback: Optional[ProgressCallback]
426
+ self,
427
+ progress_callback: Optional[ProgressCallback],
428
+ executor: Optional[ThreadPoolExecutor],
409
429
  ) -> tuple[ProgressCallback, bool]:
430
+ # determine position of the progress bar with a counter of executor passings
431
+ # to avoid bar overwriting in case of parallel downloads
432
+ count = executor._counter() if executor is not None else 1 # type: ignore
433
+
410
434
  # progress bar init
411
435
  if progress_callback is None:
412
- progress_callback = ProgressCallback(position=1)
436
+ progress_callback = ProgressCallback(position=count)
413
437
  # one shot progress callback to close after download
414
438
  close_progress_callback = True
415
439
  else:
416
440
  close_progress_callback = False
441
+ progress_callback.pos = count
417
442
  # update units as bar may have been previously used for extraction
418
443
  progress_callback.unit = "B"
419
444
  progress_callback.unit_scale = True
@@ -428,7 +453,6 @@ class EOProduct:
428
453
  ssl_verify: Optional[bool] = None,
429
454
  auth: Optional[AuthBase] = None,
430
455
  ):
431
-
432
456
  """Download the quicklook image from the EOProduct's quicklook URL.
433
457
 
434
458
  This method performs an HTTP GET request to retrieve the quicklook image and saves it
@@ -528,7 +552,6 @@ class EOProduct:
528
552
  )
529
553
 
530
554
  if not os.path.isfile(quicklook_file):
531
-
532
555
  # progress bar init
533
556
  if progress_callback is None:
534
557
  progress_callback = ProgressCallback()
@@ -571,7 +594,6 @@ class EOProduct:
571
594
  quicklook_file, progress_callback, ssl_verify, auth
572
595
  )
573
596
  except RequestException as e:
574
-
575
597
  logger.debug(
576
598
  f"Error while getting resource with authentication. {e} \nTrying without authentication..."
577
599
  )