zrb 1.0.0a18__py3-none-any.whl → 1.0.0a19__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 +2 -0
- zrb/input/any_input.py +4 -0
- zrb/input/base_input.py +4 -4
- zrb/input/bool_input.py +1 -1
- zrb/input/float_input.py +2 -2
- zrb/input/int_input.py +1 -1
- zrb/input/option_input.py +2 -2
- zrb/input/password_input.py +2 -2
- zrb/input/text_input.py +2 -2
- zrb/runner/cli.py +2 -30
- zrb/runner/common_util.py +31 -0
- zrb/runner/web_app.py +20 -4
- zrb/runner/web_controller/static/pico.min.css +1 -1
- zrb/runner/web_controller/static/task-ui/common-util.js +63 -0
- zrb/runner/web_controller/static/task-ui/current-session.js +164 -0
- zrb/runner/web_controller/static/task-ui/event.js +120 -0
- zrb/runner/web_controller/static/task-ui/past-session.js +138 -0
- zrb/runner/web_controller/task_ui/controller.py +20 -19
- zrb/runner/web_controller/task_ui/view.html +12 -15
- {zrb-1.0.0a18.dist-info → zrb-1.0.0a19.dist-info}/METADATA +1 -1
- {zrb-1.0.0a18.dist-info → zrb-1.0.0a19.dist-info}/RECORD +23 -22
- zrb/runner/web_controller/task_ui/partial/common-util.js +0 -37
- zrb/runner/web_controller/task_ui/partial/main.js +0 -195
- zrb/runner/web_controller/task_ui/partial/show-existing-session.js +0 -97
- zrb/runner/web_controller/task_ui/partial/visualize-history.js +0 -104
- {zrb-1.0.0a18.dist-info → zrb-1.0.0a19.dist-info}/WHEEL +0 -0
- {zrb-1.0.0a18.dist-info → zrb-1.0.0a19.dist-info}/entry_points.txt +0 -0
zrb/__init__.py
CHANGED
@@ -27,6 +27,7 @@ from zrb.group.group import Group
|
|
27
27
|
from zrb.input.any_input import AnyInput
|
28
28
|
from zrb.input.base_input import BaseInput
|
29
29
|
from zrb.input.bool_input import BoolInput
|
30
|
+
from zrb.input.float_input import FloatInput
|
30
31
|
from zrb.input.int_input import IntInput
|
31
32
|
from zrb.input.option_input import OptionInput
|
32
33
|
from zrb.input.password_input import PasswordInput
|
@@ -73,6 +74,7 @@ assert CmdResult
|
|
73
74
|
assert CmdTask
|
74
75
|
assert HttpCheck
|
75
76
|
assert TcpCheck
|
77
|
+
assert FloatInput
|
76
78
|
assert IntInput
|
77
79
|
assert OptionInput
|
78
80
|
assert PasswordInput
|
zrb/input/any_input.py
CHANGED
zrb/input/base_input.py
CHANGED
@@ -42,14 +42,14 @@ class BaseInput(AnyInput):
|
|
42
42
|
def to_html(self, ctx: AnySharedContext) -> str:
|
43
43
|
name = self.name
|
44
44
|
description = self.description
|
45
|
-
default = self.
|
45
|
+
default = self.get_default_str(ctx)
|
46
46
|
return f'<input name="{name}" placeholder="{description}" value="{default}" />'
|
47
47
|
|
48
48
|
def update_shared_context(
|
49
49
|
self, shared_ctx: AnySharedContext, str_value: str | None = None
|
50
50
|
):
|
51
51
|
if str_value is None:
|
52
|
-
str_value = self.
|
52
|
+
str_value = self.get_default_str(shared_ctx)
|
53
53
|
value = self._parse_str_value(str_value)
|
54
54
|
if self.name in shared_ctx.input:
|
55
55
|
raise ValueError(f"Input already defined in the context: {self.name}")
|
@@ -75,7 +75,7 @@ class BaseInput(AnyInput):
|
|
75
75
|
|
76
76
|
def _prompt_cli_str(self, shared_ctx: AnySharedContext) -> str:
|
77
77
|
prompt_message = self.prompt_message
|
78
|
-
default_value = self.
|
78
|
+
default_value = self.get_default_str(shared_ctx)
|
79
79
|
if default_value != "":
|
80
80
|
prompt_message = f"{prompt_message} [{default_value}]"
|
81
81
|
print(f"{prompt_message}: ", end="")
|
@@ -84,7 +84,7 @@ class BaseInput(AnyInput):
|
|
84
84
|
value = default_value
|
85
85
|
return value
|
86
86
|
|
87
|
-
def
|
87
|
+
def get_default_str(self, shared_ctx: AnySharedContext) -> str:
|
88
88
|
return get_str_attr(
|
89
89
|
shared_ctx, self._default_str, auto_render=self._auto_render
|
90
90
|
)
|
zrb/input/bool_input.py
CHANGED
@@ -26,7 +26,7 @@ class BoolInput(BaseInput):
|
|
26
26
|
def to_html(self, ctx: AnySharedContext) -> str:
|
27
27
|
name = self.name
|
28
28
|
description = self.description
|
29
|
-
default = to_boolean(self.
|
29
|
+
default = to_boolean(self.get_default_str(ctx))
|
30
30
|
selected_true = "selected" if default else ""
|
31
31
|
selected_false = "selected" if not default else ""
|
32
32
|
return "\n".join(
|
zrb/input/float_input.py
CHANGED
@@ -25,8 +25,8 @@ class FloatInput(BaseInput):
|
|
25
25
|
def to_html(self, ctx: AnySharedContext) -> str:
|
26
26
|
name = self.name
|
27
27
|
description = self.description
|
28
|
-
default = self.
|
29
|
-
return f'<input type="number" name="{name}" placeholder="{description}" value="{default}" />' # noqa
|
28
|
+
default = self.get_default_str(ctx)
|
29
|
+
return f'<input type="number" name="{name}" placeholder="{description}" value="{default}" step="any" />' # noqa
|
30
30
|
|
31
31
|
def _parse_str_value(self, str_value: str) -> float:
|
32
32
|
return float(str_value)
|
zrb/input/int_input.py
CHANGED
@@ -25,7 +25,7 @@ class IntInput(BaseInput):
|
|
25
25
|
def to_html(self, ctx: AnySharedContext) -> str:
|
26
26
|
name = self.name
|
27
27
|
description = self.description
|
28
|
-
default = self.
|
28
|
+
default = self.get_default_str(ctx)
|
29
29
|
return f'<input type="number" step="1" name="{name}" placeholder="{description}" value="{default}" />' # noqa
|
30
30
|
|
31
31
|
def _parse_str_value(self, str_value: str) -> int:
|
zrb/input/option_input.py
CHANGED
@@ -28,7 +28,7 @@ class OptionInput(BaseInput):
|
|
28
28
|
def to_html(self, ctx: AnySharedContext) -> str:
|
29
29
|
name = self.name
|
30
30
|
description = self.description
|
31
|
-
default = self.
|
31
|
+
default = self.get_default_str(ctx)
|
32
32
|
html = [f'<select name="{name}" placeholder="{description}">']
|
33
33
|
for value in get_str_list_attr(ctx, self._options, self._auto_render):
|
34
34
|
selected = "selected" if value == default else ""
|
@@ -38,7 +38,7 @@ class OptionInput(BaseInput):
|
|
38
38
|
|
39
39
|
def _prompt_cli_str(self, shared_ctx: AnySharedContext) -> str:
|
40
40
|
prompt_message = self.prompt_message
|
41
|
-
default_value = self.
|
41
|
+
default_value = self.get_default_str(shared_ctx)
|
42
42
|
options = get_str_list_attr(shared_ctx, self._options, self._auto_render)
|
43
43
|
option_str = ", ".join(options)
|
44
44
|
if default_value != "":
|
zrb/input/password_input.py
CHANGED
@@ -28,12 +28,12 @@ class PasswordInput(BaseInput):
|
|
28
28
|
def to_html(self, ctx: AnySharedContext) -> str:
|
29
29
|
name = self.name
|
30
30
|
description = self.description
|
31
|
-
default = self.
|
31
|
+
default = self.get_default_str(ctx)
|
32
32
|
return f'<input type="password" name="{name}" placeholder="{description}" value="{default}" />' # noqa
|
33
33
|
|
34
34
|
def _prompt_cli_str(self, shared_ctx: AnySharedContext) -> str:
|
35
35
|
prompt_message = self.prompt_message
|
36
|
-
default_value = self.
|
36
|
+
default_value = self.get_default_str(shared_ctx)
|
37
37
|
value = getpass.getpass(f"{prompt_message}: ")
|
38
38
|
if value.strip() == "":
|
39
39
|
value = default_value
|
zrb/input/text_input.py
CHANGED
@@ -57,7 +57,7 @@ class TextInput(BaseInput):
|
|
57
57
|
def to_html(self, ctx: AnySharedContext) -> str:
|
58
58
|
name = self.name
|
59
59
|
description = self.description
|
60
|
-
default = self.
|
60
|
+
default = self.get_default_str(ctx)
|
61
61
|
return "\n".join(
|
62
62
|
[
|
63
63
|
f'<textarea name="{name}" placeholder="{description}">',
|
@@ -71,7 +71,7 @@ class TextInput(BaseInput):
|
|
71
71
|
f"{self.comment_start}{super().prompt_message}{self.comment_end}"
|
72
72
|
)
|
73
73
|
prompt_message_eol = f"{prompt_message}\n"
|
74
|
-
default_value = self.
|
74
|
+
default_value = self.get_default_str(shared_ctx)
|
75
75
|
with tempfile.NamedTemporaryFile(
|
76
76
|
delete=False, suffix=self._extension
|
77
77
|
) as temp_file:
|
zrb/runner/cli.py
CHANGED
@@ -5,6 +5,7 @@ from zrb.config import BANNER, WEB_HTTP_PORT
|
|
5
5
|
from zrb.context.any_context import AnyContext
|
6
6
|
from zrb.context.shared_context import SharedContext
|
7
7
|
from zrb.group.group import Group
|
8
|
+
from zrb.runner.common_util import get_run_kwargs
|
8
9
|
from zrb.runner.web_app import create_app
|
9
10
|
from zrb.session.session import Session
|
10
11
|
from zrb.task.any_task import AnyTask
|
@@ -30,7 +31,7 @@ class Cli(Group):
|
|
30
31
|
if "h" in kwargs or "help" in kwargs:
|
31
32
|
self._show_task_info(node)
|
32
33
|
return
|
33
|
-
run_kwargs =
|
34
|
+
run_kwargs = get_run_kwargs(task=node, args=args, kwargs=kwargs, prompt=True)
|
34
35
|
try:
|
35
36
|
result = self._run_task(node, args, run_kwargs)
|
36
37
|
if result is not None:
|
@@ -72,35 +73,6 @@ class Cli(Group):
|
|
72
73
|
continue
|
73
74
|
return task.run(Session(shared_ctx=shared_ctx, root_group=self))
|
74
75
|
|
75
|
-
def _get_run_kwargs(
|
76
|
-
self, task: AnyTask, args: list[str], kwargs: dict[str, str]
|
77
|
-
) -> tuple[Any]:
|
78
|
-
arg_index = 0
|
79
|
-
str_kwargs = {key: val for key, val in kwargs.items()}
|
80
|
-
run_kwargs = {**str_kwargs}
|
81
|
-
shared_ctx = SharedContext(args=args)
|
82
|
-
for task_input in task.inputs:
|
83
|
-
if task_input.name in str_kwargs:
|
84
|
-
# Update shared context for next input default value
|
85
|
-
task_input.update_shared_context(
|
86
|
-
shared_ctx, str_kwargs[task_input.name]
|
87
|
-
)
|
88
|
-
elif arg_index < len(args):
|
89
|
-
run_kwargs[task_input.name] = args[arg_index]
|
90
|
-
# Update shared context for next input default value
|
91
|
-
task_input.update_shared_context(
|
92
|
-
shared_ctx, run_kwargs[task_input.name]
|
93
|
-
)
|
94
|
-
arg_index += 1
|
95
|
-
else:
|
96
|
-
str_value = task_input.prompt_cli_str(shared_ctx)
|
97
|
-
run_kwargs[task_input.name] = str_value
|
98
|
-
# Update shared context for next input default value
|
99
|
-
task_input.update_shared_context(
|
100
|
-
shared_ctx, run_kwargs[task_input.name]
|
101
|
-
)
|
102
|
-
return run_kwargs
|
103
|
-
|
104
76
|
def _show_task_info(self, task: AnyTask):
|
105
77
|
description = task.description
|
106
78
|
inputs = task.inputs
|
@@ -0,0 +1,31 @@
|
|
1
|
+
from typing import Any
|
2
|
+
|
3
|
+
from zrb.context.shared_context import SharedContext
|
4
|
+
from zrb.task.any_task import AnyTask
|
5
|
+
|
6
|
+
|
7
|
+
def get_run_kwargs(
|
8
|
+
task: AnyTask, args: list[str], kwargs: dict[str, str], prompt: bool = True
|
9
|
+
) -> tuple[Any]:
|
10
|
+
arg_index = 0
|
11
|
+
str_kwargs = {key: val for key, val in kwargs.items()}
|
12
|
+
run_kwargs = {**str_kwargs}
|
13
|
+
shared_ctx = SharedContext(args=args)
|
14
|
+
for task_input in task.inputs:
|
15
|
+
if task_input.name in str_kwargs:
|
16
|
+
# Update shared context for next input default value
|
17
|
+
task_input.update_shared_context(shared_ctx, str_kwargs[task_input.name])
|
18
|
+
elif arg_index < len(args):
|
19
|
+
run_kwargs[task_input.name] = args[arg_index]
|
20
|
+
# Update shared context for next input default value
|
21
|
+
task_input.update_shared_context(shared_ctx, run_kwargs[task_input.name])
|
22
|
+
arg_index += 1
|
23
|
+
else:
|
24
|
+
if prompt:
|
25
|
+
str_value = task_input.prompt_cli_str(shared_ctx)
|
26
|
+
else:
|
27
|
+
str_value = task_input.get_default_str(shared_ctx)
|
28
|
+
run_kwargs[task_input.name] = str_value
|
29
|
+
# Update shared context for next input default value
|
30
|
+
task_input.update_shared_context(shared_ctx, run_kwargs[task_input.name])
|
31
|
+
return run_kwargs
|
zrb/runner/web_app.py
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
import asyncio
|
2
|
+
import json
|
2
3
|
import os
|
3
4
|
import sys
|
4
5
|
from datetime import datetime, timedelta
|
5
|
-
from typing import Any
|
6
6
|
|
7
7
|
from zrb.config import BANNER, WEB_HTTP_PORT
|
8
8
|
from zrb.context.shared_context import SharedContext
|
9
9
|
from zrb.group.any_group import AnyGroup
|
10
|
+
from zrb.runner.common_util import get_run_kwargs
|
10
11
|
from zrb.runner.web_controller.group_info_ui.controller import handle_group_info_ui
|
11
12
|
from zrb.runner.web_controller.home_page.controller import handle_home_page
|
12
13
|
from zrb.runner.web_controller.task_ui.controller import handle_task_ui
|
@@ -76,9 +77,7 @@ def create_app(root_group: AnyGroup, port: int = WEB_HTTP_PORT):
|
|
76
77
|
raise HTTPException(status_code=404, detail="Not Found")
|
77
78
|
|
78
79
|
@app.post("/api/sessions/{path:path}")
|
79
|
-
async def create_new_session(
|
80
|
-
path: str, request: Request = None
|
81
|
-
) -> NewSessionResponse:
|
80
|
+
async def create_new_session(path: str, request: Request) -> NewSessionResponse:
|
82
81
|
"""
|
83
82
|
Creating new session
|
84
83
|
"""
|
@@ -96,6 +95,23 @@ def create_app(root_group: AnyGroup, port: int = WEB_HTTP_PORT):
|
|
96
95
|
return NewSessionResponse(session_name=session.name)
|
97
96
|
raise HTTPException(status_code=404, detail="Not Found")
|
98
97
|
|
98
|
+
@app.get("/api/inputs/{path:path}", response_model=dict[str, str])
|
99
|
+
async def get_default_inputs(
|
100
|
+
path: str, query: str = Query("{}", description="JSON encoded inputs")
|
101
|
+
):
|
102
|
+
"""
|
103
|
+
Getting input completion for path
|
104
|
+
"""
|
105
|
+
args = path.strip("/").split("/")
|
106
|
+
task, _, _ = extract_node_from_args(root_group, args)
|
107
|
+
if isinstance(task, AnyTask):
|
108
|
+
query_dict = json.loads(query)
|
109
|
+
run_kwargs = get_run_kwargs(
|
110
|
+
task=task, args=[], kwargs=query_dict, prompt=False
|
111
|
+
)
|
112
|
+
return run_kwargs
|
113
|
+
raise HTTPException(status_code=404, detail="Not Found")
|
114
|
+
|
99
115
|
@app.get(
|
100
116
|
"/api/sessions/{path:path}",
|
101
117
|
response_model=SessionStateLog | SessionStateLogList,
|