zipfile_repo
Utility functions for handling and fetching repo archives in zip format.
Classes¶
Functions¶
cache_source
¶
cache_source(
zip_uri: str,
is_remote: bool,
cache_dir: Path,
no_input: bool = False,
) -> Path
Download and unpack a zipfile at a given URI.
This will download the zipfile to the cookiecutter repository, and unpack into a temporary directory.
Parameters:
zip_uri
-
The URI for the zipfile.
TYPE:
str
is_remote
-
Is the zip URI a URL or a file?
TYPE:
bool
cache_dir
-
The cookiecutter repository directory to put the archive into.
TYPE:
Path
no_input
-
Do not prompt for user input and eventually force a refresh of cached resources.
TYPE:
bool
DEFAULT:
False
Returns:
-
Path
-
The path to the unpacked zipfile.
download_zipfile
¶
download_zipfile(
url: str, cache_dir: Path, no_input: bool = False
) -> Path
Download a zipfile from a URL into the cache_dir.
extract_zipfile
¶
extract_zipfile(
zip_path: Path,
output_dir: Optional[Path] = None,
password: Optional[str] = None,
) -> Path
Extract a zipfile into a temporary directory.
Parameters:
zip_path
-
The path to the zipfile.
TYPE:
Path
output_dir
-
Optional path to extract the zipfile to. Defaults to a temporary directory.
DEFAULT:
None
password
-
The password for a password-protected zipfile.
DEFAULT:
None
Raises:
-
InvalidZipPasswordError
-
If the zipfile is password-protected and the user provides an incorrect password.
Returns:
-
Path
-
The temporary directory containing the unpacked zipfile.
template_repo_from_zipfile
¶
template_repo_from_zipfile(
zip_uri: str,
locality: Locality,
cache_dir: Path,
no_input: bool = False,
password: Optional[str] = None,
) -> TemplateRepo
Return a template repo from a zipfile URI.
validate_zipfile
¶
validate_zipfile(zip_path: Path, zip_uri: str) -> None
Validate that a zipfile exists and is not empty.
Parameters:
Raises:
-
EmptyZipRepositoryError
-
If the zipfile is empty.
-
NoZipDirectoryError
-
If the zipfile does not contain a top-level directory.