Skip to content

Commit

Permalink
Fix todo list
Browse files Browse the repository at this point in the history
  • Loading branch information
goFrendiAsgard committed Nov 27, 2024
1 parent 76cfafb commit 94b4223
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "zrb"
version = "1.0.0a3"
version = "1.0.0a4"
description = "Your Automation Powerhouse"
authors = ["Go Frendi Gunawan <[email protected]>"]
license = "AGPL-3.0-or-later"
Expand Down
4 changes: 3 additions & 1 deletion src/zrb/__main__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import sys

from zrb.runner.cli import cli
from zrb.util.cli.style import stylize_error
from zrb.util.cli.style import stylize_error, stylize_warning
from zrb.util.group import NodeNotFoundError


def serve_cli():
try:
cli.run(sys.argv[1:])
except KeyboardInterrupt:
print(stylize_warning("\nStopped"), file=sys.stderr)
except NodeNotFoundError as e:
print(stylize_error(f"{e}"), file=sys.stderr)
20 changes: 19 additions & 1 deletion src/zrb/builtin/todo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime
import json
import os
from typing import Any

from zrb.builtin.group import todo_group
from zrb.config import TODO_DIR
Expand Down Expand Up @@ -154,10 +156,26 @@ def todo_log(ctx: AnyContext):
todo_task = cascade_todo_task(todo_task)
current_duration = todo_task.keyval.get("duration", "0")
todo_task.keyval["duration"] = add_durations(current_duration, ctx.input.duration)
print(current_duration, todo_task.keyval)
# Save todo list
save_todo_list(todo_file_path, todo_list)
# Add log work
# TODO
log_work_dir = os.path.join(TODO_DIR, "log-work")
os.makedirs(log_work_dir, exist_ok=True)
log_work_file_path = os.path.join(
log_work_dir, f"{todo_task.keyval.get('id')}.json"
)
if os.path.isfile(log_work_file_path):
with open(log_work_file_path, "r") as f:
log_work_json = f.read()
else:
log_work_json = "[]"
log_work: list[dict[str, Any]] = json.loads(log_work_json)
log_work.append(
{"log": ctx.input.log, "duration": ctx.input.duration, "start": ctx.input.start}
)
with open(log_work_file_path, "w") as f:
f.write(json.dumps(log_work, indent=2))
return get_visual_todo_list(todo_list)


Expand Down
7 changes: 2 additions & 5 deletions src/zrb/runner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _get_run_command(self, node_path: list[str], run_kwargs: dict[str, str]) ->
return " ".join(parts)

def _get_run_command_param(self, key: str, val: str) -> str:
if '"' in val or "'" in val or " " in val:
if '"' in val or "'" in val or " " in val or val == "":
return f"--{key} {double_quote(val)}"
return f"--{key} {val}"

Expand All @@ -71,10 +71,7 @@ def _run_task(
shared_ctx, run_kwargs[task_input.name]
)
continue
try:
return task.run(Session(shared_ctx=shared_ctx, root_group=self))
except KeyboardInterrupt:
pass
return task.run(Session(shared_ctx=shared_ctx, root_group=self))

def _get_run_kwargs(
self, task: AnyTask, args: list[str], kwargs: dict[str, str]
Expand Down
2 changes: 1 addition & 1 deletion src/zrb/util/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,4 @@ def _format_duration(total_seconds: int) -> str:
if total_seconds >= value_in_seconds:
amount, total_seconds = divmod(total_seconds, value_in_seconds)
result.append(f"{amount}{unit}")
return " ".join(result) if result else "0s"
return "".join(result) if result else "0s"

0 comments on commit 94b4223

Please sign in to comment.