From fc7d0c5d757a3606e63758b6b36528e5995d3275 Mon Sep 17 00:00:00 2001 From: helloplhm-qwq Date: Fri, 1 Dec 2023 19:03:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit common.debug_mode & common.log_length_limit 这gunpg怎么老抽风 --- common/variable.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/common/variable.py b/common/variable.py index 698d9f9..779a801 100644 --- a/common/variable.py +++ b/common/variable.py @@ -9,10 +9,37 @@ # Do not edit except you know what you are doing. import os +import ujson as json +def _read_config_file(): + try: + with open("./config.json", "r", encoding = "utf-8") as f: + return json.load(f) + except: + pass -debug_mode = True -log_length_limit = 100000 +def _read_config(key): + try: + config = _read_config_file() + keys = key.split('.') + value = config + for k in keys: + if isinstance(value, dict): + if k not in value and keys.index(k) != len(keys) - 1: + value[k] = {} + elif k not in value and keys.index(k) == len(keys) - 1: + value = None + value = value[k] + else: + value = None + break + + return value + except: + return None + +debug_mode = _read_config("common.debug_mode") +log_length_limit = _read_config("common.log_length_limit") running = True config = {} workdir = os.getcwd()