Skip to content

Commit 2db9194

Browse files
author
Alexander Willner
committed
cleanup
1 parent 33b0d06 commit 2db9194

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

things_cli/cli.py

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from xml.etree.ElementTree import Element, SubElement
1616

1717
import argcomplete # type: ignore
18-
1918
import things as api
19+
2020
from things_cli import __version__
2121

2222

@@ -58,44 +58,52 @@ def print_tasks(self, tasks):
5858
def gantt_dumps(self, tasks, array=None):
5959
"""Convert tasks into mermaid-js GANTT."""
6060

61-
for task in tasks:
62-
context = (
63-
task.get("project_title", None)
64-
or task.get("area_title", None)
65-
or task.get("heading_title", None)
66-
or task.get("start", None)
67-
or ""
68-
)
61+
result = ""
6962

70-
title = task["title"].replace(":", " ")
71-
start = task.get("start_date")
72-
deadline = task.get("deadline") or "1h"
73-
if not start and deadline != "1h":
74-
start = deadline
75-
if start == deadline:
76-
deadline = "1h"
77-
if deadline == "1h":
78-
visual = ":milestone"
79-
else:
80-
visual = ":active"
81-
# noqa todo: if in the past: done
82-
if start and not task.get("stop_date"):
83-
if context not in array:
84-
array[context] = []
85-
if not "".join(s for s in array[context] if title.lower() in s.lower()):
86-
array[context].append(
87-
f" {title} {visual}, {start}, {deadline}\n"
88-
)
63+
if array is None:
64+
array = {}
65+
66+
for task in tasks:
67+
ThingsCLI.gantt_add_task(task, array)
8968
self.gantt_dumps(task.get("items", []), array)
9069

91-
result = ""
9270
for group in array:
9371
result += f" section {group}\n"
9472
for item in array[group]:
9573
result += item
9674

9775
return result
9876

77+
@staticmethod
78+
def gantt_add_task(task, array):
79+
"""Add a task to a mermaid-js GANTT."""
80+
81+
context = (
82+
task.get("project_title", None)
83+
or task.get("area_title", None)
84+
or task.get("heading_title", None)
85+
or task.get("start", None)
86+
or ""
87+
)
88+
89+
title = task["title"].replace(":", " ")
90+
start = task.get("start_date")
91+
deadline = task.get("deadline") or "1h"
92+
if not start and deadline != "1h":
93+
start = deadline
94+
if start == deadline:
95+
deadline = "1h"
96+
if deadline == "1h":
97+
visual = ":milestone"
98+
else:
99+
visual = ":active"
100+
# noqa todo: if in the past: done
101+
if start and not task.get("stop_date"):
102+
if context not in array:
103+
array[context] = []
104+
if not "".join(s for s in array[context] if title.lower() in s.lower()):
105+
array[context].append(f" {title} {visual}, {start}, {deadline}\n")
106+
99107
def csv_dumps(self, tasks):
100108
"""Convert tasks into CSV."""
101109

@@ -183,7 +191,7 @@ def txt_dumps(self, tasks, indentation="", result=""):
183191
@classmethod
184192
def print_unimplemented(cls, command):
185193
"""Show warning that method is not yet implemented."""
186-
print("command '%s' not implemented yet" % command, file=sys.stderr)
194+
print(f"command '{command}' not implemented yet", file=sys.stderr)
187195

188196
@classmethod
189197
def get_parser(cls):
@@ -332,7 +340,7 @@ def get_parser(cls):
332340
"--version",
333341
"-v",
334342
action="version",
335-
version="%(prog)s (version {version})".format(version=__version__),
343+
version=f"%(prog)s (version {__version__})",
336344
)
337345

338346
argcomplete.autocomplete(parser)

0 commit comments

Comments
 (0)