From 9e945d1cc0ce2a51080fa7d11a5b1d787bc467f4 Mon Sep 17 00:00:00 2001 From: thepoy Date: Wed, 20 Mar 2024 09:32:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=9B=E5=BB=BA=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=8F=AF=E8=83=BD=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 与图形化软件`up2b`一起使用时,可能会在不存在的`up2b/conf`目录中创建文件而报错。 --- pyproject.toml | 6 +++--- up2b/up2b_lib/constants.py | 4 ++++ up2b/up2b_lib/up2b_api/__init__.py | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b7aeebc..8deae1f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ readme = "README.md" requires-python = ">=3" license = { file = "LICENSE" } classifiers = ["Programming Language :: Python :: 3"] -keywords = ["typora", "image bed", "upload"] +keywords = ["typora", "image bed", "upload", "picture bed", "图床"] dependencies = [ "requests", "click", @@ -45,9 +45,9 @@ write_to = "up2b/version.py" [tool.black] line-length = 88 -target-version = ['py36', 'py37', 'py38', 'py39', 'py310', 'py311'] +target-version = ['py36', 'py37', 'py38', 'py39', 'py310', 'py311', "py312"] include = '\.pyi?$' [tool.pyright] -pythonVersion = '3.11' +pythonVersion = '3.12' venv = 'dev' diff --git a/up2b/up2b_lib/constants.py b/up2b/up2b_lib/constants.py index 0bb386e..61e2b10 100644 --- a/up2b/up2b_lib/constants.py +++ b/up2b/up2b_lib/constants.py @@ -61,5 +61,9 @@ def __str__(self) -> str: os.makedirs(CONFIG_FOLDER_PATH / "conf", 0o755) CONF_FILE = CONFIG_FOLDER_PATH / "conf" / "conf.up2b.json" + +if not CONF_FILE.parent.exists(): + CONF_FILE.parent.mkdir(parents=True) + CACHE_PATH = Path(gettempdir()) / "up2b" CACHE_DATABASE = CONFIG_FOLDER_PATH / "cache.db" diff --git a/up2b/up2b_lib/up2b_api/__init__.py b/up2b/up2b_lib/up2b_api/__init__.py index f6b7ad6..a947798 100644 --- a/up2b/up2b_lib/up2b_api/__init__.py +++ b/up2b/up2b_lib/up2b_api/__init__.py @@ -49,6 +49,7 @@ def choose_image_bed(image_bed_code: int): raise TypeError( "image bed code must be an integer, not %s" % str(type(image_bed_code)) ) + try: with open(CONF_FILE, "r+") as f: conf = json.loads(f.read())