From bfe2f29574935eda7ad518955910650ac1897b4a Mon Sep 17 00:00:00 2001 From: Fushinn Date: Fri, 19 Jan 2024 12:54:37 +0800 Subject: [PATCH] =?UTF-8?q?0.9.8.6=20#####=201.=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ##### --- core/config.py | 4 ++++ core/models.py | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/config.py b/core/config.py index 6ceb2b3..48b274b 100644 --- a/core/config.py +++ b/core/config.py @@ -35,6 +35,10 @@ 'get_docker_shell_command': 'curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh' } +# 如果目录不存在,创建它 +if not os.path.exists(os.path.dirname(config_path)): + os.makedirs(os.path.dirname(config_path)) + # 如果存在,尝试打开文件并读取值 if os.path.exists(config_path): try: diff --git a/core/models.py b/core/models.py index aea8f41..91707b0 100644 --- a/core/models.py +++ b/core/models.py @@ -85,7 +85,13 @@ class Config: SECRET_KEY = token_hex(16) SQLALCHEMY_TRACK_MODIFICATIONS = False prefix = 'sqlite:///' - SQLALCHEMY_DATABASE_URI = prefix + os.path.join(os.path.dirname(argv[0]), 'work', 'data.db') + db_dir = os.path.join(os.path.dirname(argv[0]), 'work') + + # 确保数据库目录存在 + if not os.path.exists(db_dir): + os.makedirs(db_dir) + + SQLALCHEMY_DATABASE_URI = prefix + os.path.join(db_dir, 'data.db') ######################### 数据库相关Class结束 #########################