File size: 993 Bytes
8a469fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
import os
from pathlib import Path

base_dir = str(Path().absolute())
dirs = [
    os.path.join(base_dir, 'extensions', 'sd-webui-prompt-all-in-one', 'tags'),
    os.path.join(base_dir, 'extensions', 'a1111-sd-webui-tagcomplete', 'tags'),
]


def get_csvs():
    global base_dir
    csvs = []
    for dir in dirs:
        if not os.path.exists(dir):
            continue
        for file in os.listdir(dir):
            if file.endswith('.csv'):
                path = os.path.join(dir, file)
                name = os.path.basename(file)
                size = os.path.getsize(path)
                # 去除 base_dir 后的路径
                key = path.replace(base_dir, '')
                csvs.append({
                    'key': key,
                    'name': name,
                    'size': size,
                    'path': path
                })
    return csvs


def get_csv(key):
    path = base_dir + key
    if not os.path.exists(path):
        return None
    return path