hostctl 0.1.0__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.
- hostctl/AGENTS.md +292 -0
- hostctl/README.md +248 -0
- hostctl/__init__.py +194 -0
- hostctl/__main__.py +6 -0
- hostctl/_async.py +169 -0
- hostctl/_cli.py +232 -0
- hostctl/executor/__init__.py +82 -0
- hostctl/executor/_common.py +234 -0
- hostctl/executor/_qga.py +646 -0
- hostctl/executor/container.py +171 -0
- hostctl/executor/local.py +91 -0
- hostctl/executor/psrp.py +145 -0
- hostctl/executor/qemu.py +305 -0
- hostctl/executor/serial.py +312 -0
- hostctl/executor/ssh.py +226 -0
- hostctl/executor/winrm.py +255 -0
- hostctl/host/__init__.py +93 -0
- hostctl/host/_common.py +804 -0
- hostctl/host/_local.py +258 -0
- hostctl/host/_ssh.py +587 -0
- hostctl/host/_winrm.py +1002 -0
- hostctl/host/composite_path.py +567 -0
- hostctl/host/container.py +606 -0
- hostctl/host/container_path.py +664 -0
- hostctl/host/qemu.py +1078 -0
- hostctl/host/serial.py +401 -0
- hostctl/host/system.py +809 -0
- hostctl/process/__init__.py +49 -0
- hostctl/process/_common.py +113 -0
- hostctl/process/container.py +265 -0
- hostctl/process/psrp.py +208 -0
- hostctl/process/qemu_serial.py +247 -0
- hostctl/process/serial.py +257 -0
- hostctl/process/ssh.py +165 -0
- hostctl/provider/__init__.py +33 -0
- hostctl/provider/_common.py +452 -0
- hostctl/provider/transports.py +303 -0
- hostctl/py.typed +0 -0
- hostctl/serial/__init__.py +285 -0
- hostctl/shell/__init__.py +123 -0
- hostctl/shell/_common.py +616 -0
- hostctl/shell/cmd.py +167 -0
- hostctl/shell/fish.py +63 -0
- hostctl/shell/posix.py +83 -0
- hostctl/shell/powershell.py +120 -0
- hostctl/sync.py +245 -0
- hostctl-0.1.0.dist-info/METADATA +302 -0
- hostctl-0.1.0.dist-info/RECORD +51 -0
- hostctl-0.1.0.dist-info/WHEEL +4 -0
- hostctl-0.1.0.dist-info/entry_points.txt +2 -0
- hostctl-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Public shell construction API and built-in shell flavours."""
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
from importlib import metadata as _metadata
|
|
5
|
+
|
|
6
|
+
from ._common import (
|
|
7
|
+
Shell as Shell,
|
|
8
|
+
ShellCommand as ShellCommand,
|
|
9
|
+
ShellFlavour as ShellFlavour,
|
|
10
|
+
ShellOperator as ShellOperator,
|
|
11
|
+
ShellSession as ShellSession,
|
|
12
|
+
ShellToken as ShellToken,
|
|
13
|
+
)
|
|
14
|
+
from .cmd import CmdShellFlavour as CmdShellFlavour
|
|
15
|
+
from .fish import FishShellFlavour as FishShellFlavour
|
|
16
|
+
from .posix import (
|
|
17
|
+
BashShellFlavour as BashShellFlavour,
|
|
18
|
+
PosixShellFlavour as PosixShellFlavour,
|
|
19
|
+
ZshShellFlavour as ZshShellFlavour,
|
|
20
|
+
)
|
|
21
|
+
from .powershell import PowerShellFlavour as PowerShellFlavour
|
|
22
|
+
|
|
23
|
+
POSIX_SHELL = PosixShellFlavour()
|
|
24
|
+
BASH = BashShellFlavour()
|
|
25
|
+
ZSH = ZshShellFlavour()
|
|
26
|
+
FISH = FishShellFlavour()
|
|
27
|
+
CMD = CmdShellFlavour()
|
|
28
|
+
POWERSHELL = PowerShellFlavour()
|
|
29
|
+
PWSH = PowerShellFlavour(major_version=7)
|
|
30
|
+
|
|
31
|
+
_SHELLS = {
|
|
32
|
+
POSIX_SHELL.name: POSIX_SHELL,
|
|
33
|
+
BASH.name: BASH,
|
|
34
|
+
ZSH.name: ZSH,
|
|
35
|
+
FISH.name: FISH,
|
|
36
|
+
CMD.name: CMD,
|
|
37
|
+
POWERSHELL.name: POWERSHELL,
|
|
38
|
+
PWSH.name: PWSH,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
ShellFlavourSelection = typing.Union[str, ShellFlavour, typing.Type[ShellFlavour]]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def register_shell_flavour(
|
|
45
|
+
value: typing.Union[ShellFlavour, typing.Type[ShellFlavour]],
|
|
46
|
+
*,
|
|
47
|
+
name: typing.Optional[str] = None,
|
|
48
|
+
replace: bool = False,
|
|
49
|
+
) -> ShellFlavour:
|
|
50
|
+
"""Register a configured flavour instance for string-based selection."""
|
|
51
|
+
flavour = value() if isinstance(value, type) else value
|
|
52
|
+
if not isinstance(flavour, ShellFlavour):
|
|
53
|
+
raise TypeError("shell flavour must be a ShellFlavour instance or subclass")
|
|
54
|
+
selected_name = name or flavour.name
|
|
55
|
+
if not selected_name:
|
|
56
|
+
raise ValueError("shell flavour name must not be empty")
|
|
57
|
+
if selected_name in _SHELLS and not replace:
|
|
58
|
+
raise ValueError(f"shell flavour is already registered: {selected_name}")
|
|
59
|
+
_SHELLS[selected_name] = flavour
|
|
60
|
+
return flavour
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def shell_flavour(value: ShellFlavourSelection) -> ShellFlavour:
|
|
64
|
+
"""Normalize a public shell selection without inferring from the transport."""
|
|
65
|
+
if isinstance(value, type):
|
|
66
|
+
if not issubclass(value, ShellFlavour):
|
|
67
|
+
raise TypeError("shell flavour class must inherit ShellFlavour")
|
|
68
|
+
value = value()
|
|
69
|
+
if isinstance(value, ShellFlavour):
|
|
70
|
+
return value
|
|
71
|
+
try:
|
|
72
|
+
return _SHELLS[value]
|
|
73
|
+
except (KeyError, TypeError) as exc:
|
|
74
|
+
if isinstance(value, str):
|
|
75
|
+
try:
|
|
76
|
+
entries = _metadata.entry_points()
|
|
77
|
+
selected = (
|
|
78
|
+
entries.select(group="hostctl.shell_flavours", name=value)
|
|
79
|
+
if hasattr(entries, "select")
|
|
80
|
+
else [
|
|
81
|
+
item
|
|
82
|
+
for item in entries.get("hostctl.shell_flavours", ())
|
|
83
|
+
if item.name == value
|
|
84
|
+
]
|
|
85
|
+
)
|
|
86
|
+
if selected:
|
|
87
|
+
loaded = selected[0].load()
|
|
88
|
+
register_shell_flavour(loaded, name=value)
|
|
89
|
+
return _SHELLS[value]
|
|
90
|
+
except Exception as plugin_error:
|
|
91
|
+
raise ValueError(
|
|
92
|
+
f"invalid shell flavour plugin {value!r}: {plugin_error}"
|
|
93
|
+
) from plugin_error
|
|
94
|
+
supported = ", ".join(sorted(_SHELLS))
|
|
95
|
+
raise ValueError(
|
|
96
|
+
f"unsupported shell flavour; choose one of: {supported}"
|
|
97
|
+
) from exc
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
__all__ = [
|
|
101
|
+
"POSIX_SHELL",
|
|
102
|
+
"BASH",
|
|
103
|
+
"ZSH",
|
|
104
|
+
"FISH",
|
|
105
|
+
"CMD",
|
|
106
|
+
"BashShellFlavour",
|
|
107
|
+
"CmdShellFlavour",
|
|
108
|
+
"FishShellFlavour",
|
|
109
|
+
"POWERSHELL",
|
|
110
|
+
"PosixShellFlavour",
|
|
111
|
+
"PowerShellFlavour",
|
|
112
|
+
"PWSH",
|
|
113
|
+
"Shell",
|
|
114
|
+
"ShellCommand",
|
|
115
|
+
"ShellFlavour",
|
|
116
|
+
"ShellFlavourSelection",
|
|
117
|
+
"ShellOperator",
|
|
118
|
+
"ShellSession",
|
|
119
|
+
"ShellToken",
|
|
120
|
+
"ZshShellFlavour",
|
|
121
|
+
"register_shell_flavour",
|
|
122
|
+
"shell_flavour",
|
|
123
|
+
]
|