#!/usr/bin/env python3 import config_pb2 import yaml def dict2pb(d, pb): for key in d: val = d[key] if isinstance(val, dict): dict2pb(val, getattr(pb, key)) else: setattr(pb, key, val) def main(): with open('./tools/config.yml', 'r') as configfile: config = yaml.load(configfile) if 'REVISION' in config: config_rev = config['REVISION'] del config['REVISION'] else: config_rev = 1 confpb = config_pb2.Config() dict2pb(config, confpb) pbdata = confpb.SerializeToString() pbdataarry = ','.join([str(int(b)) for b in pbdata]) cfile = """#include uint8_t CONFIG_DATA[] = {%s}; size_t CONFIG_DATA_LEN = %s; int CONFIG_REV = %s;""" % (pbdataarry, len(pbdata), int(config_rev)) print(cfile) if __name__ == "__main__": main()