Пример #1
0
def parse_server_list(product):
	global server_list
	global server_set
	if product == "mhxy" or product == "dh2":
		for cLine in server_list:
			#每一行数据 526 60.5.184.87 52688 大名府 dm
			line_set = cLine.split(" ")
			hostnum = line_set[0]
			ip = line_set[1]
			portnum = line_set[2]
			#cName = line_set[3].decode('gbk').encode('utf-8')
			cName = line_set[3]
			short_name = line_set[4][0:2]
			branch = line_set[5].strip()
			server_set[hostnum] = [ip, cName, short_name, portnum, branch]
	elif product == "dh3":
		from server_tag import synctaginfo
		for svn_tag , server_info_list in synctaginfo.items():
			for server_info in server_info_list:
				hostnum = server_info["serverid"]   #int
				#cName = server_info["name"].decode('gbk').encode('utf-8')
				cName = server_info["name"]
				ip = server_info["ip"]
				#试图从汉字转换成为首2字的拼音缩写,需要使用一个外部拼音字典
				import ch2py
				py = ch2py.ch2pr(cName)
				py_set = py.split(" ")
				if len(py_set) < 2:
					print "得到服务器缩写名字错误,hostnum %d name %s ip %s" %(hostnum, cName, ip)
					continue
				short_name = py_set[0][0] + py_set[1][0]
				server_set[str(hostnum)] = [ip, cName, short_name,svn_tag]
	
	else:
		print "错误的列表!"
		sys.exit(1)
	print "=============================="
	print "共有server %d 组" % len(server_set)
	print "=============================="