From 3ebc89dfeb77cf90b1760fbb17780bf896681b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=90=91=E5=A4=9C?= Date: Thu, 18 Jan 2024 21:11:29 +0800 Subject: [PATCH] :recycle: refactor(const): refact const vars --- src/ipm/__init__.py | 4 ++-- src/ipm/api.py | 6 +++--- src/ipm/const.py | 3 ++- src/ipm/utils/loader.py | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ipm/__init__.py b/src/ipm/__init__.py index 9ebcc2d..d72a4e9 100644 --- a/src/ipm/__init__.py +++ b/src/ipm/__init__.py @@ -1,8 +1,8 @@ -from .api import install, extract, build +from .api import install, extract, build, uninstall, init, new __author__ = "苏向夜 " __organization__ = ( "Noctisynth", "HydroRoll-Team", ) -__all__ = ["install", "extract", "build"] +__all__ = ["install", "extract", "build", "uninstall", "init", "new"] diff --git a/src/ipm/api.py b/src/ipm/api.py index 2cb6eee..ea55afb 100644 --- a/src/ipm/api.py +++ b/src/ipm/api.py @@ -3,7 +3,7 @@ from .utils import freeze, urlparser, loader from .models.ipk import InfiniPackage, InfiniFrozenPackage from .exceptions import FileTypeMismatch, TomlLoadFailed, FileNotFoundError -from .const import INDEX, HOME +from .const import INDEX, SRC_HOME from .logging import info, success, warning, error import toml @@ -67,7 +67,7 @@ def extract( def install(uri: str, index: str = "", echo: bool = False) -> None: info("正在初始化 IPM 环境...", echo) - HOME.mkdir(parents=True, exist_ok=True) + SRC_HOME.mkdir(parents=True, exist_ok=True) index = index or INDEX if uri.isalpha(): @@ -87,7 +87,7 @@ def install(uri: str, index: str = "", echo: bool = False) -> None: if uri.endswith(".ipk"): info("安装中...", echo) - ipk = extract(Path(uri).resolve(), HOME, echo) + ipk = extract(Path(uri).resolve(), SRC_HOME, echo) else: raise FileTypeMismatch("文件类型与预期[.ipk]不匹配.") diff --git a/src/ipm/const.py b/src/ipm/const.py index d31b10a..439903a 100644 --- a/src/ipm/const.py +++ b/src/ipm/const.py @@ -5,7 +5,8 @@ # 初始化参数 INDEX = "https://ipm.hydroroll.team/index/" -HOME = Path.home() / ".ipm" / "src" +IPM_PATH = Path.home() / ".ipm" +SRC_HOME = IPM_PATH / "src" # 文本参数 ATTENSION = """# This file is @generated by IPM. diff --git a/src/ipm/utils/loader.py b/src/ipm/utils/loader.py index 41b19f9..6c1bf25 100644 --- a/src/ipm/utils/loader.py +++ b/src/ipm/utils/loader.py @@ -1,6 +1,6 @@ from pathlib import Path from .freeze import extract_ipk -from ..const import HOME +from ..const import SRC_HOME from ..models.ipk import InfiniPackage import requests @@ -22,6 +22,6 @@ def load(name: str, baseurl: str = "", filename: str = "") -> InfiniPackage: hash_file.write(hash_bytes) hash_file.close() - ipk = extract_ipk(ipk_file, HOME) + ipk = extract_ipk(ipk_file, SRC_HOME) temp_dir.cleanup() return ipk