2017-07-02 23:01:23 +02:00
|
|
|
from io import StringIO
|
|
|
|
import glob
|
|
|
|
import collections
|
|
|
|
import json
|
|
|
|
|
2017-07-11 11:29:12 +02:00
|
|
|
formats = __import__("extract-formats")
|
|
|
|
|
|
|
|
|
2017-07-02 23:01:23 +02:00
|
|
|
class Options(object):
|
2017-07-11 11:29:12 +02:00
|
|
|
output_types = True
|
|
|
|
output_fields = True
|
|
|
|
check_alignment = False
|
|
|
|
|
2017-07-02 23:01:23 +02:00
|
|
|
|
|
|
|
options = Options()
|
|
|
|
csv = []
|
|
|
|
|
|
|
|
output = StringIO()
|
|
|
|
for i in sorted(glob.glob("../??-*.md")):
|
2017-07-11 11:29:12 +02:00
|
|
|
with open(i) as f:
|
|
|
|
formats.main(options, output=output, lines=f.readlines())
|
|
|
|
csvstr = output.getvalue().strip()
|
|
|
|
if csvstr == "":
|
|
|
|
continue
|
|
|
|
csv += csvstr.split("\n")
|
2017-07-02 23:01:23 +02:00
|
|
|
|
|
|
|
resmap = collections.OrderedDict()
|
|
|
|
|
|
|
|
currentmsgname = None
|
|
|
|
currentmsgfields = {}
|
|
|
|
typenum = None
|
|
|
|
for line in csv:
|
2017-07-11 11:29:12 +02:00
|
|
|
parts = line.split(",")
|
|
|
|
if len(parts) == 2:
|
|
|
|
if currentmsgname is not None:
|
|
|
|
resmap[currentmsgname] = collections.OrderedDict(
|
|
|
|
[("type", typenum), ("payload", currentmsgfields)])
|
|
|
|
currentmsgfields = collections.OrderedDict()
|
|
|
|
currentmsgname = parts[0]
|
|
|
|
typenum = parts[1]
|
|
|
|
continue
|
|
|
|
assert currentmsgname == parts[0], line
|
|
|
|
assert len(parts) == 4, line
|
|
|
|
position = parts[1]
|
|
|
|
length = parts[3]
|
|
|
|
fieldname = parts[2]
|
|
|
|
currentmsgfields[fieldname] = {"position": position, "length": length}
|
2017-07-02 23:01:23 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2017-07-11 11:29:12 +02:00
|
|
|
print(json.dumps(resmap, indent=True))
|