|
15 | 15 | from xml.etree.ElementTree import Element, SubElement |
16 | 16 |
|
17 | 17 | import argcomplete # type: ignore |
18 | | - |
19 | 18 | import things as api |
| 19 | + |
20 | 20 | from things_cli import __version__ |
21 | 21 |
|
22 | 22 |
|
@@ -58,44 +58,52 @@ def print_tasks(self, tasks): |
58 | 58 | def gantt_dumps(self, tasks, array=None): |
59 | 59 | """Convert tasks into mermaid-js GANTT.""" |
60 | 60 |
|
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 = "" |
69 | 62 |
|
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) |
89 | 68 | self.gantt_dumps(task.get("items", []), array) |
90 | 69 |
|
91 | | - result = "" |
92 | 70 | for group in array: |
93 | 71 | result += f" section {group}\n" |
94 | 72 | for item in array[group]: |
95 | 73 | result += item |
96 | 74 |
|
97 | 75 | return result |
98 | 76 |
|
| 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 | + |
99 | 107 | def csv_dumps(self, tasks): |
100 | 108 | """Convert tasks into CSV.""" |
101 | 109 |
|
@@ -183,7 +191,7 @@ def txt_dumps(self, tasks, indentation="", result=""): |
183 | 191 | @classmethod |
184 | 192 | def print_unimplemented(cls, command): |
185 | 193 | """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) |
187 | 195 |
|
188 | 196 | @classmethod |
189 | 197 | def get_parser(cls): |
@@ -332,7 +340,7 @@ def get_parser(cls): |
332 | 340 | "--version", |
333 | 341 | "-v", |
334 | 342 | action="version", |
335 | | - version="%(prog)s (version {version})".format(version=__version__), |
| 343 | + version=f"%(prog)s (version {__version__})", |
336 | 344 | ) |
337 | 345 |
|
338 | 346 | argcomplete.autocomplete(parser) |
|
0 commit comments