From 374ae25d9c776bf2d3373a3df62c267250231e43 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Sun, 12 Nov 2023 23:16:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=AF=E5=8A=A8=E6=97=B6=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=A7=A3=E5=86=B3=E4=BE=9D=E8=B5=96=E5=90=8E=E4=B8=8D?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E7=9A=84=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 83 +++++++++++++++++++++++---------------------- pkg/utils/pkgmgr.py | 2 +- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/main.py b/main.py index 0f24502c..5d8717da 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,48 @@ sys.path.append(".") from pkg.utils.log import init_runtime_log_file, reset_logging + +def check_file(): + # 检查是否有banlist.py,如果没有就把banlist-template.py复制一份 + if not os.path.exists('banlist.py'): + shutil.copy('res/templates/banlist-template.py', 'banlist.py') + + # 检查是否有sensitive.json + if not os.path.exists("sensitive.json"): + shutil.copy("res/templates/sensitive-template.json", "sensitive.json") + + # 检查是否有scenario/default.json + if not os.path.exists("scenario/default.json"): + shutil.copy("scenario/default-template.json", "scenario/default.json") + + # 检查cmdpriv.json + if not os.path.exists("cmdpriv.json"): + shutil.copy("res/templates/cmdpriv-template.json", "cmdpriv.json") + + # 检查tips_custom + if not os.path.exists("tips.py"): + shutil.copy("tips-custom-template.py", "tips.py") + + # 检查temp目录 + if not os.path.exists("temp/"): + os.mkdir("temp/") + + # 检查并创建plugins、prompts目录 + check_path = ["plugins", "prompts"] + for path in check_path: + if not os.path.exists(path): + os.mkdir(path) + + # 配置文件存在性校验 + if not os.path.exists('config.py'): + shutil.copy('config-template.py', 'config.py') + print('请先在config.py中填写配置') + sys.exit(0) + + +# 初始化相关文件 +check_file() + try: import colorlog except ImportError: @@ -367,53 +409,12 @@ def stop(): raise e -def check_file(): - # 检查是否有banlist.py,如果没有就把banlist-template.py复制一份 - if not os.path.exists('banlist.py'): - shutil.copy('res/templates/banlist-template.py', 'banlist.py') - - # 检查是否有sensitive.json - if not os.path.exists("sensitive.json"): - shutil.copy("res/templates/sensitive-template.json", "sensitive.json") - - # 检查是否有scenario/default.json - if not os.path.exists("scenario/default.json"): - shutil.copy("scenario/default-template.json", "scenario/default.json") - - # 检查cmdpriv.json - if not os.path.exists("cmdpriv.json"): - shutil.copy("res/templates/cmdpriv-template.json", "cmdpriv.json") - - # 检查tips_custom - if not os.path.exists("tips.py"): - shutil.copy("tips-custom-template.py", "tips.py") - - # 检查temp目录 - if not os.path.exists("temp/"): - os.mkdir("temp/") - - # 检查并创建plugins、prompts目录 - check_path = ["plugins", "prompts"] - for path in check_path: - if not os.path.exists(path): - os.mkdir(path) - - # 配置文件存在性校验 - if not os.path.exists('config.py'): - shutil.copy('config-template.py', 'config.py') - print('请先在config.py中填写配置') - sys.exit(0) - - def main(): global use_override # 检查是否携带了 --override 或 -r 参数 if '--override' in sys.argv or '-r' in sys.argv: use_override = True - # 初始化相关文件 - check_file() - # 初始化logging init_runtime_log_file() pkg.utils.context.context['logger_handler'] = reset_logging() diff --git a/pkg/utils/pkgmgr.py b/pkg/utils/pkgmgr.py index 5ddfefe3..42dc67bf 100644 --- a/pkg/utils/pkgmgr.py +++ b/pkg/utils/pkgmgr.py @@ -19,7 +19,7 @@ def run_pip(params: list): def install_requirements(file): - pipmain(['install', '-r', file, "--upgrade", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple", + pipmain(['install', '-r', file, "-i", "https://pypi.tuna.tsinghua.edu.cn/simple", "--trusted-host", "pypi.tuna.tsinghua.edu.cn"]) log.reset_logging()