示例#1
0
def gen_py(xml_path, xml_name, gen_py_path):
	xmlname = xml_path + xml_name + r".xml";
	gen_py_name = gen_py_path + xml_name + r".py";
	print xmlname;
	print gen_py_name;
############################################################
	#生成.py
	g_file.open(gen_py_name, "w");
	gen_py_header_detailed(g_file);
	parse.get_xml_data_structs(xmlname);
	gen_py_detailed(g_file, parse.g_structs_data);
	parse.get_xml_data_protocols(xmlname);
	gen_py_detailed(g_file, parse.g_structs_data);
	
	parse.get_xml_data_protocols_cmd(xmlname);
	gen_py_cmd_map(g_file, parse.g_structs_data);
	g_file.close();
示例#2
0
def gen_cpp(xml_path, xml_name, gen_cpp_path):
	xmlname = xml_path + xml_name + r".xml";
	gen_cpp_name = gen_cpp_path + xml_name + r".h";
	gen_cpp_name_new = gen_cpp_path + xml_name + r".h.new";
	gen_cpp_cmd_name_pre = gen_cpp_path + xml_name;# + r"_cmd.h";
	############################################################
	#写到临时文件 .xxx.h.new 中
	g_file.open(gen_cpp_name_new, "w");
	gen_cpp_header_detailed(g_file, xml_name);
	parse.get_xml_data_structs(xmlname);
	gen_cpp_detailed(g_file, parse.g_structs_data, " : public el::lib_msg_t");
	parse.get_xml_data_protocols(xmlname);
	gen_cpp_detailed(g_file, parse.g_structs_data, " : public el::lib_msg_t");
	g_file.write_line(r"#pragma pack()", 0, 2);
	g_file.close();
	
	new_md5 = gen_md5_key(gen_cpp_name_new);
	os.remove(gen_cpp_name_new);
	
	old_md5 = gen_md5_key(gen_cpp_name);
	
#	print new_md5;
#	print old_md5;
	
#	if new_md5 != old_md5:
	print "change xml file:" + xmlname;
	#############################################################
	g_file.open(gen_cpp_name, "w");
	gen_cpp_header_detailed(g_file, xml_name);
	parse.get_xml_data_structs(xmlname);
	gen_cpp_detailed(g_file, parse.g_structs_data, " : public el::lib_msg_t");
	parse.get_xml_data_protocols(xmlname);
	gen_cpp_detailed(g_file, parse.g_structs_data, " : public el::lib_msg_t");
	g_file.write_line(r"#pragma pack()", 0, 2);
	g_file.close();
	
	parse.get_xml_data_protocols_cmd(xmlname);
	gen_cpp_cmd(parse.g_structs_data, gen_cpp_cmd_name_pre);