Create a zip archive out of a input folder Parameters ---------- archive_path Path to the zip file that will be created input_dir input dir to compress compression_level compression level of the resulting zip file.
(
archive_path: Path,
input_dir: Path,
compression_level: int = 6,
)
| 144 | |
| 145 | |
| 146 | def make_zip_archive( |
| 147 | archive_path: Path, |
| 148 | input_dir: Path, |
| 149 | compression_level: int = 6, |
| 150 | ) -> None: |
| 151 | """Create a zip archive out of a input folder |
| 152 | |
| 153 | Parameters |
| 154 | ---------- |
| 155 | archive_path |
| 156 | Path to the zip file that will be created |
| 157 | input_dir |
| 158 | input dir to compress |
| 159 | compression_level |
| 160 | compression level of the resulting zip file. |
| 161 | """ |
| 162 | if compression_level > 0: |
| 163 | compression = zipfile.ZIP_DEFLATED |
| 164 | else: |
| 165 | compression = zipfile.ZIP_STORED |
| 166 | |
| 167 | with zipfile.ZipFile( |
| 168 | archive_path, "w", compression=compression, compresslevel=compression_level |
| 169 | ) as zf: |
| 170 | for file in input_dir.rglob("*"): |
| 171 | zf.write(file, file.relative_to(input_dir)) |
| 172 | |
| 173 | |
| 174 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…