From f88496023f823bdc93b012706a0953422e336e37 Mon Sep 17 00:00:00 2001 From: ikun <132731393+ikun0014@users.noreply.github.com> Date: Thu, 22 Feb 2024 18:45:13 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=8A=8A=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=94=9F=E6=88=90=E7=9A=84=E5=9C=B0=E6=96=B9=E6=8D=A2?= =?UTF-8?q?=E4=B8=AA=E4=BD=8D=E7=BD=AE=EF=BC=8C=E5=AF=B9Docker=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=9B=B4=E5=8F=8B=E5=A5=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ps: Docker只能挂载目录,所以更友好 --- common/config.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/config.py b/common/config.py index a52f58d..8ad7991 100644 --- a/common/config.py +++ b/common/config.py @@ -26,7 +26,7 @@ local_data = threading.local() def get_data_connection(): # 检查线程本地存储对象是否存在连接对象,如果不存在则创建一个新的连接对象 if not hasattr(local_data, 'connection'): - local_data.connection = sqlite3.connect('data.db') + local_data.connection = sqlite3.connect('./data/data.db') return local_data.connection @@ -37,7 +37,7 @@ local_cache = threading.local() def get_cache_connection(): # 检查线程本地存储对象是否存在连接对象,如果不存在则创建一个新的连接对象 if not hasattr(local_cache, 'connection'): - local_cache.connection = sqlite3.connect('cache.db') + local_cache.connection = sqlite3.connect('./data/cache.db') return local_cache.connection @@ -320,7 +320,7 @@ default = { def handle_default_config(): - with open("./config.json", "w", encoding="utf-8") as f: + with open("./data/config.json", "w", encoding="utf-8") as f: f.write(json.dumps(default, indent=2, ensure_ascii=False, escape_forward_slashes=False)) f.close() @@ -512,7 +512,7 @@ def push_to_list(key, obj): def write_config(key, value): config = None - with open('config.json', 'r', encoding='utf-8') as f: + with open('./data/config.json', 'r', encoding='utf-8') as f: config = json.load(f) keys = key.split('.') @@ -524,7 +524,7 @@ def write_config(key, value): current[keys[-1]] = value variable.config = config - with open('config.json', 'w', encoding='utf-8') as f: + with open('./data/config.json', 'w', encoding='utf-8') as f: json.dump(config, f, indent=2, ensure_ascii=False, escape_forward_slashes=False) f.close() @@ -621,18 +621,18 @@ def write_data(key, value): def initConfig(): try: - with open("./config.json", "r", encoding="utf-8") as f: + with open("./data/config.json", "r", encoding="utf-8") as f: try: variable.config = json.loads(f.read()) if (not isinstance(variable.config, dict)): logger.warning('配置文件并不是一个有效的字典,使用默认值') variable.config = default - with open("./config.json", "w", encoding="utf-8") as f: + with open("./data/config.json", "w", encoding="utf-8") as f: f.write(json.dumps(variable.config, indent=2, ensure_ascii=False, escape_forward_slashes=False)) f.close() except: - if os.path.getsize("./config.json") != 0: + if os.path.getsize("./data/config.json") != 0: logger.error("配置文件加载失败,请检查是否遵循JSON语法规范") sys.exit(1) else: