This commit is contained in:
2026-06-21 21:11:07 +08:00
parent 2d0873af45
commit 6a004a54b9
3 changed files with 50 additions and 1 deletions
+48
View File
@@ -0,0 +1,48 @@
"""Git 工具模块.
提供 Git 仓库管理的常用操作封装,
支持初始化、提交、清理、推送等功能.
"""
from __future__ import annotations
import os
from pathlib import Path
import pyflowx as px
def init_sub_dirs() -> None:
"""初始化子目录的Git仓库."""
origin = Path.cwd()
sub_dirs = [subdir for subdir in Path.cwd().iterdir() if subdir.is_dir()]
for subdir in sub_dirs:
os.chdir(str(subdir))
_ = px.run(
[
["git", "init"],
["git", "add", "."],
["git", "commit", "-m", "init commit"],
],
)
os.chdir(str(origin))
push: px.TaskSpec = px.TaskSpec("push", cmd=["git", "push"])
pull: px.TaskSpec = px.TaskSpec("pull", cmd=["git", "pull"])
kill_tgit: px.TaskSpec = px.TaskSpec("task_kill", cmd=["taskkill", "/f", "/t", "/im", "tgitcache.exe"])
def main() -> None:
"""Git工具主函数."""
runner = px.CliRunner(
strategy="thread",
description="Gittool - Git 执行工具.",
graphs={
"isub": px.Graph.from_specs([px.TaskSpec("isub", fn=init_sub_dirs)]),
"p": px.Graph.from_specs([push]),
"pl": px.Graph.from_specs([pull]),
"r": px.Graph.from_specs([kill_tgit]),
},
)
runner.run_cli()