lunar_toolkit.downloader
¶
PdsDownloader — parallel file retrieval from the PDS archive.
Progress = Callable[[str, int, int | None], None]
module-attribute
¶
progress(file name, bytes done, bytes total or None), called per chunk; raising aborts.
While the host is paused (throttling cooldown) it is called about once a second with
done = -1.
PdsDownloader(cache_dir=DEFAULT_CACHE_DIR, max_workers=4)
¶
Download and cache files from the PDS archive.
| Parameters: |
|
|---|
cache_path(url)
¶
Return the local path that would be used to cache url.
ensure_cached(url, force=False, show_progress=True, expected_md5=None)
¶
Return local path for url, downloading if not already cached.
download(product_rows, output_dir, url_col='PDS_URL', show_progress=True, force=False)
¶
Download PDS image files in parallel.
| Parameters: |
|
|---|
| Returns: |
|
|---|
ChecksumError
¶
Bases: IOError
Raised when a downloaded file does not match its expected MD5.
report_progress(callback)
¶
Send the progress of every download_file in this thread /
context to callback.
file_md5(path, chunk=8 << 20)
¶
Return the hex MD5 digest of path (streamed, constant memory).
url_filename(url)
¶
File name at the end of url's path (query string ignored).
download_file(url, dest, show_progress=True, expected_md5=None, resume=True, timeout=60.0, retries=8, retry_codes=RETRY_CODES, max_wait=None, progress=None)
¶
Download url to dest, throttled per host and retried on throttling / errors.
Politeness: at most $LUNAR_MAX_PER_HOST (default 3) downloads run against one
host at a time, and their requests start at least $LUNAR_MIN_INTERVAL seconds
apart (default 1). Throttling replies (429, 503) pause every download to that host
for the server's Retry-After (up to 2 h; else exponential back-off) and do not
count as failures; they give up only after max_wait seconds in total (default
$LUNAR_MAX_WAIT, else 6 h). Other retry_codes (5xx), connection errors and
interrupted transfers are retried retries times with back-off. Each retry resumes
the .part file; checksum mismatches are not retried. See _download_once.
progress (default: the report_progress callback, if any)
gets the bytes done after each chunk; an exception it raises stops the download and keeps the
.part file for a later resume.