From cfc97fb22d01d40938326484ebd81456c765c709 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Mon, 13 Mar 2023 10:58:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81json=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=20(#265)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- main.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 10cc092c..9df58056 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ sensitive.json temp/ current_tag scenario/ -!scenario/default-template.json \ No newline at end of file +!scenario/default-template.json +override.json \ No newline at end of file diff --git a/main.py b/main.py index 9f868d75..fec0fde7 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import importlib +import json import os import shutil import threading @@ -143,9 +144,22 @@ def main(first_time_init=False): setattr(config, key, getattr(config_template, key)) logging.warning("[{}]不存在".format(key)) is_integrity = False + if not is_integrity: logging.warning("配置文件不完整,请依据config-template.py检查config.py") logging.warning("以上配置已被设为默认值,将在5秒后继续启动... ") + + # 检查override.json覆盖 + if os.path.exists("override.json"): + override_json = json.load(open("override.json", "r", encoding="utf-8")) + for key in override_json: + if hasattr(config, key): + setattr(config, key, override_json[key]) + logging.info("覆写配置[{}]为[{}]".format(key, override_json[key])) + else: + logging.error("无法覆写配置[{}]为[{}],该配置不存在,请检查override.json是否正确".format(key, override_json[key])) + + if not is_integrity: time.sleep(5) import pkg.utils.context