File size: 2,908 Bytes
063983d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325af3f
 
32acc22
 
325af3f
063983d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92a3b39
063983d
 
 
 
 
 
 
 
 
 
 
325af3f
32acc22
 
063983d
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import json
import os
from datetime import datetime


import cachetools#缓存模块
#将config中导入的内容作为函数返回的结果加入缓存,通过定时更新缓存来更新config
ROTATE = 1 #TTLCache(maxsize = 1, ttl = ROTATE) 表示缓存的生存时间为ttl秒。 最大容量为maxsize个条目。
@cachetools.cached(cachetools.TTLCache(maxsize = 1, ttl = ROTATE))
def get_variables():
    # 获取当前脚本的根目录路径
    current_dir = os.path.dirname(os.path.abspath(__file__))
    current_config_json = os.path.join(current_dir, "config.json")

    def get_config_data()->json:
        with open(current_config_json,'r')as f:
            data = json.load(f)
        return data
    data = get_config_data()
    #是否允许定时任务执行->方便开关任务
    allow_scheduler = data['allow_scheduler']
    #是否允许bili上传
    allow_submit = data['allow_submit']
    #默认删除章节片头和广告的配置
    default_chapter_delete = data['default_chapter_delete']

    #设置manga保存路径
    manga_dir = data['manga_dir']
    #设置mask保存路径
    mask_dir = data['mask_dir']
    #获取manga绝对路径
    manga_abs_dir = os.path.join(current_dir, manga_dir)
    #获取mask绝对路径
    mask_abs_dir = os.path.join(current_dir, mask_dir)
    #可以选择的两项,包括manga绝对路径和mask绝对路径
    default_values = [manga_abs_dir, mask_abs_dir]



    #需要执行任务的bili 容器space的url
    # bili_space = ['https://rogerxavier-moviepy-with-manga-test.hf.space'
    #               ,'https://rogerxavier-moviepy-with-manga-bili-2.hf.space'
    # ]

    #不能加下划线,因为后面拼接的时候加了一个 且必须https
    bili_spaces = ['https://rogerxavier-moviepy-with-manga-test.hf.space'
    ]

    # 构造函数获取当前目录file list信息-不放config进行返回是为了避免引入旧值
    def update_file_info(root_dir):
        info = {}
        for root, dirs, files in os.walk(root_dir):
            info[root] = {
                "directories": dirs,
                "files": files
            }
            for dir_name in dirs:
                update_file_info(os.path.join(root, dir_name))
        return info

    file_info = update_file_info(current_dir)

    return {
        "allow_scheduler": allow_scheduler,
        "manga_dir": manga_dir,
        "mask_dir": mask_dir,
        "manga_abs_dir": manga_abs_dir,
        "mask_abs_dir": mask_abs_dir,
        "default_values": default_values,
        "bili_spaces": bili_spaces,
        "current_config_json":current_config_json,
        "current_dir":current_dir,
        "file_info": file_info,#这个在多个地方用到
        "allow_submit":allow_submit,
        "default_chapter_delete":default_chapter_delete
    }



from utils import * #写在这里防止循环引用的时候utils中导入manga_abs_dir出错