-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_to_json.py
37 lines (32 loc) · 976 Bytes
/
export_to_json.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from collections import OrderedDict
import sys
import parser
import json
if __name__ == '__main__':
sm = parser.parse_filename(sys.argv[1])
data = OrderedDict({})
states = list(sm.all_states())
start = states[states.index(sm.start)]
data['start'] = start.name
data['current_state'] = start.name
data['states'] = {
s.name: dict(name=s.name, description=s.description)
for s in states
}
data['transitions'] = {}
for state in states:
data['transitions'][state.name] = {
code: target.name
for code, target in state.transitions.items()
}
data['events'] = [code for code in sm.all_event_codes()]
data['actions'] = {
state.name: [code.code for code in state.actions]
for state in states
}
data['bus_log'] = []
print('var data = {};'.format(
json.dumps(data, indent=4))
)