def zip_folder(folder_path):
"""
Zip the entire folder and return a file to the zip. Use this inside
a "with" statement to cleanup the zipfile after it is used.
:param folder_path:
:return: Name of the zipfile
"""
filename = os.path.join(
tempfile.gettempdir(), "data-" + uuid.uuid4().hex)
zipfile_name = make_zip(filename, folder_path)
try:
yield zipfile_name
finally:
if os.path.exists(zipfile_name):
os.remove(zipfile_name)
评论列表
文章目录