bitool 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bitool/__init__.py +27 -0
- bitool/cmd/__init__.py +65 -0
- bitool/cmd/_base.py +105 -0
- bitool/cmd/_condition.py +60 -0
- bitool/cmd/_scheduler.py +548 -0
- bitool/cmd/env.py +454 -0
- bitool/cmd/git.py +123 -0
- bitool/cmd/io.py +248 -0
- bitool/cmd/pdf.py +385 -0
- bitool/cmd/run.py +300 -0
- bitool/cmd/toml.py +237 -0
- bitool/cmd/version.py +630 -0
- bitool/consts.py +14 -0
- bitool/core/__init__.py +7 -0
- bitool/core/app.py +142 -0
- bitool/core/commands.py +194 -0
- bitool/core/config.py +647 -0
- bitool/core/env.py +18 -0
- bitool/core/logger.py +237 -0
- bitool/core/plugin.py +117 -0
- bitool/core/workspace.py +76 -0
- bitool/models/__init__.py +3 -0
- bitool/models/version.py +173 -0
- bitool/scripts/__init__.py +1 -0
- bitool/scripts/bumpversion.py +189 -0
- bitool/scripts/clearscreen.py +37 -0
- bitool/scripts/envpy.py +161 -0
- bitool/scripts/envrs.py +119 -0
- bitool/scripts/filedate.py +246 -0
- bitool/scripts/filelevel.py +191 -0
- bitool/scripts/gittool.py +178 -0
- bitool/scripts/img2pdf.py +151 -0
- bitool/scripts/pdf2img.py +139 -0
- bitool/scripts/piptool.py +130 -0
- bitool/scripts/pymake.py +345 -0
- bitool/scripts/sshcopyid.py +491 -0
- bitool/scripts/taskkill.py +366 -0
- bitool/scripts/which.py +227 -0
- bitool/types.py +7 -0
- bitool/utils/__init__.py +9 -0
- bitool/utils/cli_parser.py +412 -0
- bitool/utils/executor.py +881 -0
- bitool/utils/profiler.py +369 -0
- bitool/utils/task.py +133 -0
- bitool/utils/task_group.py +668 -0
- bitool/utils/tests/__init__.py +0 -0
- bitool/utils/tests/test_profiler.py +487 -0
- bitool-0.1.2.dist-info/METADATA +154 -0
- bitool-0.1.2.dist-info/RECORD +51 -0
- bitool-0.1.2.dist-info/WHEEL +4 -0
- bitool-0.1.2.dist-info/entry_points.txt +15 -0
bitool/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Bitool Maturin - Rust + Python 混合架构工具集."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.1.2"
|
|
4
|
+
__author__ = "gooker_young"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from .cmd._scheduler import CommandScheduler
|
|
8
|
+
from .consts import Constants
|
|
9
|
+
from .core.app import BitoolApp
|
|
10
|
+
from .core.commands import CommandCategory, CommandExecutor, CommandRegistry
|
|
11
|
+
from .core.plugin import Plugin, PluginContext, PluginRegistry
|
|
12
|
+
from .core.workspace import WorkspaceManager
|
|
13
|
+
from .utils.profiler import profile
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"BitoolApp",
|
|
17
|
+
"CommandCategory",
|
|
18
|
+
"CommandExecutor",
|
|
19
|
+
"CommandRegistry",
|
|
20
|
+
"CommandScheduler",
|
|
21
|
+
"Constants",
|
|
22
|
+
"Plugin",
|
|
23
|
+
"PluginContext",
|
|
24
|
+
"PluginRegistry",
|
|
25
|
+
"WorkspaceManager",
|
|
26
|
+
"profile",
|
|
27
|
+
]
|
bitool/cmd/__init__.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from ._base import BaseCommand
|
|
2
|
+
from ._condition import BuiltinConditions, Condition
|
|
3
|
+
from ._scheduler import CommandResult, CommandScheduler, SchedulerMetrics
|
|
4
|
+
from .env import SetEnvCommand
|
|
5
|
+
from .git import GitAddCommand, GitCommitCommand, GitTagCommand
|
|
6
|
+
from .io import WriteFileCommand
|
|
7
|
+
from .pdf import (
|
|
8
|
+
CompressPdfCommand,
|
|
9
|
+
ImagesToPdfCommand,
|
|
10
|
+
MergePdfsCommand,
|
|
11
|
+
PdfToImagesCommand,
|
|
12
|
+
SplitPdfCommand,
|
|
13
|
+
)
|
|
14
|
+
from .run import (
|
|
15
|
+
RunCommand,
|
|
16
|
+
RunDAGCommands,
|
|
17
|
+
RunParallelCommands,
|
|
18
|
+
RunSequentialCommands,
|
|
19
|
+
RunShellCommand,
|
|
20
|
+
)
|
|
21
|
+
from .toml import (
|
|
22
|
+
ReadTomlCommand,
|
|
23
|
+
ReadTomlVersionCommand,
|
|
24
|
+
UpdateTomlVersionCommand,
|
|
25
|
+
WriteTomlCommand,
|
|
26
|
+
)
|
|
27
|
+
from .version import (
|
|
28
|
+
BumpFileVersionCommand,
|
|
29
|
+
BumpProjectVersionCommand,
|
|
30
|
+
ReadTextVersionCommand,
|
|
31
|
+
UpdateTextVersionCommand,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
__all__ = [
|
|
35
|
+
"BaseCommand",
|
|
36
|
+
"BuiltinConditions",
|
|
37
|
+
"BumpFileVersionCommand",
|
|
38
|
+
"BumpProjectVersionCommand",
|
|
39
|
+
"CommandResult",
|
|
40
|
+
"CommandScheduler",
|
|
41
|
+
"CompressPdfCommand",
|
|
42
|
+
"Condition",
|
|
43
|
+
"GitAddCommand",
|
|
44
|
+
"GitCommitCommand",
|
|
45
|
+
"GitTagCommand",
|
|
46
|
+
"ImagesToPdfCommand",
|
|
47
|
+
"MergePdfsCommand",
|
|
48
|
+
"PdfToImagesCommand",
|
|
49
|
+
"PdfToTextCommand",
|
|
50
|
+
"ReadTextVersionCommand",
|
|
51
|
+
"ReadTomlCommand",
|
|
52
|
+
"ReadTomlVersionCommand",
|
|
53
|
+
"RunCommand",
|
|
54
|
+
"RunDAGCommands",
|
|
55
|
+
"RunParallelCommands",
|
|
56
|
+
"RunSequentialCommands",
|
|
57
|
+
"RunShellCommand",
|
|
58
|
+
"SchedulerMetrics",
|
|
59
|
+
"SetEnvCommand",
|
|
60
|
+
"SplitPdfCommand",
|
|
61
|
+
"UpdateTextVersionCommand",
|
|
62
|
+
"UpdateTomlVersionCommand",
|
|
63
|
+
"WriteFileCommand",
|
|
64
|
+
"WriteTomlCommand",
|
|
65
|
+
]
|
bitool/cmd/_base.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import abstractmethod
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from typing import Callable
|
|
6
|
+
|
|
7
|
+
from bitool.cmd._condition import Condition
|
|
8
|
+
from bitool.core import logger
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class BaseCommand:
|
|
13
|
+
"""命令基类.
|
|
14
|
+
|
|
15
|
+
提供命令的基础功能,包括条件检查、依赖管理和执行控制.
|
|
16
|
+
所有自定义命令应继承此类并实现 run 方法.
|
|
17
|
+
|
|
18
|
+
Attributes:
|
|
19
|
+
name: 命令名称,用于标识和日志输出.
|
|
20
|
+
description: 命令描述信息.
|
|
21
|
+
allow_conditions: 允许条件列表,所有条件满足时命令才会执行.
|
|
22
|
+
forbid_conditions: 禁止条件列表,任一条件满足时命令不会执行.
|
|
23
|
+
dependencies: 依赖的命令名称列表.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
name: str = "base"
|
|
27
|
+
description: str = "base command"
|
|
28
|
+
allow_conditions: list[Condition | tuple[Callable[[], bool], str]] = field(
|
|
29
|
+
default_factory=list
|
|
30
|
+
)
|
|
31
|
+
forbid_conditions: list[Condition | tuple[Callable[[], bool], str]] = field(
|
|
32
|
+
default_factory=list
|
|
33
|
+
)
|
|
34
|
+
dependencies: list[str] = field(default_factory=list)
|
|
35
|
+
|
|
36
|
+
def __post_init__(self) -> None:
|
|
37
|
+
"""数据类初始化后的处理.
|
|
38
|
+
|
|
39
|
+
将传入的 tuple 或 Condition 对象统一转换为 Condition 对象.
|
|
40
|
+
"""
|
|
41
|
+
# 将传入的 tuple 或 Condition 对象统一转换为 Condition 对象
|
|
42
|
+
self.allow_conditions = [Condition.from_data(c) for c in self.allow_conditions]
|
|
43
|
+
self.forbid_conditions = [
|
|
44
|
+
Condition.from_data(c) for c in self.forbid_conditions
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
@abstractmethod
|
|
48
|
+
def run(self) -> bool:
|
|
49
|
+
"""运行命令.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
命令执行是否成功.
|
|
53
|
+
|
|
54
|
+
Raises:
|
|
55
|
+
NotImplementedError: 子类必须实现此方法.
|
|
56
|
+
"""
|
|
57
|
+
raise NotImplementedError
|
|
58
|
+
|
|
59
|
+
def validate_and_run(self) -> bool:
|
|
60
|
+
"""检查条件并运行命令.
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
命令执行是否成功.如果条件不满足则返回 False.
|
|
64
|
+
"""
|
|
65
|
+
if self.validate():
|
|
66
|
+
return self.run()
|
|
67
|
+
|
|
68
|
+
return False
|
|
69
|
+
|
|
70
|
+
def validate(self) -> bool:
|
|
71
|
+
"""检查命令是否可以运行.
|
|
72
|
+
|
|
73
|
+
验证允许条件和禁止条件:
|
|
74
|
+
- 所有允许条件必须满足
|
|
75
|
+
- 任何禁止条件都不能满足
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
是否满足执行条件.
|
|
79
|
+
"""
|
|
80
|
+
allow_results = [
|
|
81
|
+
(c.func(), c.reason)
|
|
82
|
+
for c in self.allow_conditions
|
|
83
|
+
if isinstance(c, Condition)
|
|
84
|
+
]
|
|
85
|
+
forbid_results = [
|
|
86
|
+
(c.func(), c.reason)
|
|
87
|
+
for c in self.forbid_conditions
|
|
88
|
+
if isinstance(c, Condition)
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
# 检查允许条件:所有条件都必须满足
|
|
92
|
+
if not all(r for r, _ in allow_results):
|
|
93
|
+
logger.warning(
|
|
94
|
+
f"命令`{self.__class__!s}`条件不满足,跳过执行, 不满足项: {[reason for r, reason in allow_results if not r]}"
|
|
95
|
+
)
|
|
96
|
+
return False
|
|
97
|
+
|
|
98
|
+
# 检查禁止条件:任何条件都不应满足
|
|
99
|
+
if any(r for r, _ in forbid_results):
|
|
100
|
+
logger.warning(
|
|
101
|
+
f"命令`{self.__class__!s}`条件不满足,跳过执行, 禁止项: {[reason for r, reason in forbid_results if r]}"
|
|
102
|
+
)
|
|
103
|
+
return False
|
|
104
|
+
|
|
105
|
+
return True
|
bitool/cmd/_condition.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from shutil import which
|
|
6
|
+
from typing import Callable
|
|
7
|
+
|
|
8
|
+
from bitool.consts import Constants
|
|
9
|
+
|
|
10
|
+
__all__ = ["Condition"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class Condition:
|
|
15
|
+
"""命令条件类"""
|
|
16
|
+
|
|
17
|
+
func: Callable[[], bool]
|
|
18
|
+
reason: str = "未知原因"
|
|
19
|
+
|
|
20
|
+
@classmethod
|
|
21
|
+
def from_data(cls, data: tuple[Callable[[], bool], str] | Condition) -> Condition:
|
|
22
|
+
"""从 tuple 或 Condition 对象创建 Condition 实例."""
|
|
23
|
+
if isinstance(data, Condition):
|
|
24
|
+
return data
|
|
25
|
+
return cls(func=data[0], reason=data[1])
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class BuiltinConditions:
|
|
29
|
+
"""内置条件类"""
|
|
30
|
+
|
|
31
|
+
IS_WINDOWS = Condition(lambda: Constants.IS_WINDOWS, "当前系统是 Windows")
|
|
32
|
+
IS_UNIX = Condition(lambda: Constants.IS_UNIX, "当前系统是 Unix")
|
|
33
|
+
|
|
34
|
+
@staticmethod
|
|
35
|
+
def HAS_APP_INSTALLED(app: str) -> Condition:
|
|
36
|
+
"""检查系统中是否已安装指定应用.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
app: 应用程序名称.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
Condition实例.
|
|
43
|
+
"""
|
|
44
|
+
return Condition(lambda: which(app) is not None, f"{app} 已安装")
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def HAS_ENTRY_IN_DIR(entry: str, directory: Path) -> Condition:
|
|
48
|
+
"""检查系统路径中是否包含指定条目.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
entry: 条目名称.
|
|
52
|
+
directory: 目录路径.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
Condition实例.
|
|
56
|
+
"""
|
|
57
|
+
return Condition(
|
|
58
|
+
lambda: entry.lower() in [f.name.lower() for f in directory.iterdir()],
|
|
59
|
+
f"{entry} 在 {directory} 中",
|
|
60
|
+
)
|