pds4_tools.utils.data_access module

Functions

download_file(url[, force, block_size, timeout])

Download a remote file from a URL.

is_supported_url(string)

Check if a string is a supported URL.

clear_download_cache([urls])

Clears the data file cache by deleting the local file(s).

Details

download_file(url, force=False, block_size=65536, timeout=10)[source]

Download a remote file from a URL.

Files are downloaded into a local cache location, and deleted upon Python interpreter exit. Uses is_supported_url to determine supported URL schemes.

Parameters
urlstr or unicode

A supported remote URL to download.

forcebool, optional

Re-download file even if the URL is already cached. Defaults to None.

block_sizeint, optional

The block-size of each remote read command, in bytes. Defaults to 64 KB.

timeoutint, optional

A timeout in seconds for blocking operations like the connection attempt. Defaults to 10 seconds.

Returns
str or unicode

Path to the local (cache) location of the downloaded file.

Notes

The cache location can be customized via the PDS4TOOLSCACHEDIR environment variable. Partially adapted from astropy.utils.data.download_file.

is_supported_url(string)[source]

Check if a string is a supported URL.

Parameters
stringstr or unicode

The string to test.

Returns
bool

True if URL scheme is supported for download (HTTP, HTTPS, FTP); False otherwise.

clear_download_cache(urls=None)[source]

Clears the data file cache by deleting the local file(s).

Parameters
urlslist[str or unicode], optional

If given, a list of URLs to delete from the cache. Defaults to None, which deletes all files/URLs from the cache.

Returns
None