diff --git a/src/pyflowx/cli/clearscreen.py b/src/pyflowx/cli/clearscreen.py index 34a274d..1670a4c 100644 --- a/src/pyflowx/cli/clearscreen.py +++ b/src/pyflowx/cli/clearscreen.py @@ -6,10 +6,10 @@ from __future__ import annotations import pyflowx as px -from pyflowx.tasks.system import CLR +from pyflowx.tasks.system import clr def main() -> None: """清屏工具主函数.""" - graph = px.Graph.from_specs([CLR()]) + graph = px.Graph.from_specs([clr()]) px.run(graph, strategy="thread") diff --git a/src/pyflowx/cli/hfdownload.py b/src/pyflowx/cli/hfdownload.py index 389c30a..6ca3ed4 100644 --- a/src/pyflowx/cli/hfdownload.py +++ b/src/pyflowx/cli/hfdownload.py @@ -3,7 +3,7 @@ from pathlib import Path from typing import Literal, get_args import pyflowx as px -from pyflowx.tasks.system import SETENV +from pyflowx.tasks.system import setenv HFDownloadType = Literal["model", "dataset", "space"] @@ -30,7 +30,7 @@ def main(): download_dir.mkdir(parents=True, exist_ok=True) graph = px.Graph.from_specs([ - SETENV("HF_ENDPOINT", "https://hf-mirror.com"), + setenv("HF_ENDPOINT", "https://hf-mirror.com"), px.TaskSpec( name="download", cmd=[ diff --git a/src/pyflowx/cli/restarticoncache.py b/src/pyflowx/cli/restarticoncache.py new file mode 100644 index 0000000..bb6bdd7 --- /dev/null +++ b/src/pyflowx/cli/restarticoncache.py @@ -0,0 +1,10 @@ +from __future__ import annotations + +import pyflowx as px +from pyflowx.tasks.system import reset_icon_cache + + +def main() -> None: + """重启图标缓存工具主函数.""" + graph = px.Graph.from_specs(reset_icon_cache()) + px.run(graph, strategy="thread") diff --git a/src/pyflowx/cli/which.py b/src/pyflowx/cli/which.py index ff40fb3..7dabe2e 100644 --- a/src/pyflowx/cli/which.py +++ b/src/pyflowx/cli/which.py @@ -8,7 +8,7 @@ from __future__ import annotations import argparse import pyflowx as px -from pyflowx.tasks.system import WHICH +from pyflowx.tasks.system import which def main() -> None: @@ -17,5 +17,5 @@ def main() -> None: parser.add_argument("commands", nargs="+", help="要查找的命令名称, 如: python ls ps gcc...") args = parser.parse_args() - graph = px.Graph.from_specs([WHICH(cmd) for cmd in args.commands]) + graph = px.Graph.from_specs([which(cmd) for cmd in args.commands]) px.run(graph, strategy="thread") diff --git a/src/pyflowx/tasks/system.py b/src/pyflowx/tasks/system.py index 11a6a84..b431822 100644 --- a/src/pyflowx/tasks/system.py +++ b/src/pyflowx/tasks/system.py @@ -13,13 +13,35 @@ import pyflowx as px from pyflowx.conditions import Constants -def CLR(): +def clr(): """清屏任务.""" cmd = ["cls"] if Constants.IS_WINDOWS else ["clear"] return px.TaskSpec("clear_screen", fn=lambda: subprocess.run(cmd, check=False)) -def SETENV(name: str, value: str, default: bool = False): +def reset_icon_cache() -> list[px.TaskSpec]: + """重置图标缓存任务.""" + if not Constants.IS_WINDOWS: + print("reset_icon_cache: 仅在 Windows 上支持") + return [] + + return [ + px.TaskSpec("kill_explorer", fn=lambda: subprocess.run(["taskkill", "/f", "/im", "explorer.exe"], check=False)), + px.TaskSpec( + "delete_icon_cache", + fn=lambda: subprocess.run(["del", "/a", "/q", r"%localappdata%\IconCache.db"], check=False), + ), + px.TaskSpec( + "delete_icon_cache_all", + fn=lambda: subprocess.run( + ["del", "/a", "/q", r"%localappdata%\Microsoft\Windows\Explorer\iconcache*"], check=False + ), + ), + px.TaskSpec("restart_explorer", fn=lambda: subprocess.run(["start", "explorer.exe"], check=False)), + ] + + +def setenv(name: str, value: str, default: bool = False): """设置环境变量任务.""" def set_env(): @@ -31,7 +53,7 @@ def SETENV(name: str, value: str, default: bool = False): return px.TaskSpec(f"setenv_{name.lower()}", fn=set_env, verbose=True) -def WHICH(cmd: str): +def which(cmd: str): """查找命令路径任务.""" which_cmd = "where" if Constants.IS_WINDOWS else "which" @@ -48,4 +70,4 @@ def WHICH(cmd: str): return px.TaskSpec(f"which_{cmd}", fn=find_command) -__all__ = ["CLR", "SETENV", "WHICH"] +__all__ = ["clr", "setenv", "which"]