taolib.remote#

远端 SSH 自动化接口集合。

提供 SSH 配置读取/脱敏、prefix 上下文管理与远端探测接口(可注入 connection_factory 便于测试)。 更完整的使用说明见文档:doc/libs/python/Fabric/taolib_remote.md。

Submodules#

Attributes#

Exceptions#

RemoteConfigError

配置不合法或缺失导致的错误。

RemoteDependencyError

依赖缺失或版本不兼容导致的错误。

RemoteExecutionError

远端命令执行失败导致的错误。

Classes#

SshConfig

SSH 连接配置结构(与 Fabric Connection 的关键字参数兼容)。

RemoteProbeCommands

远端探测使用的命令集合。

RemoteProbeReport

远端探测结果。

RemoteProbeRunOptions

远端命令执行选项与错误处理策略。

RemoteProber

远端探测执行器(可注入连接工厂,便于测试与扩展)。

Functions#

load_ssh_config(→ SshConfig)

从 TOML 读取 SSH 连接配置(返回深拷贝)。

redact_ssh_config(→ dict[str, Any])

脱敏 SSH 配置,避免输出敏感字段。

probe_remote(...)

兼容接口:连接远端并执行探测命令,返回结构化结果。

remote_prefixes(→ collections.abc.Iterator[None])

在同一个命令执行上下文中叠加多个 prefix。

Package Contents#

class taolib.remote.SshConfig[源代码]#

Bases: TypedDict

SSH 连接配置结构(与 Fabric Connection 的关键字参数兼容)。

host: str#
user: str#
port: int#
connect_kwargs: dict[str, Any]#
taolib.remote.load_ssh_config(config_path: str | pathlib.Path) SshConfig[源代码]#

从 TOML 读取 SSH 连接配置(返回深拷贝)。

taolib.remote.redact_ssh_config(config: SshConfig | dict[str, Any]) dict[str, Any][源代码]#

脱敏 SSH 配置,避免输出敏感字段。

exception taolib.remote.RemoteConfigError[源代码]#

Bases: RemoteError

配置不合法或缺失导致的错误。

exception taolib.remote.RemoteDependencyError[源代码]#

Bases: RemoteError

依赖缺失或版本不兼容导致的错误。

exception taolib.remote.RemoteExecutionError(message: str, *, command: str | None = None)[源代码]#

Bases: RemoteError

远端命令执行失败导致的错误。

command = None#
taolib.remote.DEFAULT_CONDA_ACTIVATE_CMD[源代码]#
taolib.remote.DEFAULT_ENCODING[源代码]#
taolib.remote.DEFAULT_PROBE_CMD[源代码]#
taolib.remote.DEFAULT_TOOLS_ENV_CMD[源代码]#
class taolib.remote.RemoteProbeCommands[源代码]#

远端探测使用的命令集合。

命令分为两类: - prefix 命令:tools_env_cmd、conda_activate_cmd,会在同一执行上下文中叠加生效; - 常规命令:uname_cmd、check_conda_cmd、probe_cmd,会在远端依次运行。

tools_env_cmd: str#
conda_activate_cmd: str#
probe_cmd: str#
check_conda_cmd: str = 'command -v conda'#
uname_cmd: str = 'uname -a'#
class taolib.remote.RemoteProbeReport[源代码]#

远端探测结果。

语义约定: - conda_available=False 时,不会尝试执行 probe_cmd(probe_attempted=False, probe_ok=None)。 - conda_available=True 且 probe_attempted=True 时,probe_ok 表示探测命令退出状态是否成功。

uname: str#
conda_available: bool#
probe_attempted: bool#
probe_ok: bool | None#
class taolib.remote.RemoteProbeRunOptions[源代码]#

远端命令执行选项与错误处理策略。

encoding 与 run_kwargs 会被合并用于 Connection.run(...)。 raise_on_* 用于控制缺少 conda 或 probe 失败时,是返回结构化结果还是抛出异常。

encoding: str#
run_kwargs: collections.abc.Mapping[str, Any] | None = None#
raise_on_conda_missing: bool = False#
raise_on_probe_failure: bool = False#
merged_run_kwargs() dict[str, Any][源代码]#
class taolib.remote.RemoteProber[源代码]#

远端探测执行器(可注入连接工厂,便于测试与扩展)。

connection_factory: taolib.remote.connection.ConnectionFactory | None = None#
commands: taolib.remote.probe_models.RemoteProbeCommands#
options: taolib.remote.probe_models.RemoteProbeRunOptions#
probe(ssh_config: collections.abc.Mapping[str, Any]) taolib.remote.probe_models.RemoteProbeReport[源代码]#
taolib.remote.probe_remote(ssh_config: collections.abc.Mapping[str, Any], *, tools_env_cmd: str = DEFAULT_TOOLS_ENV_CMD, conda_activate_cmd: str = DEFAULT_CONDA_ACTIVATE_CMD, probe_cmd: str = DEFAULT_PROBE_CMD, encoding: str = DEFAULT_ENCODING, check_conda_cmd: str = 'command -v conda', uname_cmd: str = 'uname -a', connection_factory: taolib.remote.connection.ConnectionFactory | None = None, run_kwargs: collections.abc.Mapping[str, Any] | None = None, raise_on_conda_missing: bool = False, raise_on_probe_failure: bool = False) taolib.remote.probe_models.RemoteProbeReport[源代码]#

兼容接口:连接远端并执行探测命令,返回结构化结果。

taolib.remote.remote_prefixes(connection: SupportsPrefix, *prefix_cmds: str) collections.abc.Iterator[None][源代码]#

在同一个命令执行上下文中叠加多个 prefix。