ominfra 0.0.0.dev143__tar.gz → 0.0.0.dev145__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {ominfra-0.0.0.dev143/ominfra.egg-info → ominfra-0.0.0.dev145}/PKG-INFO +3 -3
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/commands/execution.py +1 -1
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/commands/inject.py +2 -3
- ominfra-0.0.0.dev145/ominfra/manage/deploy/command.py +23 -0
- ominfra-0.0.0.dev145/ominfra/manage/deploy/inject.py +19 -0
- ominfra-0.0.0.dev145/ominfra/manage/deploy/paths.py +33 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/inject.py +3 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/main.py +31 -16
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/remote/execution.py +2 -1
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/scripts/journald2aws.py +73 -53
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/scripts/manage.py +136 -72
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/scripts/supervisor.py +114 -94
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/dispatchers.py +3 -3
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/http.py +6 -6
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/inject.py +12 -12
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/io.py +2 -2
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/spawningimpl.py +2 -2
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/supervisor.py +2 -2
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/types.py +2 -2
- ominfra-0.0.0.dev145/ominfra/tools/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145/ominfra.egg-info}/PKG-INFO +3 -3
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra.egg-info/SOURCES.txt +4 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra.egg-info/requires.txt +2 -2
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/pyproject.toml +3 -3
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/LICENSE +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/MANIFEST.in +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/README.rst +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/.manifests.json +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/__about__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/aws/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/aws/__main__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/aws/auth.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/aws/cli.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/aws/dataclasses.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/aws/journald2aws/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/aws/journald2aws/__main__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/aws/journald2aws/cursor.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/aws/journald2aws/driver.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/aws/journald2aws/main.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/aws/journald2aws/poster.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/aws/logs.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/aws/metadata.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/gcp/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/clouds/gcp/auth.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/cmds.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/configs.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/journald/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/journald/fields.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/journald/genmessages.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/journald/messages.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/journald/tailer.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/__main__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/bootstrap.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/bootstrap_.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/commands/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/commands/base.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/commands/marshal.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/commands/subprocess.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/config.py +0 -0
- {ominfra-0.0.0.dev143/ominfra/manage/remote → ominfra-0.0.0.dev145/ominfra/manage/deploy}/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/marshal.py +0 -0
- {ominfra-0.0.0.dev143/ominfra/scripts → ominfra-0.0.0.dev145/ominfra/manage/remote}/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/remote/channel.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/remote/config.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/remote/inject.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/remote/payload.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/manage/remote/spawning.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/pyremote.py +0 -0
- {ominfra-0.0.0.dev143/ominfra/supervisor/utils → ominfra-0.0.0.dev145/ominfra/scripts}/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/ssh.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/LICENSE.txt +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/__main__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/configs.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/dispatchersimpl.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/events.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/exceptions.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/groups.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/groupsimpl.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/main.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/pipes.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/privileges.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/process.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/processimpl.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/setup.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/setupimpl.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/signals.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/spawning.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/states.py +0 -0
- {ominfra-0.0.0.dev143/ominfra/tailscale → ominfra-0.0.0.dev145/ominfra/supervisor/utils}/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/utils/collections.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/utils/diag.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/utils/fds.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/utils/fs.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/utils/os.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/utils/ostypes.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/utils/signals.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/utils/strings.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/supervisor/utils/users.py +0 -0
- {ominfra-0.0.0.dev143/ominfra/tools → ominfra-0.0.0.dev145/ominfra/tailscale}/__init__.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/tailscale/api.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/tailscale/cli.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/threadworkers.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra/tools/listresources.py +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra.egg-info/dependency_links.txt +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra.egg-info/entry_points.txt +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/ominfra.egg-info/top_level.txt +0 -0
- {ominfra-0.0.0.dev143 → ominfra-0.0.0.dev145}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: ominfra
|
3
|
-
Version: 0.0.0.
|
3
|
+
Version: 0.0.0.dev145
|
4
4
|
Summary: ominfra
|
5
5
|
Author: wrmsr
|
6
6
|
License: BSD-3-Clause
|
@@ -12,8 +12,8 @@ Classifier: Operating System :: OS Independent
|
|
12
12
|
Classifier: Operating System :: POSIX
|
13
13
|
Requires-Python: >=3.12
|
14
14
|
License-File: LICENSE
|
15
|
-
Requires-Dist: omdev==0.0.0.
|
16
|
-
Requires-Dist: omlish==0.0.0.
|
15
|
+
Requires-Dist: omdev==0.0.0.dev145
|
16
|
+
Requires-Dist: omlish==0.0.0.dev145
|
17
17
|
Provides-Extra: all
|
18
18
|
Requires-Dist: paramiko~=3.5; extra == "all"
|
19
19
|
Requires-Dist: asyncssh~=2.18; extra == "all"
|
@@ -8,7 +8,7 @@ from .base import CommandExecutor
|
|
8
8
|
CommandExecutorMap = ta.NewType('CommandExecutorMap', ta.Mapping[ta.Type[Command], CommandExecutor])
|
9
9
|
|
10
10
|
|
11
|
-
class
|
11
|
+
class LocalCommandExecutor(CommandExecutor):
|
12
12
|
def __init__(
|
13
13
|
self,
|
14
14
|
*,
|
@@ -18,8 +18,8 @@ from .base import CommandNameMap
|
|
18
18
|
from .base import CommandRegistration
|
19
19
|
from .base import CommandRegistrations
|
20
20
|
from .base import build_command_name_map
|
21
|
-
from .execution import CommandExecutionService
|
22
21
|
from .execution import CommandExecutorMap
|
22
|
+
from .execution import LocalCommandExecutor
|
23
23
|
from .marshal import install_command_marshaling
|
24
24
|
from .subprocess import SubprocessCommand
|
25
25
|
from .subprocess import SubprocessCommandExecutor
|
@@ -106,8 +106,7 @@ def bind_commands(
|
|
106
106
|
lst.extend([
|
107
107
|
inj.bind(provide_command_executor_map, singleton=True),
|
108
108
|
|
109
|
-
inj.bind(
|
110
|
-
inj.bind(CommandExecutor, to_key=CommandExecutionService),
|
109
|
+
inj.bind(LocalCommandExecutor, singleton=True, eager=main_config.debug),
|
111
110
|
])
|
112
111
|
|
113
112
|
#
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# ruff: noqa: UP006 UP007
|
2
|
+
import dataclasses as dc
|
3
|
+
|
4
|
+
from ..commands.base import Command
|
5
|
+
from ..commands.base import CommandExecutor
|
6
|
+
|
7
|
+
|
8
|
+
##
|
9
|
+
|
10
|
+
|
11
|
+
@dc.dataclass(frozen=True)
|
12
|
+
class DeployCommand(Command['DeployCommand.Output']):
|
13
|
+
@dc.dataclass(frozen=True)
|
14
|
+
class Output(Command.Output):
|
15
|
+
pass
|
16
|
+
|
17
|
+
|
18
|
+
##
|
19
|
+
|
20
|
+
|
21
|
+
class DeployCommandExecutor(CommandExecutor[DeployCommand, DeployCommand.Output]):
|
22
|
+
def execute(self, cmd: DeployCommand) -> DeployCommand.Output:
|
23
|
+
return DeployCommand.Output()
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# ruff: noqa: UP006 UP007
|
2
|
+
import typing as ta
|
3
|
+
|
4
|
+
from omlish.lite.inject import InjectorBindingOrBindings
|
5
|
+
from omlish.lite.inject import InjectorBindings
|
6
|
+
from omlish.lite.inject import inj
|
7
|
+
|
8
|
+
from ..commands.inject import bind_command
|
9
|
+
from .command import DeployCommand
|
10
|
+
from .command import DeployCommandExecutor
|
11
|
+
|
12
|
+
|
13
|
+
def bind_deploy(
|
14
|
+
) -> InjectorBindings:
|
15
|
+
lst: ta.List[InjectorBindingOrBindings] = [
|
16
|
+
bind_command(DeployCommand, DeployCommandExecutor),
|
17
|
+
]
|
18
|
+
|
19
|
+
return inj.as_bindings(*lst)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# ruff: noqa: UP006 UP007
|
2
|
+
"""
|
3
|
+
~deploy
|
4
|
+
deploy.pid (flock)
|
5
|
+
/app
|
6
|
+
/<appspec> - shallow clone
|
7
|
+
/conf
|
8
|
+
/env
|
9
|
+
<appspec>.env
|
10
|
+
/nginx
|
11
|
+
<appspec>.conf
|
12
|
+
/supervisor
|
13
|
+
<appspec>.conf
|
14
|
+
/venv
|
15
|
+
/<appspec>
|
16
|
+
|
17
|
+
?
|
18
|
+
/logs
|
19
|
+
/wrmsr--omlish--<spec>
|
20
|
+
|
21
|
+
spec = <name>--<rev>--<when>
|
22
|
+
|
23
|
+
==
|
24
|
+
|
25
|
+
for dn in [
|
26
|
+
'app',
|
27
|
+
'conf',
|
28
|
+
'conf/env',
|
29
|
+
'conf/nginx',
|
30
|
+
'conf/supervisor',
|
31
|
+
'venv',
|
32
|
+
]:
|
33
|
+
"""
|
@@ -8,6 +8,7 @@ from omlish.lite.marshal import ObjMarshalerManager
|
|
8
8
|
|
9
9
|
from .commands.inject import bind_commands
|
10
10
|
from .config import MainConfig
|
11
|
+
from .deploy.inject import bind_deploy
|
11
12
|
from .marshal import ObjMarshalerInstaller
|
12
13
|
from .marshal import ObjMarshalerInstallers
|
13
14
|
from .remote.config import RemoteConfig
|
@@ -32,6 +33,8 @@ def bind_main(
|
|
32
33
|
bind_remote(
|
33
34
|
remote_config=remote_config,
|
34
35
|
),
|
36
|
+
|
37
|
+
bind_deploy(),
|
35
38
|
]
|
36
39
|
|
37
40
|
#
|
@@ -5,15 +5,22 @@
|
|
5
5
|
manage.py -s 'docker run -i python:3.12'
|
6
6
|
manage.py -s 'ssh -i /foo/bar.pem foo@bar.baz' -q --python=python3.8
|
7
7
|
"""
|
8
|
+
import contextlib
|
9
|
+
import typing as ta
|
10
|
+
|
8
11
|
from omlish.lite.logs import log # noqa
|
9
|
-
from omlish.lite.marshal import ObjMarshalOptions
|
10
12
|
from omlish.lite.marshal import ObjMarshalerManager
|
13
|
+
from omlish.lite.marshal import ObjMarshalOptions
|
11
14
|
from omlish.lite.pycharm import PycharmRemoteDebug
|
12
15
|
|
13
16
|
from .bootstrap import MainBootstrap
|
14
17
|
from .bootstrap_ import main_bootstrap
|
18
|
+
from .commands.base import Command
|
19
|
+
from .commands.base import CommandExecutor
|
20
|
+
from .commands.execution import LocalCommandExecutor
|
15
21
|
from .commands.subprocess import SubprocessCommand
|
16
22
|
from .config import MainConfig
|
23
|
+
from .deploy.command import DeployCommand
|
17
24
|
from .remote.config import RemoteConfig
|
18
25
|
from .remote.execution import RemoteExecution
|
19
26
|
from .remote.spawning import RemoteSpawning
|
@@ -39,6 +46,8 @@ def _main() -> None:
|
|
39
46
|
|
40
47
|
parser.add_argument('--debug', action='store_true')
|
41
48
|
|
49
|
+
parser.add_argument('--local', action='store_true')
|
50
|
+
|
42
51
|
parser.add_argument('command', nargs='+')
|
43
52
|
|
44
53
|
args = parser.parse_args()
|
@@ -69,28 +78,34 @@ def _main() -> None:
|
|
69
78
|
|
70
79
|
#
|
71
80
|
|
72
|
-
cmds = [
|
73
|
-
|
74
|
-
|
75
|
-
|
81
|
+
cmds: ta.List[Command] = []
|
82
|
+
for c in args.command:
|
83
|
+
if c == 'deploy':
|
84
|
+
cmds.append(DeployCommand())
|
85
|
+
else:
|
86
|
+
cmds.append(SubprocessCommand([c]))
|
76
87
|
|
77
88
|
#
|
78
89
|
|
79
|
-
|
80
|
-
|
81
|
-
shell_quote=args.shell_quote,
|
82
|
-
python=args.python,
|
83
|
-
)
|
90
|
+
with contextlib.ExitStack() as es:
|
91
|
+
ce: CommandExecutor
|
84
92
|
|
85
|
-
|
86
|
-
|
87
|
-
r = rce.try_execute(cmd)
|
93
|
+
if args.local:
|
94
|
+
ce = injector[LocalCommandExecutor]
|
88
95
|
|
89
|
-
|
96
|
+
else:
|
97
|
+
tgt = RemoteSpawning.Target(
|
98
|
+
shell=args.shell,
|
99
|
+
shell_quote=args.shell_quote,
|
100
|
+
python=args.python,
|
101
|
+
)
|
90
102
|
|
91
|
-
|
103
|
+
ce = es.enter_context(injector[RemoteExecution].connect(tgt, bs)) # noqa
|
92
104
|
|
93
|
-
|
105
|
+
for cmd in cmds:
|
106
|
+
r = ce.try_execute(cmd)
|
107
|
+
|
108
|
+
print(injector[ObjMarshalerManager].marshal_obj(r, opts=ObjMarshalOptions(raw_bytes=True)))
|
94
109
|
|
95
110
|
|
96
111
|
if __name__ == '__main__':
|
@@ -20,6 +20,7 @@ from ..commands.base import CommandException
|
|
20
20
|
from ..commands.base import CommandExecutor
|
21
21
|
from ..commands.base import CommandOutputOrException
|
22
22
|
from ..commands.base import CommandOutputOrExceptionData
|
23
|
+
from ..commands.execution import LocalCommandExecutor
|
23
24
|
from .channel import RemoteChannel
|
24
25
|
from .payload import RemoteExecutionPayloadFile
|
25
26
|
from .payload import get_remote_payload_src
|
@@ -52,7 +53,7 @@ def _remote_execution_main() -> None:
|
|
52
53
|
|
53
54
|
chan.set_marshaler(injector[ObjMarshalerManager])
|
54
55
|
|
55
|
-
ce = injector[
|
56
|
+
ce = injector[LocalCommandExecutor]
|
56
57
|
|
57
58
|
while True:
|
58
59
|
i = chan.recv_obj(Command)
|
@@ -2169,23 +2169,24 @@ TODO:
|
|
2169
2169
|
@dc.dataclass(frozen=True)
|
2170
2170
|
class ObjMarshalOptions:
|
2171
2171
|
raw_bytes: bool = False
|
2172
|
+
nonstrict_dataclasses: bool = False
|
2172
2173
|
|
2173
2174
|
|
2174
2175
|
class ObjMarshaler(abc.ABC):
|
2175
2176
|
@abc.abstractmethod
|
2176
|
-
def marshal(self, o: ta.Any,
|
2177
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2177
2178
|
raise NotImplementedError
|
2178
2179
|
|
2179
2180
|
@abc.abstractmethod
|
2180
|
-
def unmarshal(self, o: ta.Any,
|
2181
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2181
2182
|
raise NotImplementedError
|
2182
2183
|
|
2183
2184
|
|
2184
2185
|
class NopObjMarshaler(ObjMarshaler):
|
2185
|
-
def marshal(self, o: ta.Any,
|
2186
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2186
2187
|
return o
|
2187
2188
|
|
2188
|
-
def unmarshal(self, o: ta.Any,
|
2189
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2189
2190
|
return o
|
2190
2191
|
|
2191
2192
|
|
@@ -2193,29 +2194,29 @@ class NopObjMarshaler(ObjMarshaler):
|
|
2193
2194
|
class ProxyObjMarshaler(ObjMarshaler):
|
2194
2195
|
m: ta.Optional[ObjMarshaler] = None
|
2195
2196
|
|
2196
|
-
def marshal(self, o: ta.Any,
|
2197
|
-
return check_not_none(self.m).marshal(o,
|
2197
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2198
|
+
return check_not_none(self.m).marshal(o, ctx)
|
2198
2199
|
|
2199
|
-
def unmarshal(self, o: ta.Any,
|
2200
|
-
return check_not_none(self.m).unmarshal(o,
|
2200
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2201
|
+
return check_not_none(self.m).unmarshal(o, ctx)
|
2201
2202
|
|
2202
2203
|
|
2203
2204
|
@dc.dataclass(frozen=True)
|
2204
2205
|
class CastObjMarshaler(ObjMarshaler):
|
2205
2206
|
ty: type
|
2206
2207
|
|
2207
|
-
def marshal(self, o: ta.Any,
|
2208
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2208
2209
|
return o
|
2209
2210
|
|
2210
|
-
def unmarshal(self, o: ta.Any,
|
2211
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2211
2212
|
return self.ty(o)
|
2212
2213
|
|
2213
2214
|
|
2214
2215
|
class DynamicObjMarshaler(ObjMarshaler):
|
2215
|
-
def marshal(self, o: ta.Any,
|
2216
|
-
return marshal_obj(o)
|
2216
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2217
|
+
return ctx.manager.marshal_obj(o, opts=ctx.options)
|
2217
2218
|
|
2218
|
-
def unmarshal(self, o: ta.Any,
|
2219
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2219
2220
|
return o
|
2220
2221
|
|
2221
2222
|
|
@@ -2223,10 +2224,10 @@ class DynamicObjMarshaler(ObjMarshaler):
|
|
2223
2224
|
class Base64ObjMarshaler(ObjMarshaler):
|
2224
2225
|
ty: type
|
2225
2226
|
|
2226
|
-
def marshal(self, o: ta.Any,
|
2227
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2227
2228
|
return base64.b64encode(o).decode('ascii')
|
2228
2229
|
|
2229
|
-
def unmarshal(self, o: ta.Any,
|
2230
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2230
2231
|
return self.ty(base64.b64decode(o))
|
2231
2232
|
|
2232
2233
|
|
@@ -2234,25 +2235,25 @@ class Base64ObjMarshaler(ObjMarshaler):
|
|
2234
2235
|
class BytesSwitchedObjMarshaler(ObjMarshaler):
|
2235
2236
|
m: ObjMarshaler
|
2236
2237
|
|
2237
|
-
def marshal(self, o: ta.Any,
|
2238
|
-
if
|
2238
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2239
|
+
if ctx.options.raw_bytes:
|
2239
2240
|
return o
|
2240
|
-
return self.m.marshal(o,
|
2241
|
+
return self.m.marshal(o, ctx)
|
2241
2242
|
|
2242
|
-
def unmarshal(self, o: ta.Any,
|
2243
|
-
if
|
2243
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2244
|
+
if ctx.options.raw_bytes:
|
2244
2245
|
return o
|
2245
|
-
return self.m.unmarshal(o,
|
2246
|
+
return self.m.unmarshal(o, ctx)
|
2246
2247
|
|
2247
2248
|
|
2248
2249
|
@dc.dataclass(frozen=True)
|
2249
2250
|
class EnumObjMarshaler(ObjMarshaler):
|
2250
2251
|
ty: type
|
2251
2252
|
|
2252
|
-
def marshal(self, o: ta.Any,
|
2253
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2253
2254
|
return o.name
|
2254
2255
|
|
2255
|
-
def unmarshal(self, o: ta.Any,
|
2256
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2256
2257
|
return self.ty.__members__[o] # type: ignore
|
2257
2258
|
|
2258
2259
|
|
@@ -2260,15 +2261,15 @@ class EnumObjMarshaler(ObjMarshaler):
|
|
2260
2261
|
class OptionalObjMarshaler(ObjMarshaler):
|
2261
2262
|
item: ObjMarshaler
|
2262
2263
|
|
2263
|
-
def marshal(self, o: ta.Any,
|
2264
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2264
2265
|
if o is None:
|
2265
2266
|
return None
|
2266
|
-
return self.item.marshal(o,
|
2267
|
+
return self.item.marshal(o, ctx)
|
2267
2268
|
|
2268
|
-
def unmarshal(self, o: ta.Any,
|
2269
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2269
2270
|
if o is None:
|
2270
2271
|
return None
|
2271
|
-
return self.item.unmarshal(o,
|
2272
|
+
return self.item.unmarshal(o, ctx)
|
2272
2273
|
|
2273
2274
|
|
2274
2275
|
@dc.dataclass(frozen=True)
|
@@ -2277,11 +2278,11 @@ class MappingObjMarshaler(ObjMarshaler):
|
|
2277
2278
|
km: ObjMarshaler
|
2278
2279
|
vm: ObjMarshaler
|
2279
2280
|
|
2280
|
-
def marshal(self, o: ta.Any,
|
2281
|
-
return {self.km.marshal(k,
|
2281
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2282
|
+
return {self.km.marshal(k, ctx): self.vm.marshal(v, ctx) for k, v in o.items()}
|
2282
2283
|
|
2283
|
-
def unmarshal(self, o: ta.Any,
|
2284
|
-
return self.ty((self.km.unmarshal(k,
|
2284
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2285
|
+
return self.ty((self.km.unmarshal(k, ctx), self.vm.unmarshal(v, ctx)) for k, v in o.items())
|
2285
2286
|
|
2286
2287
|
|
2287
2288
|
@dc.dataclass(frozen=True)
|
@@ -2289,11 +2290,11 @@ class IterableObjMarshaler(ObjMarshaler):
|
|
2289
2290
|
ty: type
|
2290
2291
|
item: ObjMarshaler
|
2291
2292
|
|
2292
|
-
def marshal(self, o: ta.Any,
|
2293
|
-
return [self.item.marshal(e,
|
2293
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2294
|
+
return [self.item.marshal(e, ctx) for e in o]
|
2294
2295
|
|
2295
|
-
def unmarshal(self, o: ta.Any,
|
2296
|
-
return self.ty(self.item.unmarshal(e,
|
2296
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2297
|
+
return self.ty(self.item.unmarshal(e, ctx) for e in o)
|
2297
2298
|
|
2298
2299
|
|
2299
2300
|
@dc.dataclass(frozen=True)
|
@@ -2302,11 +2303,18 @@ class DataclassObjMarshaler(ObjMarshaler):
|
|
2302
2303
|
fs: ta.Mapping[str, ObjMarshaler]
|
2303
2304
|
nonstrict: bool = False
|
2304
2305
|
|
2305
|
-
def marshal(self, o: ta.Any,
|
2306
|
-
return {
|
2306
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2307
|
+
return {
|
2308
|
+
k: m.marshal(getattr(o, k), ctx)
|
2309
|
+
for k, m in self.fs.items()
|
2310
|
+
}
|
2307
2311
|
|
2308
|
-
def unmarshal(self, o: ta.Any,
|
2309
|
-
return self.ty(**{
|
2312
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2313
|
+
return self.ty(**{
|
2314
|
+
k: self.fs[k].unmarshal(v, ctx)
|
2315
|
+
for k, v in o.items()
|
2316
|
+
if not (self.nonstrict or ctx.options.nonstrict_dataclasses) or k in self.fs
|
2317
|
+
})
|
2310
2318
|
|
2311
2319
|
|
2312
2320
|
@dc.dataclass(frozen=True)
|
@@ -2326,50 +2334,50 @@ class PolymorphicObjMarshaler(ObjMarshaler):
|
|
2326
2334
|
{i.tag: i for i in impls},
|
2327
2335
|
)
|
2328
2336
|
|
2329
|
-
def marshal(self, o: ta.Any,
|
2337
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2330
2338
|
impl = self.impls_by_ty[type(o)]
|
2331
|
-
return {impl.tag: impl.m.marshal(o,
|
2339
|
+
return {impl.tag: impl.m.marshal(o, ctx)}
|
2332
2340
|
|
2333
|
-
def unmarshal(self, o: ta.Any,
|
2341
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2334
2342
|
[(t, v)] = o.items()
|
2335
2343
|
impl = self.impls_by_tag[t]
|
2336
|
-
return impl.m.unmarshal(v,
|
2344
|
+
return impl.m.unmarshal(v, ctx)
|
2337
2345
|
|
2338
2346
|
|
2339
2347
|
@dc.dataclass(frozen=True)
|
2340
2348
|
class DatetimeObjMarshaler(ObjMarshaler):
|
2341
2349
|
ty: type
|
2342
2350
|
|
2343
|
-
def marshal(self, o: ta.Any,
|
2351
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2344
2352
|
return o.isoformat()
|
2345
2353
|
|
2346
|
-
def unmarshal(self, o: ta.Any,
|
2354
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2347
2355
|
return self.ty.fromisoformat(o) # type: ignore
|
2348
2356
|
|
2349
2357
|
|
2350
2358
|
class DecimalObjMarshaler(ObjMarshaler):
|
2351
|
-
def marshal(self, o: ta.Any,
|
2359
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2352
2360
|
return str(check_isinstance(o, decimal.Decimal))
|
2353
2361
|
|
2354
|
-
def unmarshal(self, v: ta.Any,
|
2362
|
+
def unmarshal(self, v: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2355
2363
|
return decimal.Decimal(check_isinstance(v, str))
|
2356
2364
|
|
2357
2365
|
|
2358
2366
|
class FractionObjMarshaler(ObjMarshaler):
|
2359
|
-
def marshal(self, o: ta.Any,
|
2367
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2360
2368
|
fr = check_isinstance(o, fractions.Fraction)
|
2361
2369
|
return [fr.numerator, fr.denominator]
|
2362
2370
|
|
2363
|
-
def unmarshal(self, v: ta.Any,
|
2371
|
+
def unmarshal(self, v: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2364
2372
|
num, denom = check_isinstance(v, list)
|
2365
2373
|
return fractions.Fraction(num, denom)
|
2366
2374
|
|
2367
2375
|
|
2368
2376
|
class UuidObjMarshaler(ObjMarshaler):
|
2369
|
-
def marshal(self, o: ta.Any,
|
2377
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2370
2378
|
return str(o)
|
2371
2379
|
|
2372
|
-
def unmarshal(self, o: ta.Any,
|
2380
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2373
2381
|
return uuid.UUID(o)
|
2374
2382
|
|
2375
2383
|
|
@@ -2530,6 +2538,12 @@ class ObjMarshalerManager:
|
|
2530
2538
|
|
2531
2539
|
#
|
2532
2540
|
|
2541
|
+
def _make_context(self, opts: ta.Optional[ObjMarshalOptions]) -> 'ObjMarshalContext':
|
2542
|
+
return ObjMarshalContext(
|
2543
|
+
options=opts or self._default_options,
|
2544
|
+
manager=self,
|
2545
|
+
)
|
2546
|
+
|
2533
2547
|
def marshal_obj(
|
2534
2548
|
self,
|
2535
2549
|
o: ta.Any,
|
@@ -2537,7 +2551,7 @@ class ObjMarshalerManager:
|
|
2537
2551
|
opts: ta.Optional[ObjMarshalOptions] = None,
|
2538
2552
|
) -> ta.Any:
|
2539
2553
|
m = self.get_obj_marshaler(ty if ty is not None else type(o))
|
2540
|
-
return m.marshal(o,
|
2554
|
+
return m.marshal(o, self._make_context(opts))
|
2541
2555
|
|
2542
2556
|
def unmarshal_obj(
|
2543
2557
|
self,
|
@@ -2546,7 +2560,7 @@ class ObjMarshalerManager:
|
|
2546
2560
|
opts: ta.Optional[ObjMarshalOptions] = None,
|
2547
2561
|
) -> T:
|
2548
2562
|
m = self.get_obj_marshaler(ty)
|
2549
|
-
return m.unmarshal(o,
|
2563
|
+
return m.unmarshal(o, self._make_context(opts))
|
2550
2564
|
|
2551
2565
|
def roundtrip_obj(
|
2552
2566
|
self,
|
@@ -2561,6 +2575,12 @@ class ObjMarshalerManager:
|
|
2561
2575
|
return u
|
2562
2576
|
|
2563
2577
|
|
2578
|
+
@dc.dataclass(frozen=True)
|
2579
|
+
class ObjMarshalContext:
|
2580
|
+
options: ObjMarshalOptions
|
2581
|
+
manager: ObjMarshalerManager
|
2582
|
+
|
2583
|
+
|
2564
2584
|
##
|
2565
2585
|
|
2566
2586
|
|