Simplify create_zipfile

This commit is contained in:
Florian Bruhin 2021-03-24 11:29:55 +01:00
parent 161205eae2
commit cca6cd83d3
1 changed files with 2 additions and 4 deletions

View File

@ -73,15 +73,13 @@ def create_zipfile(directory, files, zipname="test"):
Args:
directory: path object where to create the zip file.
files: list of filenames (relative to directory) to each file to add.
files: list of pathlib.Paths (relative to directory) to each file to add.
zipname: name to give to the zip file.
"""
zipfile_path = (directory / zipname).with_suffix(".zip")
with zipfile.ZipFile(zipfile_path, "w") as new_zipfile:
for file_path in files:
new_zipfile.write(
(directory / file_path), arcname=pathlib.Path(file_path).name
)
new_zipfile.write(directory / file_path, arcname=file_path.name)
# Removes path from file name
return pathlib.Path(zipname + ".zip")