File size: 895 Bytes
f92f684
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)