#!/usr/bin/env python
#coding:utf8
import getopt
import json
import sys

def generate_definition(input_file, output_path, prefix):

	with open(input_file, 'r') as json_file:
		json_string = json_file.read()
		config_dict = json.loads(json_string)
		if not isinstance(config_dict,dict):
			sys.stderr.write('configuration file is not failed')
			exit(-1)

		with open(output_path, 'w') as o:
			o.write('/* Generated by EMControllerManagerHeaderGenerator, do not edit it manually. */\n\n\n')
			for controller_name in config_dict:
				if prefix is None:
					def_name = controller_name
				else:
					def_name = "%s_%s" % (prefix, controller_name)
				o.write('#define %s @"%s"\n' % (def_name, controller_name))
	

def main():
	try:
		options, args = getopt.getopt(sys.argv[1:],'i:o:p:')
	except Exception, e:
		print str(e)
		raise e

	input_file = None
	output_path = None
	prefix = None
	for o, a in options:
		if o == '-i':
			input_file = a
		elif o == '-o':
			output_path = a
		elif o == '-p':
			prefix = a

	if input_file is None or output_path is None:
		print "input error"
		exit(-1)
	generate_definition (input_file, output_path, prefix)

if __name__ == '__main__':
	main()

add a header generator