File size: 800 Bytes
651b002
 
017a7a9
651b002
 
 
 
1d0f43c
 
 
 
651b002
303cbb8
651b002
 
1d0f43c
651b002
 
017a7a9
651b002
 
 
 
1d0f43c
651b002
017a7a9
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from zipfile import ZipFile
from pathlib import Path
import shutil


# Extract the collection file or deck file to get the .anki21 database.
def extract(file, prefix):
    proj_dir = Path(
        f'projects/{prefix}_{file.orig_name.replace(".", "_").replace("@", "_")}'
    )
    with ZipFile(file, "r") as zip_ref:
        zip_ref.extractall(proj_dir)
        # print(f"Extracted {file.orig_name} successfully!")
    return proj_dir


def cleanup(proj_dir: Path, files):
    """
    Delete all files/folders in prefix that dont have filenames in files
    :param proj_dir:
    :param files:
    :return:
    """
    for file in proj_dir.glob("*"):
        if file.name not in files:
            if file.is_file():
                file.unlink()
            else:
                shutil.rmtree(file)