This repository has been archived by the owner on Jun 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
/
taskoverview.py
executable file
·82 lines (66 loc) · 2.42 KB
/
taskoverview.py
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
79
80
81
82
#!/usr/bin/python
import sys
import os.path
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
def generate_graph_data():
import bootstrapvz.common.tasks
import bootstrapvz.providers
import bootstrapvz.plugins
from bootstrapvz.base.tasklist import get_all_tasks
tasks = get_all_tasks([bootstrapvz.common.tasks, bootstrapvz.providers, bootstrapvz.plugins])
def distinct(seq):
seen = set()
return [x for x in seq if x not in seen and not seen.add(x)]
modules = distinct([task.__module__ for task in tasks])
task_links = []
task_links.extend([{'source': task,
'target': succ,
'definer': task,
}
for task in tasks
for succ in task.successors])
task_links.extend([{'source': pre,
'target': task,
'definer': task,
}
for task in tasks
for pre in task.predecessors])
def mk_phase(phase):
return {'name': phase.name,
'description': phase.description,
}
def mk_module(module):
return {'name': module,
}
from bootstrapvz.common import phases
def mk_node(task):
return {'name': task.__name__,
'module': modules.index(task.__module__),
'phase': (i for i, phase in enumerate(phases.order) if phase is task.phase).next(),
}
def mk_link(link):
for key in ['source', 'target', 'definer']:
link[key] = tasks.index(link[key])
return link
return {'phases': map(mk_phase, phases.order),
'modules': map(mk_module, modules),
'nodes': map(mk_node, tasks),
'links': map(mk_link, task_links)}
def write_data(data, output_path=None):
import json
if output_path is None:
import sys
json.dump(data, sys.stdout, indent=4, separators=(',', ': '))
else:
with open(output_path, 'w') as output:
json.dump(data, output)
if __name__ == '__main__' and __package__ is None:
from docopt import docopt
usage = """Usage: taskoverview.py [options]
Options:
--output <path> output
-h, --help show this help
"""
opts = docopt(usage)
data = generate_graph_data()
write_data(data, opts.get('--output', None))