-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree
executable file
·78 lines (64 loc) · 1.62 KB
/
tree
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
# Prints an acyclic dependency tree of a set of tasks.
# Usage: task 3 export | tree sometag
# sometag is the name of the unique tag of the root task from which
# all its dependencies sprout. Defult is "goal".
#
# Example output:
# - [1] Root
# - [2] Subtask A
# - [3] Subtask B
# - [4] Subtask C
# - [5] Subtask D
# - [6] Subtask E
#
# The format is "- [id] description"
# Dependency relations are
# 1 -> 2,3
# 3 -> 4,5
# 5 -> 6
import sys
import json
if len(sys.argv) > 1:
root_tag = sys.argv[1]
if len(sys.argv) > 2:
period_attribute = sys.argv[2]
else:
root_tag = "goal"
period_attribute = "estimate"
tasks = json.load(sys.stdin)
root = None
for t in tasks:
if root_tag in t["tags"]:
root = t
break
if root == None:
print("No root task has required tag:", root_tag)
exit(0)
def subtasks(task):
uuids = task.get("depends")
sts = []
if uuids == None:
return sts
uuids = uuids.split(",")
for u in uuids:
for t in tasks:
if t.get("uuid") == u:
sts.append(t)
break
return sts
def print_tree(root, spaces):
o = "- [" + str(root["id"]) + "] "
if root.get("printed"):
o = o + "*** ALREADY PRINTED -> Circularity ***"
else:
o = o + root["description"] + " (" + root.get(period_attribute, "PT0S") + ")"
if spaces > 0:
o = " " * spaces + o
if root.get("status") in ["active", "pending"]:
print(o)
root["printed"] = True
sts = subtasks(root)
for st in sts:
print_tree(st, spaces + 2)
print_tree(root, 0)