refactor(system cli): 统一命名风格并新增图标缓存重置工具
1. 将系统任务的大写命名改为蛇形命名:CLR→clr, SETENV→setenv, WHICH→which 2. 更新对应cli工具的导入和调用代码 3. 新增restart_icon_cache命令行工具和reset_icon_cache系统任务
This commit is contained in:
@@ -6,10 +6,10 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import pyflowx as px
|
import pyflowx as px
|
||||||
from pyflowx.tasks.system import CLR
|
from pyflowx.tasks.system import clr
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""清屏工具主函数."""
|
"""清屏工具主函数."""
|
||||||
graph = px.Graph.from_specs([CLR()])
|
graph = px.Graph.from_specs([clr()])
|
||||||
px.run(graph, strategy="thread")
|
px.run(graph, strategy="thread")
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from pathlib import Path
|
|||||||
from typing import Literal, get_args
|
from typing import Literal, get_args
|
||||||
|
|
||||||
import pyflowx as px
|
import pyflowx as px
|
||||||
from pyflowx.tasks.system import SETENV
|
from pyflowx.tasks.system import setenv
|
||||||
|
|
||||||
HFDownloadType = Literal["model", "dataset", "space"]
|
HFDownloadType = Literal["model", "dataset", "space"]
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ def main():
|
|||||||
download_dir.mkdir(parents=True, exist_ok=True)
|
download_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
graph = px.Graph.from_specs([
|
graph = px.Graph.from_specs([
|
||||||
SETENV("HF_ENDPOINT", "https://hf-mirror.com"),
|
setenv("HF_ENDPOINT", "https://hf-mirror.com"),
|
||||||
px.TaskSpec(
|
px.TaskSpec(
|
||||||
name="download",
|
name="download",
|
||||||
cmd=[
|
cmd=[
|
||||||
|
|||||||
@@ -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")
|
||||||
@@ -8,7 +8,7 @@ from __future__ import annotations
|
|||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
import pyflowx as px
|
import pyflowx as px
|
||||||
from pyflowx.tasks.system import WHICH
|
from pyflowx.tasks.system import which
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
@@ -17,5 +17,5 @@ def main() -> None:
|
|||||||
parser.add_argument("commands", nargs="+", help="要查找的命令名称, 如: python ls ps gcc...")
|
parser.add_argument("commands", nargs="+", help="要查找的命令名称, 如: python ls ps gcc...")
|
||||||
args = parser.parse_args()
|
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")
|
px.run(graph, strategy="thread")
|
||||||
|
|||||||
@@ -13,13 +13,35 @@ import pyflowx as px
|
|||||||
from pyflowx.conditions import Constants
|
from pyflowx.conditions import Constants
|
||||||
|
|
||||||
|
|
||||||
def CLR():
|
def clr():
|
||||||
"""清屏任务."""
|
"""清屏任务."""
|
||||||
cmd = ["cls"] if Constants.IS_WINDOWS else ["clear"]
|
cmd = ["cls"] if Constants.IS_WINDOWS else ["clear"]
|
||||||
return px.TaskSpec("clear_screen", fn=lambda: subprocess.run(cmd, check=False))
|
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():
|
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)
|
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"
|
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)
|
return px.TaskSpec(f"which_{cmd}", fn=find_command)
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["CLR", "SETENV", "WHICH"]
|
__all__ = ["clr", "setenv", "which"]
|
||||||
|
|||||||
Reference in New Issue
Block a user