diff options
| author | 2024-01-21 22:48:03 +0800 | |
|---|---|---|
| committer | 2024-01-21 22:48:03 +0800 | |
| commit | d8eecb0f3f76c62c0caa8889ffe046b5d71dd179 (patch) | |
| tree | 56bd475b6df27d2f3d2f66db68057ac3d4588392 | |
| parent | 8b76d593b0bd59bc6a74dc9f48b7b70dbf6a0808 (diff) | |
| download | ipm-d8eecb0f3f76c62c0caa8889ffe046b5d71dd179.tar.gz ipm-d8eecb0f3f76c62c0caa8889ffe046b5d71dd179.zip | |
:sparkles: feat(api): add uninstall method
| -rw-r--r-- | src/ipm/__main__.py | 9 | ||||
| -rw-r--r-- | src/ipm/api.py | 25 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/ipm/__main__.py b/src/ipm/__main__.py index 753c3a7..c732163 100644 --- a/src/ipm/__main__.py +++ b/src/ipm/__main__.py @@ -59,5 +59,14 @@ def build(package: str = typer.Argument(".", help="Infini 项目路径")): logger.error(error) +@main.command() +def uninstall(package: str = typer.Argument(help="Infini 项目路径")): + """卸载 Infini 规则包""" + try: + api.uninstall(package, echo=True) + except IpmException as error: + logger.error(error) + + if __name__ == "__main__": main() diff --git a/src/ipm/api.py b/src/ipm/api.py index 82f9aae..25f9595 100644 --- a/src/ipm/api.py +++ b/src/ipm/api.py @@ -8,6 +8,7 @@ from .const import INDEX, STORAGE, SRC_HOME from .logging import info, success, warning, error import toml +import shutil def init(source_path: StrPath, force: bool = False, echo: bool = False) -> None: @@ -105,5 +106,25 @@ def install(uri: str, index: str = "", echo: bool = False) -> None: success(f"包[{ipk.name}]成功安装在[{ipk.source_path}].", echo) -def uninstall(ipk: str | InfiniProject): - ... +def uninstall(name: str, confirm: bool = False, echo: bool = False) -> None: + lock = PackageLock() + path = SRC_HOME / name.strip() + + if not (install_info := lock.get_ipk(name)): + return warning(f"由于[{name}]未被安装, 故忽略卸载操作.", echo) + + info(f"发现已经安装的[{name}]版本[{install_info['version']}]:", echo) + info(f" 将会清理: {path}", echo) + # TODO: 拆分安装lock和安装ipk的lock + confirm: bool = ( + True + if (input("你确定要继续 (Y/n) ").upper() in ("", "Y") if not confirm else confirm) + else False + ) + if confirm: + shutil.rmtree(SRC_HOME / name, ignore_errors=True) + else: + return info("忽略.", echo) + + lock.remove(name, dump=True) + success(f"规则包[{name}]卸载完成!", echo) |
