MSP device support complete. NOT TESTED YET! Preliminary python host lib
[cerebrum.git] / generatefw.py
blob5bdfca90fca524d7c434f350547f74cc38141402
1 #!/usr/bin/env python3
3 import sys
4 import os
5 import json
6 import imp
8 desc = json.JSONDecoder().decode('\n'.join(sys.stdin.readlines()))
10 # I think it is better to just let it throw an error
11 #if "dev" not in desc or "log" not in desc:
12 # exit(1)
14 for devicename, dev in desc["dev"].items():
15 dev = desc["dev"][devicename]
16 typepath = os.path.join(os.path.dirname(__file__), dev["type"], "generate.py")
17 # if not os.path.exists(typepath):
18 # print("Cannot find a handler for endpoint type " + dev["type"])
19 # exit(1)
20 #known type
21 print(typepath)
22 ctx = imp.load_source("generate", typepath)
23 deviceconfig = ctx.generate(dev, devicename)
24 with open(os.path.join(os.path.dirname(__file__), "builds", devicename + '.config.json'), 'w') as f:
25 f.write(json.JSONEncoder(indent=4).encode(deviceconfig))
26 ctx.commit(dev)