taskManager / config.py
rogerxavier's picture
Update config.py
9cbf490 verified
raw
history blame contribute delete
No virus
2.87 kB
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 = data['bili_spaces']
# 构造函数获取当前目录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出错