pymake.utils.download module#
Utility functions to:
download and unzip software releases from the USGS and other organizations (triangle, MT3DMS).
download the latest MODFLOW-based applications and utilities for MacOS, Linux, and Windows from MODFLOW-USGS/executables
determine the latest version (GitHub tag) of a GitHub repository and a dictionary containing the file name and the link to a asset on contained in a github repository
compress all files in a list, files in a list of directories
- download_and_unzip(url, pth='./', delete_zip=True, verify=True, timeout=30, max_requests=10, chunk_size=2048000, verbose=False)[source]#
Download and unzip a zip file from a url.
- Parameters:
url (str) – url address for the zip file
pth (str) – path where the zip file will be saved (default is the current path)
delete_zip (bool) – boolean indicating if the zip file should be deleted after it is unzipped (default is True)
verify (bool) – boolean indicating if the url request should be verified
timeout (int) – url request time out length (default is 30 seconds)
max_requests (int) – number of url download request attempts (default is 10)
chunk_size (int) – maximum url download request chunk size (default is 2048000 bytes)
verbose (bool) – boolean indicating if output will be printed to the terminal
- get_repo_assets(github_repo=None, version=None, error_return=False, verify=True)[source]#
Return a dictionary containing the file name and the link to the asset contained in a github repository.
- Parameters:
github_repo (str) – Repository name, such as MODFLOW-USGS/modflow6. If github_repo is None set to ‘MODFLOW-USGS/executables’
version (str) – github repository release tag
error_return (bool) – boolean indicating if None will be returned if there are GitHub API issues
verify (bool) – boolean indicating if the url request should be verified
- Returns:
result_dict – dictionary of file names and links
- Return type:
dict
- getmfexes(pth='.', version=None, platform=None, exes=None, verbose=False, verify=True)[source]#
Get the latest MODFLOW binary executables from a github site (MODFLOW-USGS/executables) for the specified operating system and put them in the specified path.
- Parameters:
pth (str) – Location to put the executables (default is current working directory)
version (str) – Version of the MODFLOW-USGS/executables release to use. If version is None the github repo will be queried for the version number.
platform (str) – Platform that will run the executables. Valid values include mac, linux, win32 and win64. If platform is None, then routine will download the latest asset from the github repository.
exes (str or list of strings) – executable or list of executables to retain
verbose (bool) – boolean indicating if output will be printed to the terminal
verify (bool) – boolean indicating if the url request should be verified
- getmfnightly(pth='.', platform=None, exes=None, verbose=False, verify=True)[source]#
Get the latest MODFLOW 6 binary nightly-build executables from github (MODFLOW-USGS/modflow6-nightly-build) for the specified operating system and put them in the specified path.
- Parameters:
pth (str) – Location to put the executables (default is current working directory)
platform (str) – Platform that will run the executables. Valid values include mac, linux, win32 and win64. If platform is None, then routine will download the latest asset from the github repository.
exes (str or list of strings) – executable or list of executables to retain
verbose (bool) – boolean indicating if output will be printed to the terminal
verify (bool) – boolean indicating if the url request should be verified
- class pymakeZipFile(file, mode='r', compression=0, allowZip64=True, compresslevel=None, *, strict_timestamps=True, metadata_encoding=None)[source]#
Bases:
ZipFile
ZipFile file attributes are not being preserved. This class preserves file attributes as described on StackOverflow at https://stackoverflow.com/questions/39296101/python-zipfile-removes-execute-permissions-from-binaries
- static compressall(path, file_pths=None, dir_pths=None, patterns=None, append=False)[source]#
Compress selected files or files in selected directories.
- Parameters:
path (str) – output zip file path
file_pths (str or list of str) – file paths to include in the output zip file (default is None)
dir_pths (str or list of str) – directory paths to include in the output zip file (default is None)
patterns (str or list of str) – file patterns to include in the output zip file (default is None)
append (bool) – boolean indicating if file paths should be appended to an existing zip file
- Returns:
success – boolean indicating if the output zip file was created
- Return type:
bool
- extract(member, path=None, pwd=None)[source]#
- Parameters:
member (str) – individual file to extract. If member does not exist, all files are extracted.
path (str) – directory path to extract file in a zip file (default is None, which results in files being extracted in the current directory)
pwd (str) – zip file password (default is None)
- Returns:
ret_val – return value indicating status of file extraction
- Return type:
int
- extractall(path=None, members=None, pwd=None)[source]#
Extract all files in the zipfile.
- Parameters:
path (str) – directory path to extract files in a zip file (default is None, which results in files being extracted in the current directory)
members (str) – individual files to extract (default is None, which extracts all members)
pwd (str) – zip file password (default is None)
- repo_latest_version(github_repo=None, verify=True)[source]#
Return a string of the latest version number (tag) contained in a github repository release.
- Parameters:
github_repo (str) – Repository name, such as MODFLOW-USGS/modflow6. If github_repo is None set to ‘MODFLOW-USGS/executables’
- Returns:
version – string with the latest version/tag number
- Return type:
str
- zip_all(path, file_pths=None, dir_pths=None, patterns=None, append=False)[source]#
Compress all files in the user-provided list of file paths and directory paths that match the provided file patterns.
- Parameters:
path (str) – path of the zip file that will be created
file_pths (str or list) – file path or list of file paths to be compressed
dir_pths (str or list) – directory path or list of directory paths to search for files that will be compressed
patterns (str or list) – file pattern or list of file patterns s to match to when creating a list of files that will be compressed
append (bool) – boolean indicating if file paths should be appended to an existing zip file