zrb 0.26.2__py3-none-any.whl → 0.27.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.
- zrb/__init__.py +0 -3
- zrb/task/docker_compose_task.py +26 -26
- zrb/task/remote_cmd_task.py +53 -14
- zrb/task/rsync_task.py +55 -19
- {zrb-0.26.2.dist-info → zrb-0.27.0.dist-info}/METADATA +2 -2
- {zrb-0.26.2.dist-info → zrb-0.27.0.dist-info}/RECORD +9 -10
- zrb/task/base_remote_cmd_task.py +0 -354
- {zrb-0.26.2.dist-info → zrb-0.27.0.dist-info}/LICENSE +0 -0
- {zrb-0.26.2.dist-info → zrb-0.27.0.dist-info}/WHEEL +0 -0
- {zrb-0.26.2.dist-info → zrb-0.27.0.dist-info}/entry_points.txt +0 -0
zrb/__init__.py
CHANGED
@@ -10,7 +10,6 @@ from zrb.task.any_task_event_handler import (
|
|
10
10
|
OnTriggered,
|
11
11
|
OnWaiting,
|
12
12
|
)
|
13
|
-
from zrb.task.base_remote_cmd_task import BaseRemoteCmdTask, RemoteConfig
|
14
13
|
from zrb.task.checker import Checker
|
15
14
|
from zrb.task.cmd_task import CmdTask
|
16
15
|
from zrb.task.decorator import python_task
|
@@ -69,8 +68,6 @@ assert CmdTask
|
|
69
68
|
assert DockerComposeTask
|
70
69
|
assert DockerComposeStartTask
|
71
70
|
assert ServiceConfig
|
72
|
-
assert BaseRemoteCmdTask
|
73
|
-
assert RemoteConfig
|
74
71
|
assert RemoteCmdTask
|
75
72
|
assert RsyncTask
|
76
73
|
assert Notifier
|
zrb/task/docker_compose_task.py
CHANGED
@@ -33,32 +33,33 @@ from zrb.task_input.any_input import AnyInput
|
|
33
33
|
|
34
34
|
logger.debug(colored("Loading zrb.task.docker_compose_task", attrs=["dark"]))
|
35
35
|
|
36
|
+
TDockerComposeTask = TypeVar("TDockerComposeTask", bound="DockerComposeTask")
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
SHELL_SCRIPT_DIR = os.path.join(CURRENT_DIR, "..", "shell-scripts")
|
40
|
-
ensure_container_backend = CmdTask(
|
41
|
-
name="ensure-compose-backend",
|
42
|
-
cmd_path=[
|
43
|
-
os.path.join(SHELL_SCRIPT_DIR, "_common-util.sh"),
|
44
|
-
os.path.join(SHELL_SCRIPT_DIR, f"ensure-{backend}-is-installed.sh"),
|
45
|
-
],
|
46
|
-
preexec_fn=None,
|
47
|
-
should_print_cmd_result=False,
|
48
|
-
)
|
49
|
-
return CmdTask(
|
50
|
-
name="ensure-zrb-network",
|
51
|
-
cmd=[
|
52
|
-
f"{backend} network inspect zrb >/dev/null 2>&1 || \\",
|
53
|
-
f"{backend} network create -d bridge zrb",
|
54
|
-
],
|
55
|
-
upstreams=[ensure_container_backend],
|
56
|
-
should_print_cmd_result=False,
|
57
|
-
)
|
58
|
-
|
38
|
+
CURRENT_DIR = os.path.dirname(__file__)
|
39
|
+
SHELL_SCRIPT_DIR = os.path.join(CURRENT_DIR, "..", "shell-scripts")
|
59
40
|
|
60
|
-
|
61
|
-
|
41
|
+
ensure_container_backend = CmdTask(
|
42
|
+
name="ensure-compose-backend",
|
43
|
+
cmd_path=[
|
44
|
+
os.path.join(SHELL_SCRIPT_DIR, "_common-util.sh"),
|
45
|
+
os.path.join(SHELL_SCRIPT_DIR, f"ensure-{CONTAINER_BACKEND}-is-installed.sh"),
|
46
|
+
],
|
47
|
+
preexec_fn=None,
|
48
|
+
should_print_cmd_result=False,
|
49
|
+
should_show_cmd=False,
|
50
|
+
should_show_working_directory=False,
|
51
|
+
)
|
52
|
+
ensure_zrb_network_task = CmdTask(
|
53
|
+
name="ensure-zrb-network",
|
54
|
+
cmd=[
|
55
|
+
f"{CONTAINER_BACKEND} network inspect zrb >/dev/null 2>&1 || \\",
|
56
|
+
f"{CONTAINER_BACKEND} network create -d bridge zrb",
|
57
|
+
],
|
58
|
+
upstreams=[ensure_container_backend],
|
59
|
+
should_print_cmd_result=False,
|
60
|
+
should_show_cmd=False,
|
61
|
+
should_show_working_directory=False,
|
62
|
+
)
|
62
63
|
|
63
64
|
|
64
65
|
@typechecked
|
@@ -120,14 +121,13 @@ class DockerComposeTask(CmdTask):
|
|
120
121
|
should_show_cmd: bool = True,
|
121
122
|
should_show_working_directory: bool = True,
|
122
123
|
):
|
123
|
-
combined_env_files = list(env_files)
|
124
124
|
CmdTask.__init__(
|
125
125
|
self,
|
126
126
|
name=name,
|
127
127
|
group=group,
|
128
128
|
inputs=inputs,
|
129
129
|
envs=envs,
|
130
|
-
env_files=
|
130
|
+
env_files=env_files,
|
131
131
|
icon=icon,
|
132
132
|
color=color,
|
133
133
|
description=description,
|
zrb/task/remote_cmd_task.py
CHANGED
@@ -6,6 +6,7 @@ from typing import Any, Optional, Union
|
|
6
6
|
from zrb.helper.accessories.color import colored
|
7
7
|
from zrb.helper.log import logger
|
8
8
|
from zrb.helper.typecheck import typechecked
|
9
|
+
from zrb.helper.typing import JinjaTemplate
|
9
10
|
from zrb.task.any_task import AnyTask
|
10
11
|
from zrb.task.any_task_event_handler import (
|
11
12
|
OnFailed,
|
@@ -16,7 +17,6 @@ from zrb.task.any_task_event_handler import (
|
|
16
17
|
OnTriggered,
|
17
18
|
OnWaiting,
|
18
19
|
)
|
19
|
-
from zrb.task.base_remote_cmd_task import BaseRemoteCmdTask, RemoteConfig
|
20
20
|
from zrb.task.cmd_task import CmdTask, CmdVal
|
21
21
|
from zrb.task_env.env import Env
|
22
22
|
from zrb.task_env.env_file import EnvFile
|
@@ -37,15 +37,17 @@ ensure_ssh_is_installed = CmdTask(
|
|
37
37
|
os.path.join(_SHELL_SCRIPT_DIR, "ensure-ssh-is-installed.sh"),
|
38
38
|
],
|
39
39
|
preexec_fn=None,
|
40
|
+
should_print_cmd_result=False,
|
41
|
+
should_show_cmd=False,
|
42
|
+
should_show_working_directory=False,
|
40
43
|
)
|
41
44
|
|
42
45
|
|
43
46
|
@typechecked
|
44
|
-
class RemoteCmdTask(
|
47
|
+
class RemoteCmdTask(CmdTask):
|
45
48
|
def __init__(
|
46
49
|
self,
|
47
50
|
name: str,
|
48
|
-
remote_configs: Iterable[RemoteConfig],
|
49
51
|
group: Optional[Group] = None,
|
50
52
|
inputs: Iterable[AnyInput] = [],
|
51
53
|
envs: Iterable[Env] = [],
|
@@ -54,9 +56,15 @@ class RemoteCmdTask(BaseRemoteCmdTask):
|
|
54
56
|
color: Optional[str] = None,
|
55
57
|
description: str = "",
|
56
58
|
executable: Optional[str] = None,
|
59
|
+
remote_host: JinjaTemplate = "localhost",
|
60
|
+
remote_port: Union[JinjaTemplate, int] = 22,
|
61
|
+
remote_user: JinjaTemplate = "root",
|
62
|
+
remote_password: JinjaTemplate = "",
|
63
|
+
remote_ssh_key: JinjaTemplate = "",
|
57
64
|
cmd: CmdVal = "",
|
58
65
|
cmd_path: CmdVal = "",
|
59
66
|
cwd: Optional[Union[str, pathlib.Path]] = None,
|
67
|
+
should_render_cwd: bool = True,
|
60
68
|
upstreams: Iterable[AnyTask] = [],
|
61
69
|
fallbacks: Iterable[AnyTask] = [],
|
62
70
|
on_triggered: Optional[OnTriggered] = None,
|
@@ -74,18 +82,14 @@ class RemoteCmdTask(BaseRemoteCmdTask):
|
|
74
82
|
max_error_line: int = 1000,
|
75
83
|
preexec_fn: Optional[Callable[[], Any]] = os.setsid,
|
76
84
|
should_execute: Union[bool, str, Callable[..., bool]] = True,
|
85
|
+
return_upstream_result: bool = False,
|
86
|
+
should_print_cmd_result: bool = True,
|
87
|
+
should_show_cmd: bool = True,
|
88
|
+
should_show_working_directory: bool = True,
|
77
89
|
):
|
78
|
-
|
79
|
-
[
|
80
|
-
_SSH_UTIL_SCRIPT,
|
81
|
-
"_SCRIPT=\"$(cat <<'ENDSCRIPT'",
|
82
|
-
]
|
83
|
-
)
|
84
|
-
post_cmd = "\n".join(["ENDSCRIPT", ')"', 'auth_ssh "$_SCRIPT"'])
|
85
|
-
BaseRemoteCmdTask.__init__(
|
90
|
+
CmdTask.__init__(
|
86
91
|
self,
|
87
92
|
name=name,
|
88
|
-
remote_configs=remote_configs,
|
89
93
|
group=group,
|
90
94
|
inputs=inputs,
|
91
95
|
envs=envs,
|
@@ -94,11 +98,10 @@ class RemoteCmdTask(BaseRemoteCmdTask):
|
|
94
98
|
color=color,
|
95
99
|
description=description,
|
96
100
|
executable=executable,
|
97
|
-
pre_cmd=pre_cmd,
|
98
101
|
cmd=cmd,
|
99
102
|
cmd_path=cmd_path,
|
100
|
-
post_cmd=post_cmd,
|
101
103
|
cwd=cwd,
|
104
|
+
should_render_cwd=should_render_cwd,
|
102
105
|
upstreams=[ensure_ssh_is_installed] + upstreams,
|
103
106
|
fallbacks=fallbacks,
|
104
107
|
on_triggered=on_triggered,
|
@@ -116,4 +119,40 @@ class RemoteCmdTask(BaseRemoteCmdTask):
|
|
116
119
|
max_error_line=max_error_line,
|
117
120
|
preexec_fn=preexec_fn,
|
118
121
|
should_execute=should_execute,
|
122
|
+
return_upstream_result=return_upstream_result,
|
123
|
+
should_print_cmd_result=should_print_cmd_result,
|
124
|
+
should_show_cmd=should_show_cmd,
|
125
|
+
should_show_working_directory=should_show_working_directory,
|
126
|
+
)
|
127
|
+
self._remote_host = remote_host
|
128
|
+
self._remote_port = remote_port
|
129
|
+
self._remote_user = remote_user
|
130
|
+
self._remote_password = remote_password
|
131
|
+
self._remote_ssh_key = remote_ssh_key
|
132
|
+
|
133
|
+
def get_cmd_script(self, *args: Any, **kwargs: Any) -> str:
|
134
|
+
cmd_script = self._create_cmd_script(self._cmd_path, self._cmd, *args, **kwargs)
|
135
|
+
cmd_script = "\n".join(
|
136
|
+
[
|
137
|
+
"_SCRIPT=$(cat << 'ENDSCRIPT'",
|
138
|
+
cmd_script,
|
139
|
+
"ENDSCRIPT",
|
140
|
+
")",
|
141
|
+
]
|
119
142
|
)
|
143
|
+
ssh_command = self._get_ssh_command()
|
144
|
+
return "\n".join([cmd_script, ssh_command])
|
145
|
+
|
146
|
+
def _get_ssh_command(self) -> str:
|
147
|
+
host = self.render_str(self._remote_host)
|
148
|
+
port = self.render_str(self._remote_port)
|
149
|
+
user = self.render_str(self._remote_user)
|
150
|
+
password = self.render_str(self._remote_password)
|
151
|
+
key = self.render_str(self._remote_ssh_key)
|
152
|
+
if key != "" and password != "":
|
153
|
+
return f'sshpass -p "{password}" ssh -t -p "{port}" -i "{key}" "{user}@{host}" "$_SCRIPT"' # noqa
|
154
|
+
if key != "":
|
155
|
+
return f'ssh -t -p "{port}" -i "{key}" "{user}@{host}" "$_SCRIPT"'
|
156
|
+
if password != "":
|
157
|
+
return f'sshpass -p "{password}" ssh -t -p "{port}" "{user}@{host}" "$_SCRIPT"' # noqa
|
158
|
+
return f'ssh -t -p "{port}" "{user}@{host}" "$_SCRIPT"'
|
zrb/task/rsync_task.py
CHANGED
@@ -17,7 +17,6 @@ from zrb.task.any_task_event_handler import (
|
|
17
17
|
OnTriggered,
|
18
18
|
OnWaiting,
|
19
19
|
)
|
20
|
-
from zrb.task.base_remote_cmd_task import BaseRemoteCmdTask, RemoteConfig
|
21
20
|
from zrb.task.cmd_task import CmdTask
|
22
21
|
from zrb.task_env.env import Env
|
23
22
|
from zrb.task_env.env_file import EnvFile
|
@@ -39,19 +38,17 @@ ensure_rsync_is_installed = CmdTask(
|
|
39
38
|
os.path.join(_SHELL_SCRIPT_DIR, "ensure-rsync-is-installed.sh"),
|
40
39
|
],
|
41
40
|
preexec_fn=None,
|
41
|
+
should_print_cmd_result=False,
|
42
|
+
should_show_cmd=False,
|
43
|
+
should_show_working_directory=False,
|
42
44
|
)
|
43
45
|
|
44
46
|
|
45
47
|
@typechecked
|
46
|
-
class RsyncTask(
|
48
|
+
class RsyncTask(CmdTask):
|
47
49
|
def __init__(
|
48
50
|
self,
|
49
51
|
name: str,
|
50
|
-
remote_configs: Iterable[RemoteConfig],
|
51
|
-
src: JinjaTemplate,
|
52
|
-
dst: JinjaTemplate,
|
53
|
-
src_is_remote: bool = False,
|
54
|
-
dst_is_remote: bool = True,
|
55
52
|
group: Optional[Group] = None,
|
56
53
|
inputs: Iterable[AnyInput] = [],
|
57
54
|
envs: Iterable[Env] = [],
|
@@ -60,7 +57,17 @@ class RsyncTask(BaseRemoteCmdTask):
|
|
60
57
|
color: Optional[str] = None,
|
61
58
|
description: str = "",
|
62
59
|
executable: Optional[str] = None,
|
63
|
-
|
60
|
+
remote_host: JinjaTemplate = "localhost",
|
61
|
+
remote_port: Union[JinjaTemplate, int] = 22,
|
62
|
+
remote_user: JinjaTemplate = "root",
|
63
|
+
remote_password: JinjaTemplate = "",
|
64
|
+
remote_ssh_key: JinjaTemplate = "",
|
65
|
+
src_path: JinjaTemplate = ".",
|
66
|
+
src_is_remote: bool = False,
|
67
|
+
dst_path: JinjaTemplate = ".",
|
68
|
+
dst_is_remote: bool = True,
|
69
|
+
cwd: Optional[Union[JinjaTemplate, pathlib.Path]] = None,
|
70
|
+
should_render_cwd: bool = True,
|
64
71
|
upstreams: Iterable[AnyTask] = [],
|
65
72
|
fallbacks: Iterable[AnyTask] = [],
|
66
73
|
on_triggered: Optional[OnTriggered] = None,
|
@@ -78,14 +85,14 @@ class RsyncTask(BaseRemoteCmdTask):
|
|
78
85
|
max_error_line: int = 1000,
|
79
86
|
preexec_fn: Optional[Callable[[], Any]] = os.setsid,
|
80
87
|
should_execute: Union[bool, str, Callable[..., bool]] = True,
|
88
|
+
return_upstream_result: bool = False,
|
89
|
+
should_print_cmd_result: bool = True,
|
90
|
+
should_show_cmd: bool = True,
|
91
|
+
should_show_working_directory: bool = True,
|
81
92
|
):
|
82
|
-
|
83
|
-
parsed_dst = self._get_parsed_path(dst_is_remote, dst)
|
84
|
-
cmd = f'auth_rsync "{parsed_src}" "{parsed_dst}"'
|
85
|
-
BaseRemoteCmdTask.__init__(
|
93
|
+
CmdTask.__init__(
|
86
94
|
self,
|
87
95
|
name=name,
|
88
|
-
remote_configs=remote_configs,
|
89
96
|
group=group,
|
90
97
|
inputs=inputs,
|
91
98
|
envs=envs,
|
@@ -94,9 +101,8 @@ class RsyncTask(BaseRemoteCmdTask):
|
|
94
101
|
color=color,
|
95
102
|
description=description,
|
96
103
|
executable=executable,
|
97
|
-
pre_cmd=_RSYNC_UTIL_SCRIPT,
|
98
|
-
cmd=cmd,
|
99
104
|
cwd=cwd,
|
105
|
+
should_render_cwd=should_render_cwd,
|
100
106
|
upstreams=[ensure_rsync_is_installed] + upstreams,
|
101
107
|
fallbacks=fallbacks,
|
102
108
|
on_triggered=on_triggered,
|
@@ -114,9 +120,39 @@ class RsyncTask(BaseRemoteCmdTask):
|
|
114
120
|
max_error_line=max_error_line,
|
115
121
|
preexec_fn=preexec_fn,
|
116
122
|
should_execute=should_execute,
|
123
|
+
return_upstream_result=return_upstream_result,
|
124
|
+
should_print_cmd_result=should_print_cmd_result,
|
125
|
+
should_show_cmd=should_show_cmd,
|
126
|
+
should_show_working_directory=should_show_working_directory,
|
117
127
|
)
|
128
|
+
self._remote_host = remote_host
|
129
|
+
self._remote_port = remote_port
|
130
|
+
self._remote_user = remote_user
|
131
|
+
self._remote_password = remote_password
|
132
|
+
self._remote_ssh_key = remote_ssh_key
|
133
|
+
self._src_path = src_path
|
134
|
+
self._src_is_remote = src_is_remote
|
135
|
+
self._dst_path = dst_path
|
136
|
+
self._dst_is_remote = dst_is_remote
|
137
|
+
|
138
|
+
def get_cmd_script(self, *args: Any, **kwargs: Any) -> str:
|
139
|
+
port = self.render_str(self._remote_port)
|
140
|
+
password = self.render_str(self._remote_password)
|
141
|
+
key = self.render_str(self._remote_ssh_key)
|
142
|
+
src = self._get_path(self._src_path, self._src_is_remote)
|
143
|
+
dst = self._get_path(self._dst_path, self._dst_is_remote)
|
144
|
+
if key != "" and password != "":
|
145
|
+
return f'sshpass -p "{password}" rsync --mkpath -avz -e "ssh -i {key} -p {port}" {src} {dst}' # noqa
|
146
|
+
if key != "":
|
147
|
+
return f'rsync --mkpath -avz -e "ssh -i {key} -p {port}" {src} {dst}'
|
148
|
+
if password != "":
|
149
|
+
return f'sshpass -p "{password}" rsync --mkpath -avz -e "ssh -p {port}" {src} {dst}' # noqa
|
150
|
+
return f'rsync --mkpath -avz -e "ssh -p {port}" {src} {dst}'
|
118
151
|
|
119
|
-
def
|
120
|
-
|
121
|
-
|
122
|
-
|
152
|
+
def _get_path(self, resource_path: str, is_remote: bool) -> str:
|
153
|
+
rendered_path = self.render_str(resource_path)
|
154
|
+
if is_remote:
|
155
|
+
host = self.render_str(self._remote_host)
|
156
|
+
user = self.render_str(self._remote_user)
|
157
|
+
return f"{user}@{host}:{rendered_path}"
|
158
|
+
return rendered_path
|
@@ -1,10 +1,10 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: zrb
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.27.0
|
4
4
|
Summary: A Framework to Enhance Your Workflow
|
5
5
|
Home-page: https://github.com/state-alchemists/zrb
|
6
6
|
License: AGPL-3.0-or-later
|
7
|
-
Keywords: Automation,Task Runner,Code Generator,Low Code
|
7
|
+
Keywords: Automation,Task Runner,Code Generator,Monorepo,Low Code
|
8
8
|
Author: Go Frendi Gunawan
|
9
9
|
Author-email: gofrendiasgard@gmail.com
|
10
10
|
Requires-Python: >=3.10.0,<4.0.0
|
@@ -1,4 +1,4 @@
|
|
1
|
-
zrb/__init__.py,sha256=
|
1
|
+
zrb/__init__.py,sha256=dQs1S6z3XbG1BeQ62YYxc6cUs5ejw9T9ajkPgNVEs34,2875
|
2
2
|
zrb/__main__.py,sha256=-_k0XOahDF-06n41Uly-oUMkZ8XDSxO-WUUImWz6GiA,171
|
3
3
|
zrb/action/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
zrb/action/runner.py,sha256=aB46inPOs7CDckfIsS_mlgQ92_bfKltcnb77PjW6Tfw,5179
|
@@ -1393,7 +1393,6 @@ zrb/shell-scripts/ssh-util.sh,sha256=9lXDzw6oO8HuA4vdbfps_uQMMwKyNYX9fZkZgpK52g8
|
|
1393
1393
|
zrb/task/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
1394
1394
|
zrb/task/any_task.py,sha256=SlAp6LY-8TGopaQm3eZD3ZEx3wxvCff8UfcnYyu-aiY,39344
|
1395
1395
|
zrb/task/any_task_event_handler.py,sha256=ay4v7eXatF4sCiXpUYaHVJZljpnKlvBbFIwvZqXW8Mo,541
|
1396
|
-
zrb/task/base_remote_cmd_task.py,sha256=EhAT7grnIxFeMfwm8FV6GF6n0kOYESAyIIVzqgZBRBg,12324
|
1397
1396
|
zrb/task/base_task/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
1398
1397
|
zrb/task/base_task/base_task.py,sha256=oihVRUHAvNMwlfLEWQoixt5OwyMLyW9w6bSGD9WGVIk,20457
|
1399
1398
|
zrb/task/base_task/component/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -1406,7 +1405,7 @@ zrb/task/checker.py,sha256=mh_2ajZqpNdJQ8AFVQ6ZArYtBUOXST3aZSisINuEivk,3400
|
|
1406
1405
|
zrb/task/cmd_task.py,sha256=B3kRtpb0QVjusPWAMLjpfGxvAdEfgD9_N0jiU55S3rA,14718
|
1407
1406
|
zrb/task/decorator.py,sha256=SuajollezbwiSOs29bv8A6PmFcFs_RH4pr4TPcQPDHM,3081
|
1408
1407
|
zrb/task/docker_compose_start_task.py,sha256=n4mLejebyy8sF4rbcfWZucPcBiqPSkDAdGZvOhk4Xt8,5335
|
1409
|
-
zrb/task/docker_compose_task.py,sha256=
|
1408
|
+
zrb/task/docker_compose_task.py,sha256=NuNevzooQVn3wgMNrBBdVD2FepRpE38ouYkRNXeqQ2s,15543
|
1410
1409
|
zrb/task/flow_task.py,sha256=wkvvUCrt6n1ul-o3STCPMdrlBuGBrNCRgtRzGyXir9o,5079
|
1411
1410
|
zrb/task/http_checker.py,sha256=gXqBlEStMnIhzmQ7FX9Zo-nG3-wsiVEML8IOJiSG5JI,5705
|
1412
1411
|
zrb/task/looper.py,sha256=zInLRgcQlReGXz4Ffxc2W99RovSChj6kHuGEGmaPb-Q,1432
|
@@ -1416,9 +1415,9 @@ zrb/task/path_checker.py,sha256=xkOpxlLUaEXlsiWh1o-ghqQNWYadXvTl3QV4yeIC2Rc,4677
|
|
1416
1415
|
zrb/task/path_watcher.py,sha256=aKWhT7Kuc_UJMr8SSY7ZZym-_rV526tEeIaKRRz3XYU,7419
|
1417
1416
|
zrb/task/port_checker.py,sha256=SG2yrAxdJgxdR6xymviB48K529o3Rnq_WhDJZDKgAQg,4605
|
1418
1417
|
zrb/task/recurring_task.py,sha256=wtZhi0DCDdVM7ecIgoXghQPTOQemrEvCY8xDJoaG1mo,7444
|
1419
|
-
zrb/task/remote_cmd_task.py,sha256=
|
1418
|
+
zrb/task/remote_cmd_task.py,sha256=LQxDoFxd6Z-ALQqgDOntenaqABzQ5ri1sHTOKwb2-WQ,5801
|
1420
1419
|
zrb/task/resource_maker.py,sha256=e6nmFJsVHHo8_sW5F-lBfkO_2RszrlXNoubh4rwM6UY,7644
|
1421
|
-
zrb/task/rsync_task.py,sha256=
|
1420
|
+
zrb/task/rsync_task.py,sha256=gryXNikhsJ4BXU3XzK15xF4KDUXAH8ydO36JdUwER-c,6034
|
1422
1421
|
zrb/task/server.py,sha256=zC8swQOu_3YkRtGFXuRGZqz6yEu--ZhNRgNwbR44uUA,6741
|
1423
1422
|
zrb/task/task.py,sha256=iHDyUMUh1uVGlMCQdVewdT3epCOHKNRKblC3G1WSKS0,2493
|
1424
1423
|
zrb/task/time_watcher.py,sha256=v01whCMTvul_vraVccy8A9rDBk-CL7HFvPOu8g1BC5s,5130
|
@@ -1441,8 +1440,8 @@ zrb/task_input/multiline_input.py,sha256=KNto5k5X1C6KE_A-vX0OjpQyjgCRJ6BR2PwHXNQ
|
|
1441
1440
|
zrb/task_input/password_input.py,sha256=95NlJ9xIq7z_evpAyR2XsBpeuWpBXd2Ezn3P7oDOttk,4360
|
1442
1441
|
zrb/task_input/str_input.py,sha256=0nje7vI9fs_xqQBbmKB8Yn7wevlWp9Qebv7f8-GmiXs,4350
|
1443
1442
|
zrb/task_input/task_input.py,sha256=WTj_qIQyRs-04-VotjNTcVyIuf6b2afInVoCQHoRmr0,2327
|
1444
|
-
zrb-0.
|
1445
|
-
zrb-0.
|
1446
|
-
zrb-0.
|
1447
|
-
zrb-0.
|
1448
|
-
zrb-0.
|
1443
|
+
zrb-0.27.0.dist-info/LICENSE,sha256=WfnGCl8G60EYOPAEkuc8C9m9pdXWDe08NsKj3TBbxsM,728
|
1444
|
+
zrb-0.27.0.dist-info/METADATA,sha256=TPjzJNyVNVgFbcSDdhyJfNhbtYoGW2WXl72M1YqS8wE,17094
|
1445
|
+
zrb-0.27.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
1446
|
+
zrb-0.27.0.dist-info/entry_points.txt,sha256=xTgXc1kBKYhJHEujdaSPHUcJT3-hbyP1mLgwkv-5sSk,40
|
1447
|
+
zrb-0.27.0.dist-info/RECORD,,
|
zrb/task/base_remote_cmd_task.py
DELETED
@@ -1,354 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
import pathlib
|
3
|
-
from collections.abc import Callable, Iterable, Mapping
|
4
|
-
from typing import Any, Optional, TypeVar, Union
|
5
|
-
|
6
|
-
from zrb.helper.accessories.color import colored
|
7
|
-
from zrb.helper.log import logger
|
8
|
-
from zrb.helper.typecheck import typechecked
|
9
|
-
from zrb.helper.typing import JinjaTemplate
|
10
|
-
from zrb.helper.util import to_snake_case
|
11
|
-
from zrb.task.any_task import AnyTask
|
12
|
-
from zrb.task.any_task_event_handler import (
|
13
|
-
OnFailed,
|
14
|
-
OnReady,
|
15
|
-
OnRetry,
|
16
|
-
OnSkipped,
|
17
|
-
OnStarted,
|
18
|
-
OnTriggered,
|
19
|
-
OnWaiting,
|
20
|
-
)
|
21
|
-
from zrb.task.base_task.base_task import BaseTask
|
22
|
-
from zrb.task.cmd_task import CmdTask, CmdVal
|
23
|
-
from zrb.task_env.env import Env
|
24
|
-
from zrb.task_env.env_file import EnvFile
|
25
|
-
from zrb.task_group.group import Group
|
26
|
-
from zrb.task_input.any_input import AnyInput
|
27
|
-
|
28
|
-
logger.debug(colored("Loading zrb.task.base_remote_cmd_task", attrs=["dark"]))
|
29
|
-
|
30
|
-
TSingleBaseRemoteCmdTask = TypeVar(
|
31
|
-
"TSingleBaseRemoteCmdTask", bound="SingleBaseRemoteCmdTask"
|
32
|
-
)
|
33
|
-
TBaseRemoteCmdTask = TypeVar("TBaseRemoteCmdTask", bound="BaseRemoteCmdTask")
|
34
|
-
|
35
|
-
|
36
|
-
@typechecked
|
37
|
-
class RemoteConfig:
|
38
|
-
def __init__(
|
39
|
-
self,
|
40
|
-
host: JinjaTemplate,
|
41
|
-
user: JinjaTemplate = "",
|
42
|
-
password: JinjaTemplate = "",
|
43
|
-
ssh_key: JinjaTemplate = "",
|
44
|
-
port: Union[int, JinjaTemplate] = 22,
|
45
|
-
name: Optional[str] = None,
|
46
|
-
config_map: Optional[Mapping[str, JinjaTemplate]] = None,
|
47
|
-
):
|
48
|
-
self.name = name if name is not None else host
|
49
|
-
self.host = host
|
50
|
-
self.user = user
|
51
|
-
self.password = password
|
52
|
-
self.ssh_key = ssh_key
|
53
|
-
self.port = port
|
54
|
-
self.config_map = {} if config_map is None else config_map
|
55
|
-
|
56
|
-
|
57
|
-
@typechecked
|
58
|
-
class SingleBaseRemoteCmdTask(CmdTask):
|
59
|
-
def __init__(
|
60
|
-
self,
|
61
|
-
name: str,
|
62
|
-
remote_config: RemoteConfig,
|
63
|
-
group: Optional[Group] = None,
|
64
|
-
inputs: Iterable[AnyInput] = [],
|
65
|
-
envs: Iterable[Env] = [],
|
66
|
-
env_files: Iterable[EnvFile] = [],
|
67
|
-
icon: Optional[str] = None,
|
68
|
-
color: Optional[str] = None,
|
69
|
-
description: str = "",
|
70
|
-
executable: Optional[str] = None,
|
71
|
-
pre_cmd: CmdVal = "",
|
72
|
-
pre_cmd_path: CmdVal = "",
|
73
|
-
cmd: CmdVal = "",
|
74
|
-
cmd_path: CmdVal = "",
|
75
|
-
post_cmd: CmdVal = "",
|
76
|
-
post_cmd_path: CmdVal = "",
|
77
|
-
cwd: Optional[Union[str, pathlib.Path]] = None,
|
78
|
-
should_render_cwd: bool = True,
|
79
|
-
upstreams: Iterable[AnyTask] = [],
|
80
|
-
fallbacks: Iterable[AnyTask] = [],
|
81
|
-
on_triggered: Optional[OnTriggered] = None,
|
82
|
-
on_waiting: Optional[OnWaiting] = None,
|
83
|
-
on_skipped: Optional[OnSkipped] = None,
|
84
|
-
on_started: Optional[OnStarted] = None,
|
85
|
-
on_ready: Optional[OnReady] = None,
|
86
|
-
on_retry: Optional[OnRetry] = None,
|
87
|
-
on_failed: Optional[OnFailed] = None,
|
88
|
-
checkers: Iterable[AnyTask] = [],
|
89
|
-
checking_interval: Union[float, int] = 0.05,
|
90
|
-
retry: int = 2,
|
91
|
-
retry_interval: Union[float, int] = 1,
|
92
|
-
max_output_line: int = 1000,
|
93
|
-
max_error_line: int = 1000,
|
94
|
-
preexec_fn: Optional[Callable[[], Any]] = os.setsid,
|
95
|
-
should_execute: Union[bool, str, Callable[..., bool]] = True,
|
96
|
-
return_upstream_result: bool = False,
|
97
|
-
should_print_cmd_result: bool = True,
|
98
|
-
should_show_cmd: bool = True,
|
99
|
-
should_show_working_directory: bool = True,
|
100
|
-
):
|
101
|
-
CmdTask.__init__(
|
102
|
-
self,
|
103
|
-
name=name,
|
104
|
-
group=group,
|
105
|
-
inputs=inputs,
|
106
|
-
envs=envs,
|
107
|
-
env_files=env_files,
|
108
|
-
icon=icon,
|
109
|
-
color=color,
|
110
|
-
description=description,
|
111
|
-
executable=executable,
|
112
|
-
cmd=cmd,
|
113
|
-
cmd_path=cmd_path,
|
114
|
-
cwd=cwd,
|
115
|
-
should_render_cwd=should_render_cwd,
|
116
|
-
upstreams=upstreams,
|
117
|
-
fallbacks=fallbacks,
|
118
|
-
on_triggered=on_triggered,
|
119
|
-
on_waiting=on_waiting,
|
120
|
-
on_skipped=on_skipped,
|
121
|
-
on_started=on_started,
|
122
|
-
on_ready=on_ready,
|
123
|
-
on_retry=on_retry,
|
124
|
-
on_failed=on_failed,
|
125
|
-
checkers=checkers,
|
126
|
-
checking_interval=checking_interval,
|
127
|
-
retry=retry,
|
128
|
-
retry_interval=retry_interval,
|
129
|
-
max_output_line=max_output_line,
|
130
|
-
max_error_line=max_error_line,
|
131
|
-
preexec_fn=preexec_fn,
|
132
|
-
should_execute=should_execute,
|
133
|
-
return_upstream_result=return_upstream_result,
|
134
|
-
should_print_cmd_result=should_print_cmd_result,
|
135
|
-
should_show_cmd=should_show_cmd,
|
136
|
-
should_show_working_directory=should_show_working_directory,
|
137
|
-
)
|
138
|
-
self._pre_cmd = pre_cmd
|
139
|
-
self._pre_cmd_path = pre_cmd_path
|
140
|
-
self._post_cmd = post_cmd
|
141
|
-
self._post_cmd_path = post_cmd_path
|
142
|
-
self._remote_config = remote_config
|
143
|
-
|
144
|
-
def copy(self) -> TSingleBaseRemoteCmdTask:
|
145
|
-
return super().copy()
|
146
|
-
|
147
|
-
def inject_envs(self):
|
148
|
-
super().inject_envs()
|
149
|
-
# add remote config properties as env
|
150
|
-
self.add_env(
|
151
|
-
Env(
|
152
|
-
name="_CONFIG_HOST",
|
153
|
-
os_name="",
|
154
|
-
default=self.render_str(self._remote_config.host),
|
155
|
-
),
|
156
|
-
Env(
|
157
|
-
name="_CONFIG_PORT",
|
158
|
-
os_name="",
|
159
|
-
default=str(self.render_int(self._remote_config.port)),
|
160
|
-
),
|
161
|
-
Env(
|
162
|
-
name="_CONFIG_SSH_KEY",
|
163
|
-
os_name="",
|
164
|
-
default=self.render_str(self._remote_config.ssh_key),
|
165
|
-
),
|
166
|
-
Env(
|
167
|
-
name="_CONFIG_USER",
|
168
|
-
os_name="",
|
169
|
-
default=self.render_str(self._remote_config.user),
|
170
|
-
),
|
171
|
-
Env(
|
172
|
-
name="_CONFIG_PASSWORD",
|
173
|
-
os_name="",
|
174
|
-
default=self.render_str(self._remote_config.password),
|
175
|
-
),
|
176
|
-
)
|
177
|
-
for key, val in self._remote_config.config_map.items():
|
178
|
-
upper_snake_key = to_snake_case(key).upper()
|
179
|
-
rendered_val = self.render_str(val)
|
180
|
-
# add remote config map as env
|
181
|
-
self.add_env(
|
182
|
-
Env(
|
183
|
-
name="_CONFIG_MAP_" + upper_snake_key,
|
184
|
-
os_name="",
|
185
|
-
default=rendered_val,
|
186
|
-
)
|
187
|
-
)
|
188
|
-
|
189
|
-
def get_cmd_script(self, *args: Any, **kwargs: Any) -> str:
|
190
|
-
cmd_str = "\n".join(
|
191
|
-
[
|
192
|
-
self._create_cmd_script(
|
193
|
-
self._pre_cmd_path, self._pre_cmd, *args, **kwargs
|
194
|
-
),
|
195
|
-
super().get_cmd_script(*args, **kwargs),
|
196
|
-
self._create_cmd_script(
|
197
|
-
self._post_cmd_path, self._post_cmd, *args, **kwargs
|
198
|
-
),
|
199
|
-
]
|
200
|
-
)
|
201
|
-
return cmd_str
|
202
|
-
|
203
|
-
|
204
|
-
@typechecked
|
205
|
-
class BaseRemoteCmdTask(BaseTask):
|
206
|
-
def __init__(
|
207
|
-
self,
|
208
|
-
name: str,
|
209
|
-
remote_configs: Iterable[RemoteConfig],
|
210
|
-
group: Optional[Group] = None,
|
211
|
-
inputs: Iterable[AnyInput] = [],
|
212
|
-
envs: Iterable[Env] = [],
|
213
|
-
env_files: Iterable[EnvFile] = [],
|
214
|
-
icon: Optional[str] = None,
|
215
|
-
color: Optional[str] = None,
|
216
|
-
description: str = "",
|
217
|
-
executable: Optional[str] = None,
|
218
|
-
pre_cmd: CmdVal = "",
|
219
|
-
pre_cmd_path: CmdVal = "",
|
220
|
-
cmd: CmdVal = "",
|
221
|
-
cmd_path: CmdVal = "",
|
222
|
-
post_cmd: CmdVal = "",
|
223
|
-
post_cmd_path: CmdVal = "",
|
224
|
-
cwd: Optional[Union[JinjaTemplate, pathlib.Path]] = None,
|
225
|
-
should_render_cwd: bool = True,
|
226
|
-
upstreams: Iterable[AnyTask] = [],
|
227
|
-
fallbacks: Iterable[AnyTask] = [],
|
228
|
-
on_triggered: Optional[OnTriggered] = None,
|
229
|
-
on_waiting: Optional[OnWaiting] = None,
|
230
|
-
on_skipped: Optional[OnSkipped] = None,
|
231
|
-
on_started: Optional[OnStarted] = None,
|
232
|
-
on_ready: Optional[OnReady] = None,
|
233
|
-
on_retry: Optional[OnRetry] = None,
|
234
|
-
on_failed: Optional[OnFailed] = None,
|
235
|
-
checkers: Iterable[AnyTask] = [],
|
236
|
-
checking_interval: Union[float, int] = 0.05,
|
237
|
-
retry: int = 2,
|
238
|
-
retry_interval: Union[float, int] = 1,
|
239
|
-
max_output_line: int = 1000,
|
240
|
-
max_error_line: int = 1000,
|
241
|
-
preexec_fn: Optional[Callable[[], Any]] = os.setsid,
|
242
|
-
should_execute: Union[bool, str, Callable[..., bool]] = True,
|
243
|
-
return_upstream_result: bool = False,
|
244
|
-
should_print_cmd_result: bool = True,
|
245
|
-
should_show_cmd: bool = True,
|
246
|
-
should_show_working_directory: bool = True,
|
247
|
-
):
|
248
|
-
self._remote_configs = list(remote_configs)
|
249
|
-
self._sub_tasks = [
|
250
|
-
SingleBaseRemoteCmdTask(
|
251
|
-
name=f"{name}-{remote_config.name}",
|
252
|
-
remote_config=remote_config,
|
253
|
-
inputs=inputs,
|
254
|
-
envs=envs,
|
255
|
-
env_files=env_files,
|
256
|
-
description=description,
|
257
|
-
executable=executable,
|
258
|
-
pre_cmd=pre_cmd,
|
259
|
-
pre_cmd_path=pre_cmd_path,
|
260
|
-
cmd=cmd,
|
261
|
-
cmd_path=cmd_path,
|
262
|
-
post_cmd=post_cmd,
|
263
|
-
post_cmd_path=post_cmd_path,
|
264
|
-
cwd=cwd,
|
265
|
-
should_render_cwd=should_render_cwd,
|
266
|
-
upstreams=upstreams,
|
267
|
-
fallbacks=fallbacks,
|
268
|
-
on_triggered=on_triggered,
|
269
|
-
on_waiting=on_waiting,
|
270
|
-
on_skipped=on_skipped,
|
271
|
-
on_started=on_started,
|
272
|
-
on_ready=on_ready,
|
273
|
-
on_retry=on_retry,
|
274
|
-
on_failed=on_failed,
|
275
|
-
checkers=checkers,
|
276
|
-
checking_interval=checking_interval,
|
277
|
-
retry=retry,
|
278
|
-
retry_interval=retry_interval,
|
279
|
-
max_output_line=max_output_line,
|
280
|
-
max_error_line=max_error_line,
|
281
|
-
preexec_fn=preexec_fn,
|
282
|
-
should_execute=should_execute,
|
283
|
-
return_upstream_result=return_upstream_result,
|
284
|
-
should_print_cmd_result=should_print_cmd_result,
|
285
|
-
should_show_cmd=should_show_cmd,
|
286
|
-
should_show_working_directory=should_show_working_directory,
|
287
|
-
)
|
288
|
-
for remote_config in self._remote_configs
|
289
|
-
]
|
290
|
-
BaseTask.__init__(
|
291
|
-
self,
|
292
|
-
name=name,
|
293
|
-
icon=icon,
|
294
|
-
color=color,
|
295
|
-
group=group,
|
296
|
-
description=description,
|
297
|
-
upstreams=self._sub_tasks,
|
298
|
-
retry=0,
|
299
|
-
return_upstream_result=True,
|
300
|
-
)
|
301
|
-
|
302
|
-
def insert_input(self, *inputs: AnyInput):
|
303
|
-
super().insert_input(*inputs)
|
304
|
-
for subtask in self._sub_tasks:
|
305
|
-
subtask.insert_input(*inputs)
|
306
|
-
|
307
|
-
def add_input(self, *inputs: AnyInput):
|
308
|
-
super().add_input(*inputs)
|
309
|
-
for subtask in self._sub_tasks:
|
310
|
-
subtask.add_input(*inputs)
|
311
|
-
|
312
|
-
def insert_env(self, *envs: Env):
|
313
|
-
super().insert_env(*envs)
|
314
|
-
for subtask in self._sub_tasks:
|
315
|
-
subtask.insert_env(*envs)
|
316
|
-
|
317
|
-
def add_env(self, *envs: Env):
|
318
|
-
super().add_env(*envs)
|
319
|
-
for subtask in self._sub_tasks:
|
320
|
-
subtask.add_env(*envs)
|
321
|
-
|
322
|
-
def insert_env_file(self, *env_files: EnvFile):
|
323
|
-
super().insert_env_file(*env_files)
|
324
|
-
for subtask in self._sub_tasks:
|
325
|
-
subtask.insert_env_file(*env_files)
|
326
|
-
|
327
|
-
def add_env_file(self, *env_files: Env):
|
328
|
-
super().add_env_file(*env_files)
|
329
|
-
for subtask in self._sub_tasks:
|
330
|
-
subtask.add_env_file(*env_files)
|
331
|
-
|
332
|
-
def insert_upstream(self, *upstreams: AnyTask):
|
333
|
-
for subtask in self._sub_tasks:
|
334
|
-
subtask.insert_upstream(*upstreams)
|
335
|
-
|
336
|
-
def add_upstream(self, *upstreams: AnyTask):
|
337
|
-
for subtask in self._sub_tasks:
|
338
|
-
subtask.add_upstream(*upstreams)
|
339
|
-
|
340
|
-
def insert_fallback(self, *fallbacks: AnyTask):
|
341
|
-
for subtask in self._sub_tasks:
|
342
|
-
subtask.insert_fallbacks(*fallbacks)
|
343
|
-
|
344
|
-
def add_fallback(self, *fallbacks: AnyTask):
|
345
|
-
for subtask in self._sub_tasks:
|
346
|
-
subtask.add_fallback(*fallbacks)
|
347
|
-
|
348
|
-
def insert_checker(self, *checkers: AnyTask):
|
349
|
-
for subtask in self._sub_tasks:
|
350
|
-
subtask.insert_checkers(*checkers)
|
351
|
-
|
352
|
-
def add_checker(self, *checkers: AnyTask):
|
353
|
-
for subtask in self._sub_tasks:
|
354
|
-
subtask.add_checker(*checkers)
|
File without changes
|
File without changes
|
File without changes
|