#!/usr/bin/python3 # -*- coding: utf-8 -*- import argparse import os import sys from MsgProtobuf import MsgProtobuf def main(): parser = argparse.ArgumentParser( description='Tool for generating the protobuf input file from the inputted message csv file' ) parser.add_argument('--output_dir', help='output directory for the generated Protobuf file', default='.') parser.add_argument('--namespace', help='namespace for protobuf package definition') parser.add_argument('csv', nargs='+', help='csv input file') parser.add_argument('protobuf', help='filename of outputted Protobuf file') args = parser.parse_args() if len(sys.argv) < 2: parser.print_help() else: msg_protobuf = MsgProtobuf() try: for csv in args.csv: msg_protobuf.load(csv) if args.output_dir is not None: os.makedirs(args.output_dir, exist_ok=True) msg_protobuf.write_proto(args.protobuf, args.namespace, args.output_dir) except Exception as e: print('Error: %s' % e) sys.exit(1) # msg_data.dump() if __name__ == "__main__": # calling main function main()