Spaces:
Runtime error
Runtime error
import time | |
import tempfile | |
import zipfile | |
class Interface: | |
def get_tempdir(): | |
timestamp = int(time.time()) | |
temp_dir = tempfile.mkdtemp() | |
return timestamp, temp_dir | |
def create_zip(file_list, zip_path, password=None): | |
with zipfile.ZipFile(zip_path, "w", zipfilep64=True) as zipf: | |
if password: | |
zipf.setpassword(bytes(password, 'utf-8')) | |
for item in file_list: | |
if os.path.isdir(item): | |
for root, _, files in os.walk(item): | |
for file in files: | |
file_path = os.path.join(root, file) | |
arcname = os.path.relpath(file_path, item) | |
zipf.write(file_path, arcname) | |
else: | |
arcname = os.path.basename(item) | |
zipf.write(item, arcname) |