Exemplo n.º 1
0
def converter_mapmonsterdb_data(excel_file, sheet_name):
	book = xlrd.open_workbook(excel_file)
	sheet = book.sheet_by_name(sheet_name)
	print sheet.name

	data_template = '["%(s0)s"] = {\n%(s2)s\n'+' '*20+'}'

	rows_text = ''
	last_row_s0 = ''
	row_dict = {}
	row_list = ''

	for i in xrange(1, sheet.nrows):
		# 循环sheet中的行
		current_row_s0 = _utf8(sheet.cell_value(i,0))
		if last_row_s0 == '':
			last_row_s0 = current_row_s0
		if last_row_s0 != current_row_s0:
			if row_list != '':
				row_list = row_list[:-2]
			row_dict['s2'] = row_list
			row_data = data_template % row_dict
			rows_text = rows_text + ' ' * 12 + row_data + ',\n'
			row_dict = {}
			row_list = ''
			last_row_s0 = current_row_s0

		row_dict['s0'] = current_row_s0
		row_data = "[%d]={%d,'%s', %d, %d}, \n" % (int(sheet.cell_value(i,1)), int(sheet.cell_value(i,2)), _utf8(sheet.cell_value(i,3)), int(sheet.cell_value(i,4)), int(sheet.cell_value(i,5)))
		row_list = row_list + ' ' * 22 + row_data

	if row_list != '':
		row_list = row_list[:-2]
	row_dict['s2'] = row_list
	row_data = data_template % row_dict
	rows_text = rows_text + ' ' * 12 + row_data + ',\n'
	return rows_text[:-2]
Exemplo n.º 2
0
def converter_mapmonsterdb_data2(excel_file, sheet_name):
	book = xlrd.open_workbook(excel_file)
	sheet = book.sheet_by_name(sheet_name)
	print sheet.name

	data_template1 = '[%(s0)d] = {\n%(s2)s\n'+' '*20+'}'
	data_template2 = '["%(s0)s"] = {\n%(s2)s\n'+' '*20+'}'
	rows_text = ''
	last_row_s0 = ''


	map_dict = {}
	map_txt = ''

	row_dict = {}
	row_list = ''
	last_row_d0 = 0
	last_row_s1 = ''

	for i in xrange(1, sheet.nrows):
		# 循环sheet中的行
		current_row_d0 = int(sheet.cell_value(i,0))
		current_row_s1 = _utf8(sheet.cell_value(i,1))
		if last_row_d0 == 0:
			last_row_d0 = current_row_d0
		if last_row_d0 != current_row_d0:
			if row_list != '':
				row_list = row_list[:-2]
			row_dict['s2'] = row_list
			row_data = data_template2 % row_dict
			rows_text = rows_text + ' ' * 24 + row_data + ',\n'
			if rows_text != '':
				rows_text = rows_text[:-2]
			map_dict['s2'] = rows_text
			map_data = data_template1 % map_dict
			map_txt = map_txt + ' ' * 12 + map_data + ',\n'
			map_dict = {}
			row_dict = {}
			row_list = ''
			rows_text = ''
			last_row_s1 = ''
			last_row_d0 = current_row_d0
		else:
			if last_row_s1 == '':
				last_row_s1 = current_row_s1
			if last_row_s1 != current_row_s1:
				if row_list != '':
					row_list = row_list[:-2]
				row_dict['s2'] = row_list
				row_data = data_template2 % row_dict
				rows_text = rows_text + ' ' * 24 + row_data + ',\n'
				row_list = ''
				row_dict = {}
				last_row_s1 = current_row_s1
		row_dict['s0'] = current_row_s1
		row_data = "[%d]={%d,'%s', %d, %d}, \n" % (int(sheet.cell_value(i,2)), int(sheet.cell_value(i,3)), _utf8(sheet.cell_value(i,4)), int(sheet.cell_value(i,5)), int(sheet.cell_value(i,6)))
		row_list = row_list + ' ' * 34 + row_data
		map_dict['s0'] = current_row_d0

	row_dict['s2'] = row_list
	row_data = data_template2 % row_dict
	rows_text = rows_text + ' ' * 24 + row_data + ',\n'	
	if rows_text != '':
		rows_text = rows_text[:-2]
	map_dict['s2'] = rows_text
	map_data = data_template1 % map_dict
	map_txt = map_txt + ' ' * 12 + map_data + ',\n'
	return map_txt[:-2]
Exemplo n.º 3
0
def convertImg(argv_type, argv_line, argv_platform, argv_lang, argv_start, argv_end):
    """
    """

    diff_flag = False
    if argv_start != -1 and argv_end != -1:
        diff_flag = True

    diff_list = list()
    if diff_flag:
        diff_list = getDiffList(argv_start, argv_end, argv_line)

    print diff_list

    excel_file = "plist.xls"  # excel配置文件,xls格式
    client_template = "resDB.lua"  # 后端配置文件模版
    client_output = "resDB.lua"  #  后端配置输出文件
    plist_dict = converter_plist(excel_file, "plist", argv_type, argv_lang)

    # 公共资源列表
    book = xlrd.open_workbook("plist.xls")
    sheet = book.sheet_by_name("platform")
    print sheet.name
    publicres_dict = {}
    for i in xrange(1, sheet.nrows):
        # 循环sheet中的行
        row_key = _utf8(sheet.cell_value(i, 0))
        publicres_dict[row_key] = ""

    # 多语言资源列表
    book = xlrd.open_workbook("plist.xls")
    sheet = book.sheet_by_name("language")
    print sheet.name
    languageres_dict = {}
    for i in xrange(1, sheet.nrows):
        # 循环sheet中的行
        row_key = _utf8(sheet.cell_value(i, 0))
        languageres_dict[row_key] = ""

    # 生成resDB
    row_texts = ""

    # win32不做plist
    need_raise = False
    if argv_type != "win32":
        for row_key, row_value in plist_dict.iteritems():
            # 处理图片
            for j in xrange(0, len(row_value)):
                # 拆分目录
                img_flag = row_value[j][0]
                img_name = row_value[j][1]

                img_flag = getImageFlag(img_name)

                if img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_JSON or img_flg == IMAGE_FLAG_CSB:
                    continue

                # 查找是否多平台文件
                continue_flag, target_name = getPublicresFlag(img_name, publicres_dict, argv_platform)

                if continue_flag:
                    continue
                else:
                    img_name = target_name

                # 查找是否多语言文件
                continue_flag, target_name = getLanguageresFlag(img_name, languageres_dict, argv_lang)

                if continue_flag:
                    continue
                else:
                    img_name = target_name

                img_path = os.path.splitext(img_name)[0]

                if img_flag == 4:
                    img_path = os.path.splitext(os.path.basename(img_name))[0]

                img_plist = row_key.replace("\\", "/")

                img_path = img_path.replace("\\", "#")

                type_format = row_value[j][2]

                # 检查plist配置的图像转换是否正确
                if argv_type.lower() in ["android", "wp8"]:
                    if not os.path.exists(img_name):
                        print img_name, "not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
                    else:
                        img = Image.open(img_name)
                        if img:
                            if img.mode == "RGBA":
                                in_list = [
                                    "rgba8888",
                                    "rgba4444",
                                    "rgba5551",
                                    "pvrtc4",
                                    "dxt3",
                                    "selflow",
                                    "selfhigh",
                                    "selfmiddle",
                                ]
                            elif img.mode == "RGB":
                                in_list = ["rgb888", "rgb565", "pvrtc4_noalpha", "dxt1"]
                            else:
                                in_list = ["none"]
                            need_raise = True
                            for data in in_list:
                                if data in type_format:
                                    need_raise = False
                            if need_raise:
                                print img_name + " convert format error! need " + str(in_list)
                        else:
                            print img_name + "==open error!"
                            raise

                if need_raise:
                    raise

                if row_key.lower() != "none":
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                        img_path,
                        img_plist + ".plist",
                        1,
                        type_format,
                    )
                else:
                    type_flag = 0
                    type_img_name = os.path.splitext(img_name.replace("\\", "/"))[0]
                    type_img_ext = os.path.splitext(img_name.replace("\\", "/"))[1]
                    if type_img_ext.lower() != ".png":
                        type_img_name = img_name.replace("\\", "/")
                    else:
                        if argv_type.lower() in ["ios", "android", "wp8"]:
                            if type_format == "none":
                                type_img_name = img_name.replace("\\", "/")
                                type_flag = 0
                            else:
                                type_img_name = type_img_name + ".plist"
                                type_flag = 1
                        else:
                            raise

                    if (
                        img_name.find("\\ui\\") >= 0
                        or img_name.find("\\audio\\") >= 0
                        or img_name.find("\\json\\") >= 0
                        or img_name.find("\\skilleffect\\") >= 0
                    ):
                        if argv_type.lower() in ["ios", "android", "wp8"]:
                            row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                                os.path.splitext(img_name)[0].replace("\\", "#"),
                                type_img_name,
                                type_flag,
                                type_format,
                            )
                        else:
                            raise
                    else:
                        if argv_type.lower() in ["ios", "android", "wp8"]:
                            row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                                os.path.splitext(os.path.basename(img_name))[0],
                                type_img_name,
                                type_flag,
                                type_format,
                            )
                        else:
                            raise

    # 遍历目录
    path_dict = {}
    walkpath("res", path_dict)

    for row_key, row_value in path_dict.iteritems():
        # 处理图片
        for j in xrange(0, len(row_value)):
            # 拆分目录
            img_path = row_key
            img_name = row_value[j]
            if (
                img_name.find(".png") >= 0
                or img_name.find(".mp3") >= 0
                or img_name.find(".caf") >= 0
                or img_name.find(".m4a") >= 0
                or img_name.find(".ExportJson") >= 0
                or img_name.find(".json") >= 0
                or img_name.find(".csb") > 0
                or img_name.find(".plist") > 0
                or img_name.find(".ogg") >= 0
            ):
                pass
            else:
                continue

            img_flag = getImageFlag(img_name)

            # json文件夹只处理ExportJson文件
            if img_flag == IMAGE_FLAG_JSON:
                if img_name.find("\\equip\\") >= 0:
                    if img_name.find(".ExportJson") < 0 and img_name.find(".plist") < 0:
                        continue
                else:
                    if img_name.find(".ExportJson") < 0:
                        continue

            # map文件夹只处理json文件
            if img_flag == IMAGE_FLAG_MAP and img_name.find(".json") < 0:
                continue

            # csb文件夹只处理csb文件
            if img_flag == IMAGE_FLAG_CSB and img_name.find(".csb") < 0:
                continue

            # 查找是否已经被plist,win32不做plist
            continue_flag = getPlistedFlag(img_name, plist_dict, argv_type)

            if continue_flag:
                continue

            # 查找是否有同名plist

            if img_flag == IMAGE_FLAG_NORMAL:
                found_flag = getPlistExistedFlag(img_name, path_dict, row_key)
                if found_flag:
                    row_texts = row_texts + '\t["%s"]={"%s",%d,""},\n' % (
                        os.path.splitext(os.path.basename(img_name))[0],
                        os.path.splitext(img_name.replace("\\", "/"))[0],
                        1,
                    )
                    continue

            # 查找是否多平台文件
            continue_flag, target_name = getPublicresFlag(img_name, publicres_dict, argv_platform)

            if continue_flag:
                continue
            else:
                img_name = target_name

            # 查找是否多语言文件
            continue_flag, target_name = getLanguageresFlag(img_name, languageres_dict, argv_lang)

            if continue_flag:
                continue
            else:
                img_name = target_name

            # 产生图像格式
            type_format = getImageType(img_name, argv_type)

            type_flag = 0
            type_img_name = os.path.splitext(img_name.replace("\\", "/"))[0]
            type_img_ext = os.path.splitext(img_name.replace("\\", "/"))[1]
            if type_img_ext.lower() != ".png":
                # 音效文件特殊处理
                if img_name.find("res\\audio\\") >= 0:
                    if img_name.find("\\" + argv_type.lower() + "\\") <= 0:
                        continue
                    else:
                        img_name = img_name.replace("\\" + argv_type.lower() + "\\", "\\")

                type_img_name = img_name.replace("\\", "/")
                if img_name.find(".plist") > 0:
                    type_flag = 1
                else:
                    type_flag = 0
            else:
                if argv_type.lower() == "ios":
                    type_img_name = type_img_name + ".plist"
                    type_flag = 1
                elif argv_type.lower() == "android":
                    if type_format == "none":
                        type_img_name = img_name.replace("\\", "/")
                        type_flag = 0
                    else:
                        type_img_name = type_img_name + ".plist"
                        type_flag = 1
                elif argv_type.lower() == "wp8":
                    if type_format == "none":
                        type_img_name = img_name.replace("\\", "/")
                        type_flag = 0
                    else:
                        type_img_name = type_img_name + ".plist"
                        type_flag = 1
                else:
                    type_img_name = img_name.replace("\\", "/")
            if (
                img_name.find("\\ui\\") >= 0
                or img_name.find("\\audio\\") >= 0
                or img_name.find("\\json\\") >= 0
                or img_name.find("\\skilleffect\\") >= 0
            ):
                if argv_type.lower() in ["ios", "android", "wp8"]:
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                        os.path.splitext(img_name)[0].replace("\\", "#"),
                        type_img_name,
                        type_flag,
                        type_format,
                    )
                else:
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                        os.path.splitext(img_name)[0].replace("\\", "#"),
                        type_img_name,
                        type_flag,
                        type_format,
                    )
            else:
                if argv_type.lower() in ["ios", "android", "wp8"]:
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                        os.path.splitext(os.path.basename(img_name))[0],
                        type_img_name,
                        type_flag,
                        type_format,
                    )
                else:
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                        os.path.splitext(os.path.basename(img_name))[0],
                        type_img_name,
                        type_flag,
                        type_format,
                    )

    client_output_dict = {}
    client_output_dict["$RESPATH$"] = row_texts
    gen_file(client_template, client_output, client_output_dict, False)

    print "plist ok! start convert!"

    # 处理文件

    if argv_type == "win32":

        safeRmTree("..\\..\\client\\res")

        import time

        time.sleep(2)

        while os.path.exists("..\\..\\client\\res"):
            pass

        shutil.copytree("res", "..\\..\\client\\res", False, ignoreFile)
        if os.path.exists("..\\..\\client\\res\\audio"):
            shutil.rmtree("..\\..\\client\\res\\audio", True)
            os.makedirs("..\\..\\client\\res\\audio")
        # win32音效特殊处理
        for file_name in os.listdir("res\\audio\\win32\\"):
            sub_path = os.path.join("res\\audio\\win32\\", file_name)
            if os.path.isdir(sub_path):
                continue
            else:
                safeCopy(sub_path, "..\\..\\client\\res\\audio")

        # 公共资源改名覆盖
        for publicres_key in publicres_dict.iterkeys():
            print "win32 copy %s to %s" % (
                "..\\..\\client\\" + publicres_key + "_" + argv_platform + ".png",
                "..\\..\\client\\" + publicres_key + ".png",
            )
            shutil.copy(
                "..\\..\\client\\" + publicres_key + "_" + argv_platform + ".png",
                "..\\..\\client\\" + publicres_key + ".png",
            )

        # 多语言资源改名覆盖
        if argv_lang != "gbk" and argv_lang != "multi":
            for languageres_key in languageres_dict.iterkeys():
                print "win32 copy %s to %s" % (
                    "..\\..\\client\\" + languageres_key + "_" + argv_lang + ".png",
                    "..\\..\\client\\" + languageres_key + ".png",
                )
                shutil.copy(
                    "..\\..\\client\\" + languageres_key + "_" + argv_lang + ".png",
                    "..\\..\\client\\" + languageres_key + ".png",
                )

        return

    # 处理配置的plist
    safeRmTree("temp\\")

    convert_flag = False

    for row_key, row_value in plist_dict.iteritems():
        # 处理图片

        convert_flag = False

        for j in xrange(0, len(row_value)):
            # 拆分目录
            img_flag = row_value[j][0]
            img_name = row_value[j][1]
            img_format = row_value[j][2]

            img_path = os.path.dirname(img_name) + "\\"

            if img_flag == 4:
                img_path = ""

            img_flag = getImageFlag(img_name)
            copy_flag = 1
            if img_flag == IMAGE_FLAG_JSON or img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_CSB:
                copy_flag = 0

            if row_key.lower() == "none":
                if (
                    img_name.find("\\ui\\") >= 0
                    or img_name.find("\\audio\\") >= 0
                    or img_name.find("\\json\\") >= 0
                    or img_name.find("\\skilleffect\\") >= 0
                ):
                    pass
                else:
                    img_path = ""

            if not os.path.exists("temp\\" + img_path):
                os.makedirs("temp\\" + img_path)

            # 查找是否多平台文件
            continue_flag, target_name = getPublicresFlag(img_name, publicres_dict, argv_platform)

            if continue_flag:
                continue
            else:
                img_publicres_name = target_name

            # 查找是否多语言文件
            continue_flag, target_name = getLanguageresFlag(img_name, languageres_dict, argv_lang)

            if continue_flag:
                continue
            else:
                img_publicres_name = target_name

            if not os.path.exists(img_name):
                print img_name, "not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
            else:
                safeCopy(img_name, "temp\\" + img_path + os.path.basename(img_publicres_name))

            if img_name.replace("\\", "/") in diff_list:
                convert_flag = True

            if row_key.lower() == "none":
                if (diff_flag and convert_flag) or not diff_flag:
                    cmd_text = "res\\xcopy.bat %s temp %s 0 %d %s" % (
                        "..\\..\\outputClient\\" + argv_type + "\\" + os.path.splitext(img_publicres_name)[0],
                        getFormatFlag(argv_type, img_format),
                        copy_flag,
                        img_path,
                    )
                    os.system(cmd_text)
                    safeRmTree("temp\\")
                    convert_flag = False
                else:
                    safeRmTree("temp\\")
                    convert_flag = False

        if row_key.lower() != "none":
            if (diff_flag and convert_flag) or not diff_flag:
                cmd_text = "res\\xcopy.bat %s temp %s 1 %d" % (
                    "..\\..\\outputClient\\" + argv_type + "\\" + row_key,
                    getFormatFlag(argv_type, img_format),
                    copy_flag,
                )
                os.system(cmd_text)
                # 如果目标图没有生成,那么抛异常
                if (
                    (not os.path.exists("..\\..\\outputClient\\" + argv_type + "\\" + row_key + ".png"))
                    and (not os.path.exists("..\\..\\outputClient\\" + argv_type + "\\" + row_key + ".pvr.ccz"))
                    and (not os.path.exists("..\\..\\outputClient\\" + argv_type + "\\" + row_key + ".dds"))
                ):
                    raise

                safeRmTree("temp\\")
            else:
                safeRmTree("temp\\")

    # 遍历处理其他文件
    for row_key, row_value in path_dict.iteritems():
        # 处理图片
        for j in xrange(0, len(row_value)):
            # 拆分目录
            img_path = row_key
            img_name = row_value[j]

            img_format = "none"

            img_path = os.path.dirname(img_name) + "\\"

            if (
                img_name.find(".png") >= 0
                or img_name.find(".mp3") >= 0
                or img_name.find(".caf") >= 0
                or img_name.find(".m4a") >= 0
                or img_name.find(".ExportJson") >= 0
                or img_name.find(".json") >= 0
                or img_name.find(".tmx") >= 0
                or img_name.find(".plist") >= 0
                or img_name.find(".ogg") >= 0
            ):
                pass
            else:
                continue

            img_flag = getImageFlag(img_name)
            copy_flag = 1
            if img_flag == IMAGE_FLAG_JSON or img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_CSB:
                copy_flag = 0

            # 查找是否已经被plist,win32不做plist
            continue_flag = getPlistedFlag(img_name, plist_dict, argv_type)

            if continue_flag:
                continue

            # 查找是否有同名plist
            if img_flag == IMAGE_FLAG_NORMAL:
                found_flag = getPlistExistedFlag(img_name, path_dict, row_key)

                if found_flag:
                    # 复制过去
                    safeCopy(img_name, "..\\..\\outputClient\\" + argv_type + "\\" + img_path)
                    img_plist = os.path.splitext(img_name)[0] + ".plist"
                    safeCopy(img_plist, "..\\..\\outputClient\\" + argv_type + "\\" + img_path)
                    continue

            # 查找是否多平台文件
            continue_flag, target_name = getPublicresFlag(img_name, publicres_dict, argv_platform)

            if continue_flag:
                continue
            else:
                img_publicres_name = target_name

            # 查找是否多语言文件
            continue_flag, target_name = getLanguageresFlag(img_name, languageres_dict, argv_lang)

            if continue_flag:
                continue
            else:
                img_publicres_name = target_name

            convert_flag = False
            if img_name.replace("\\", "/") in diff_list:
                convert_flag = True

            if (diff_flag and convert_flag) or not diff_flag:
                pass
            else:
                continue

            # 产生图像格式
            img_format = getImageType(img_name, argv_type)

            img_ext = os.path.splitext(img_name.replace("\\", "/"))[1]
            if img_ext.lower() != ".png":

                if img_flag == IMAGE_FLAG_NORMAL:

                    # 音效文件特殊处理
                    if img_path.find("res\\audio\\") >= 0:
                        if img_path.find("\\" + argv_type.lower() + "\\") <= 0:
                            continue
                        else:
                            img_path = img_path.replace("\\" + argv_type.lower() + "\\", "\\")

                    safeCopy(img_name, "..\\..\\outputClient\\" + argv_type + "\\" + img_path)

                elif img_flag == IMAGE_FLAG_MAP:
                    if img_name.find(".tmx") >= 0 or img_name.find(".json") >= 0:

                        with open(img_name, "r") as fr:
                            content = fr.read()

                        content = content.replace(".png", ".pvr.ccz")

                        safeWrite(
                            "..\\..\\outputClient\\" + argv_type + "\\" + img_path + os.path.basename(img_name), content
                        )

                    else:
                        safeCopy(img_name, "..\\..\\outputClient\\" + argv_type + "\\" + img_path)

                elif img_flag == IMAGE_FLAG_JSON:
                    safeCopy(img_name, "..\\..\\outputClient\\" + argv_type + "\\" + img_path)

                print "copy " + img_name
            else:
                if (
                    img_name.find("\\ui\\") >= 0
                    or img_name.find("\\audio\\") >= 0
                    or img_name.find("\\json\\") >= 0
                    or img_name.find("\\skilleffect\\") >= 0
                ):
                    pass
                else:
                    img_path = ""

                if not os.path.exists(img_name):
                    print img_name, "not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
                else:
                    safeCopy(img_name, "temp\\" + img_path + os.path.basename(img_publicres_name))

                cmd_text = "res\\xcopy.bat %s temp %s 0 %d %s" % (
                    "..\\..\\outputClient\\" + argv_type + "\\" + os.path.splitext(img_publicres_name)[0],
                    getFormatFlag(argv_type, img_format),
                    copy_flag,
                    img_path,
                )
                os.system(cmd_text)
                safeRmTree("temp\\")
Exemplo n.º 4
0
def converter_plist(excel_file, sheet_name, argv_type, argv_lang):
    book = xlrd.open_workbook(excel_file)
    sheet = book.sheet_by_name(sheet_name)
    print sheet.name

    rows_dict = {}

    for i in xrange(1, sheet.nrows):
        # 循环sheet中的行
        if argv_type.lower() == "ios" and argv_lang.lower() != "multi":
            row_key = _utf8(sheet.cell_value(i, 0))
        elif argv_type.lower() == "android" and argv_lang.lower() != "multi":
            row_key = _utf8(sheet.cell_value(i, 1))
        elif argv_type.lower() == "wp8" and argv_lang.lower() != "multi":
            row_key = _utf8(sheet.cell_value(i, 2))
        elif argv_type.lower() == "ios" and argv_lang.lower() == "multi":
            row_key = _utf8(sheet.cell_value(i, 3))
        elif argv_type.lower() == "android" and argv_lang.lower() == "multi":
            row_key = _utf8(sheet.cell_value(i, 4))
        elif argv_type.lower() == "wp8" and argv_lang.lower() == "multi":
            row_key = _utf8(sheet.cell_value(i, 5))
        else:
            row_key = _utf8(sheet.cell_value(i, 0))

        row_flag = _int(sheet.cell_value(i, 6))
        row_value = _utf8(sheet.cell_value(i, 7))

        if argv_type.lower() == "ios":
            row_format = _utf8(sheet.cell_value(i, 8))
        elif argv_type.lower() == "android":
            row_format = _utf8(sheet.cell_value(i, 9))
        elif argv_type.lower() == "wp8":
            row_format = _utf8(sheet.cell_value(i, 10))
        else:
            row_format = _utf8(sheet.cell_value(i, 8))

        # 文件
        if row_flag == 1:
            if row_value.find(".png") >= 0:
                if rows_dict.has_key(row_key):
                    rows_dict[row_key].append([row_flag, row_value, row_format])
                else:
                    rows_dict[row_key] = [[row_flag, row_value, row_format]]
        # 目录
        elif row_flag == 2 or row_flag == 4:
            for file_name in os.listdir(row_value):
                if os.path.isdir(row_value + os.path.sep + file_name):
                    continue

                if file_name.find(".png") >= 0:
                    if rows_dict.has_key(row_key):
                        rows_dict[row_key].append([row_flag, row_value + os.path.sep + file_name, row_format])
                    else:
                        rows_dict[row_key] = [[row_flag, row_value + os.path.sep + file_name, row_format]]
        # 忽略
        elif row_flag == 3:
            if rows_dict.has_key(row_key):
                delete_index = -1
                for i in xrange(0, len(rows_dict[row_key])):
                    if rows_dict[row_key][i][1] == row_value:
                        delete_index = i
                        break
                if delete_index != -1:
                    del rows_dict[row_key][delete_index]
        else:
            pass

    return rows_dict
Exemplo n.º 5
0
def convertImg(argv_type,argv_line,argv_platform,argv_lang,argv_start,argv_end):
    """
    """

    diff_flag = False
    if argv_start != -1 and argv_end != -1:
        diff_flag = True

    diff_list = list()
    if diff_flag:
        diff_list = getDiffList(argv_start,argv_end,argv_line)

    print diff_list
    
    excel_file = 'plist.xls'  # excel配置文件,xls格式
    client_template = 'resDB.lua'  # 后端配置文件模版
    client_output = 'resDB.lua'  #  后端配置输出文件
    plist_dict = converter_plist(excel_file,"plist",argv_type,argv_lang)

    #公共资源列表
    book = xlrd.open_workbook('plist.xls')
    sheet = book.sheet_by_name('platform')
    print sheet.name
    publicres_dict = {}
    for i in xrange(1, sheet.nrows):
        # 循环sheet中的行
        row_key = _utf8(sheet.cell_value(i, 0))
        publicres_dict[row_key] = ""
    
    #多语言资源列表
    book = xlrd.open_workbook('plist.xls')
    sheet = book.sheet_by_name('language')
    print sheet.name
    languageres_dict = {}
    for i in xrange(1, sheet.nrows):
        # 循环sheet中的行
        row_key = _utf8(sheet.cell_value(i, 0))
        languageres_dict[row_key] = ""


    #生成resDB
    row_texts = ""
    
    #win32不做plist
    need_raise = False
    if argv_type != 'win32':#判断平台不是为win32
        for row_key,row_value in plist_dict.iteritems():
            #处理图片
            for j in xrange(0,len(row_value)):
                #拆分目录
                img_flag = row_value[j][0]
                img_name = row_value[j][1]

                img_flag = getImageFlag(img_name)

                if img_flag == IMAGE_FLAG_JSON:
                    continue

                #查找是否多平台文件
                continue_flag,target_name = getPublicresFlag(img_name,publicres_dict,argv_platform)

                if continue_flag:
                    continue
                else:
                    img_name = target_name

                #查找是否多语言文件
                continue_flag,target_name = getLanguageresFlag(img_name,languageres_dict,argv_lang)

                if continue_flag:
                    continue
                else:
                    img_name = target_name


                img_path = os.path.splitext(img_name)[0]     #获得图片路径       
                
                if img_flag == 4:
                    img_path = os.path.splitext(os.path.basename(img_name))[0]
                    
                img_plist = row_key.replace('\\','/')#选择代替的标识符
     
                img_path = img_path.replace('\\','#')#继续替换

                type_format = row_value[j][2]#图片格式

                #检查plist配置的图像转换是否正确
                if argv_type.lower() in ['android','wp8']:
                    if not os.path.exists(img_name):
                        print img_name,"not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
                    else:
                        img = Image.open(img_name)
                        if img:
                            if img.mode == 'RGBA':
                                in_list = ['rgba8888','rgba4444','rgba5551','pvrtc4','dxt3','selflow','selfhigh','selfmiddle','none']
                            elif img.mode == 'RGB':
                                in_list = ['rgb888','rgb565','pvrtc4_noalpha','dxt1','none']
                            else:
                                in_list = ['none']
                            need_raise = True
                            for data in in_list:
                                if data in type_format:
                                    need_raise = False
                            if need_raise:
                                    print img_name+" convert format error! need "+str(in_list)
                        else:
                            print img_name+'==open error!'
                            raise
                
                if need_raise:
                    raise

                if row_key.lower() != 'none':                
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(img_path,img_plist+'.plist',1,type_format)
                else:
                    type_flag = 0
                    type_img_name = os.path.splitext(img_name.replace('\\','/'))[0]
                    type_img_ext = os.path.splitext(img_name.replace('\\','/'))[1]
                    if type_img_ext.lower() != '.png':
                        type_img_name = img_name.replace('\\','/')
                    else:
                        if argv_type.lower() in ['ios','android','wp8']:
                            if type_format == 'none':
                                type_img_name = img_name.replace('\\','/')
                                type_flag = 0
                            else:
                                type_img_name = type_img_name + '.plist'
                                type_flag = 1
                        else:
                            raise
             
                    if img_name.find('\\ui\\') >= 0 or img_name.find('\\audio\\') >= 0 or img_name.find('\\json\\') >= 0 or img_name.find('\\skilleffect\\') >= 0:
                        if argv_type.lower() in ['ios','android','wp8']:
                            row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(os.path.splitext(img_name)[0].replace('\\','#'),type_img_name,type_flag,type_format)
                        else:
                            raise
                    else:
                        if argv_type.lower() in ['ios','android','wp8']:
                            row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(os.path.splitext(os.path.basename(img_name))[0],type_img_name,type_flag,type_format)
                        else:
                            raise
    
    #遍历目录
    path_dict = {}
    walkpath("res",path_dict)
    
    for row_key,row_value in path_dict.iteritems():
        #处理图片
        for j in xrange(0,len(row_value)):
            #拆分目录
            img_path = row_key
            img_name = row_value[j]

            if img_name.find('.png') >= 0 or \
            img_name.find('.mp3') >= 0 or \
            img_name.find('.caf') >= 0 or \
            img_name.find('.m4a') >= 0 or \
            img_name.find('.ExportJson') >= 0 or \
            img_name.find('.json') >= 0 or \
            img_name.find('.csb') > 0 or \
            img_name.find('.plist') > 0 or \
            img_name.find('.fnt') > 0 or \
            img_name.find('.ttf') > 0 or \
            img_name.find('.ogg') >= 0 :
                pass
            else:
                continue
            
            img_flag = getImageFlag(img_name)

            #json文件夹只处理ExportJson文件
            if img_flag == IMAGE_FLAG_JSON: 
                if img_name.find('\\equip\\') >= 0:
                    if img_name.find('.ExportJson') < 0 and img_name.find('.plist') < 0:
                        continue
                else:
                    if img_name.find('.ExportJson') < 0:
                        continue

            
            #查找是否已经被plist,win32不做plist
            continue_flag = getPlistedFlag(img_name,plist_dict,argv_type)

            if continue_flag:
                continue

            
            #查找是否有同名plist

            if img_flag == IMAGE_FLAG_NORMAL:
                found_flag = getPlistExistedFlag(img_name,path_dict,row_key)
                if found_flag:
                    #row_texts = row_texts + '\t["%s"]={"%s",%d,""},\n'%(os.path.splitext(os.path.basename(img_name))[0],os.path.splitext(img_name.replace('\\','/'))[0],1)
                    continue

            #查找是否多平台文件
            continue_flag,target_name = getPublicresFlag(img_name,publicres_dict,argv_platform)

            if continue_flag:
                continue
            else:
                img_name = target_name

            #查找是否多语言文件
            continue_flag,target_name = getLanguageresFlag(img_name,languageres_dict,argv_lang)

            if continue_flag:
                continue
            else:
                img_name = target_name


            #产生图像格式
            type_format = getImageType(img_name,argv_type)

            type_flag = 0
            type_img_name = os.path.splitext(img_name.replace('\\','/'))[0]
            type_img_ext = os.path.splitext(img_name.replace('\\','/'))[1]
            if type_img_ext.lower() != '.png':
                #音效文件特殊处理
                if img_name.find('res\\audio\\') >= 0:
                    if img_name.find('\\'+'win32'+'\\') <= 0:
                        continue
                    else:
                        img_name = img_name.replace('\\'+'win32'+'\\','\\')

                type_img_name = img_name.replace('\\','/')
                if img_name.find('.plist') > 0:
                    type_flag = 1
                else:
                    type_flag = 0
            else:
                if argv_type.lower() == 'ios':
                    type_img_name = type_img_name + '.plist'
                    type_flag = 1
                elif argv_type.lower() == 'android':
                    if type_format == 'none':
                        type_img_name = img_name.replace('\\','/')
                        type_flag = 0
                    else:
                        type_img_name = type_img_name + '.plist'
                        type_flag = 1
                elif argv_type.lower() == 'wp8':
                    if type_format == 'none':
                        type_img_name = img_name.replace('\\','/')
                        type_flag = 0
                    else:
                        type_img_name = type_img_name + '.plist'
                        type_flag = 1
                else:
                    type_img_name = img_name.replace('\\','/')
            if img_name.find('\\ui\\') >= 0 or img_name.find('\\audio\\') >= 0 or img_name.find('\\json\\') >= 0 or img_name.find('\\skilleffect\\') >= 0:
                if argv_type.lower() in ['ios','android','wp8']:
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(os.path.splitext(img_name)[0].replace('\\','#'),type_img_name,type_flag,type_format)
                else:
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(os.path.splitext(img_name)[0].replace('\\','#'),type_img_name,type_flag,type_format)
            else:
                if argv_type.lower() in ['ios','android','wp8']:
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(os.path.splitext(os.path.basename(img_name))[0],type_img_name,type_flag,type_format)
                else:
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(os.path.splitext(os.path.basename(img_name))[0],type_img_name,type_flag,type_format)


    client_output_dict = {}
    client_output_dict["$RESPATH$"] = row_texts

    gen_file(client_template, client_output, client_output_dict, False)
    
    print 'plist ok! start convert!'
    
    #处理文件
    
    if argv_type == 'win32':

        safeRmTree("..\\..\\client\\res")

        import time
        time.sleep(2)
         
        while os.path.exists("..\\..\\client\\res"):
            pass

        shutil.copytree('res', "..\\..\\client\\res",False,ignoreFile)
        if os.path.exists("..\\..\\client\\res\\audio"):
            shutil.rmtree("..\\..\\client\\res\\audio", True)
            os.makedirs("..\\..\\client\\res\\audio")
        #win32音效特殊处理
        #for file_name in os.listdir("res\\audio\\win32\\"):        
        #    sub_path = os.path.join("res\\audio\\win32\\", file_name)
        #    if os.path.isdir(sub_path):
        #        continue
        #    else:
        #        safeCopy(sub_path,"..\\..\\client\\res\\audio")
        #        
        copyFiles("res\\audio\\win32\\", "..\\..\\client\\res\\audio");
        #公共资源改名覆盖
        for publicres_key in publicres_dict.iterkeys():
            print 'win32 copy %s to %s'%("..\\..\\client\\"+publicres_key+"_"+argv_platform+".png","..\\..\\client\\"+publicres_key+".png")
            shutil.copy("..\\..\\client\\"+publicres_key+"_"+argv_platform+".png","..\\..\\client\\"+publicres_key+".png")
        
        #多语言资源改名覆盖
        if argv_lang != 'gbk' and argv_lang != 'multi':
            for languageres_key in languageres_dict.iterkeys():
                print 'win32 copy %s to %s'%("..\\..\\client\\"+languageres_key+"_"+argv_lang+".png","..\\..\\client\\"+languageres_key+".png")
                shutil.copy("..\\..\\client\\"+languageres_key+"_"+argv_lang+".png","..\\..\\client\\"+languageres_key+".png")

        return
    
    #处理配置的plist
    safeRmTree("temp\\")

    convert_flag = False
    
    for row_key,row_value in plist_dict.iteritems():
        #处理图片
        
        convert_flag = False
        
        for j in xrange(0,len(row_value)):
            #拆分目录
            img_flag = row_value[j][0]
            img_name = row_value[j][1]
            img_format = row_value[j][2]
            
            img_path = os.path.dirname(img_name) + '\\'
            
            if img_flag == 4:
                img_path = ""
            
            img_flag = getImageFlag(img_name)
            copy_flag = 1
            if img_flag == IMAGE_FLAG_JSON or img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_FONT:
                copy_flag = 0


            if row_key.lower() == 'none':
                if img_name.find('\\ui\\') >= 0 or img_name.find('\\audio\\') >= 0 or img_name.find('\\json\\') >= 0 or img_name.find('\\skilleffect\\') >= 0:
                    pass
                else:
                    img_path = ''

            if not os.path.exists("temp\\"+img_path):
                os.makedirs("temp\\"+img_path)
            

            #查找是否多平台文件
            continue_flag,target_name = getPublicresFlag(img_name,publicres_dict,argv_platform)

            if continue_flag:
                continue
            else:
                img_publicres_name = target_name

            #查找是否多语言文件
            continue_flag,target_name = getLanguageresFlag(img_name,languageres_dict,argv_lang)

            if continue_flag:
                continue
            else:
                img_publicres_name = target_name


            if not os.path.exists(img_name):
                print img_name,"not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
            else:
                safeCopy(img_name,"temp\\"+img_path+os.path.basename(img_publicres_name))                    
               
            if img_name.replace('\\','/') in diff_list :                
                convert_flag = True
                
            if row_key.lower() == 'none':
                if (diff_flag and convert_flag) or not diff_flag:
                    cmd_text = "res\\xcopy.bat %s temp %s 0 %d %s"%('..\\..\\outputClient\\'+argv_type+'\\'+os.path.splitext(img_publicres_name)[0],getFormatFlag(argv_type,img_format),copy_flag,img_path)
                    os.system(cmd_text)
                    safeRmTree("temp\\")
                    convert_flag = False
                else:
                    safeRmTree("temp\\")
                    convert_flag = False


         
        if row_key.lower() != 'none':            
            if (diff_flag and convert_flag) or not diff_flag:
                cmd_text = "res\\xcopy.bat %s temp %s 1 %d"%('..\\..\\outputClient\\'+argv_type+'\\'+row_key,getFormatFlag(argv_type,img_format),copy_flag)
                os.system(cmd_text)
                #如果目标图没有生成,那么抛异常
                if (not os.path.exists('..\\..\\outputClient\\'+argv_type+'\\'+row_key+'.png')) and (not os.path.exists('..\\..\\outputClient\\'+argv_type+'\\'+row_key+'.pvr.ccz')) and (not os.path.exists('..\\..\\outputClient\\'+argv_type+'\\'+row_key+'.dds')):
                    raise

                safeRmTree("temp\\")
            else:
                safeRmTree("temp\\")



    #遍历处理其他文件
    for row_key,row_value in path_dict.iteritems():
        #处理图片
        for j in xrange(0,len(row_value)):
            #拆分目录
            img_path = row_key
            img_name = row_value[j]

            img_format = 'none'

            img_path = os.path.dirname(img_name) + '\\'
            
            if img_name.find('.png') >= 0 or \
            img_name.find('.mp3') >= 0 or \
            img_name.find('.caf') >= 0 or \
            img_name.find('.m4a') >= 0 or \
            img_name.find('.ExportJson') >= 0 or \
            img_name.find('.csb') >= 0 or \
            img_name.find('.json') >= 0 or \
            img_name.find('.tmx') >= 0 or \
            img_name.find('.plist') >= 0 or \
            img_name.find('.fnt') >= 0 or \
            img_name.find('.ttf') >= 0 or \
            img_name.find('.ogg') >= 0 :
                pass
            else:
                continue

            img_flag = getImageFlag(img_name)
            copy_flag = 1
            if img_flag == IMAGE_FLAG_JSON or img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_FONT:
                copy_flag = 0


            #查找是否已经被plist,win32不做plist
            continue_flag = getPlistedFlag(img_name,plist_dict,argv_type)

            if continue_flag:
                continue

            #查找是否有同名plist
            if img_flag == IMAGE_FLAG_NORMAL:
                found_flag = getPlistExistedFlag(img_name,path_dict,row_key)

                if found_flag:
                    #复制过去
                    safeCopy(img_name,"..\\..\\outputClient\\"+argv_type+'\\'+img_path)
                    img_plist = os.path.splitext(img_name)[0]+'.plist'
                    safeCopy(img_plist,"..\\..\\outputClient\\"+argv_type+'\\'+img_path)            
                    continue

            #查找是否多平台文件
            continue_flag,target_name = getPublicresFlag(img_name,publicres_dict,argv_platform)

            if continue_flag:
                continue
            else:
                img_publicres_name = target_name

            #查找是否多语言文件
            continue_flag,target_name = getLanguageresFlag(img_name,languageres_dict,argv_lang)

            if continue_flag:
                continue
            else:
                img_publicres_name = target_name


            convert_flag = False
            if img_name.replace('\\','/') in diff_list :
                convert_flag = True
            
            if (diff_flag and convert_flag) or not diff_flag:
                pass
            else:
                continue
            

            #产生图像格式
            img_format = getImageType(img_name,argv_type)

            img_ext = os.path.splitext(img_name.replace('\\','/'))[1]
            if img_ext.lower() != '.png':
                if img_flag == IMAGE_FLAG_NORMAL or img_flag == IMAGE_FLAG_FONT:

                    #音效文件特殊处理
                    if img_path.find('res\\audio\\') >= 0:
                        if img_path.find('\\'+'win32'+'\\') <= 0:
                            continue
                        else:
                            img_path = img_path.replace('\\'+'win32'+'\\','\\')

                    safeCopy(img_name,"..\\..\\outputClient\\"+argv_type+'\\'+img_path)

                elif img_flag == IMAGE_FLAG_JSON:
                    safeCopy(img_name,"..\\..\\outputClient\\"+argv_type+'\\'+img_path)
                elif img_flag == IMAGE_FLAG_MAP:
                    safeCopy(img_name,"..\\..\\outputClient\\"+argv_type+'\\'+img_path)
                elif img_flag == IMAGE_FLAG_CSB:
                    safeCopy(img_name,"..\\..\\outputClient\\"+argv_type+'\\'+img_path)
                print 'copy '+img_name
            else:
                if img_name.find('\\ui\\') >= 0 or img_name.find('\\audio\\') >= 0 or img_name.find('\\json\\') >= 0 or img_name.find('\\skilleffect\\') >= 0:
                    pass
                else:
                    img_path = ''
            

                if not os.path.exists(img_name):
                    print img_name,"not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
                else:
                    safeCopy(img_name,"temp\\"+img_path+os.path.basename(img_publicres_name))                    
                               
                cmd_text = "res\\xcopy.bat %s temp %s 0 %d %s"%("..\\..\\outputClient\\"+argv_type+'\\'+os.path.splitext(img_publicres_name)[0],getFormatFlag(argv_type,img_format),copy_flag,img_path)
                os.system(cmd_text)
                safeRmTree("temp\\")
Exemplo n.º 6
0
def convertImg(argv_type, argv_line, argv_platform, argv_lang, argv_start,
               argv_end):
    """
    """

    diff_flag = False
    if argv_start != -1 and argv_end != -1:
        diff_flag = True

    diff_list = list()
    if diff_flag:
        diff_list = getDiffList(argv_start, argv_end, argv_line)

    print diff_list

    excel_file = 'plist.xls'  # excel配置文件,xls格式
    client_template = 'resDB.lua'  # 后端配置文件模版
    client_output = 'resDB.lua'  #  后端配置输出文件
    plist_dict = converter_plist(excel_file, "plist", argv_type, argv_lang)

    #公共资源列表
    book = xlrd.open_workbook('plist.xls')
    sheet = book.sheet_by_name('platform')
    print sheet.name
    publicres_dict = {}
    for i in xrange(1, sheet.nrows):
        # 循环sheet中的行
        row_key = _utf8(sheet.cell_value(i, 0))
        publicres_dict[row_key] = ""

    #多语言资源列表
    book = xlrd.open_workbook('plist.xls')
    sheet = book.sheet_by_name('language')
    print sheet.name
    languageres_dict = {}
    for i in xrange(1, sheet.nrows):
        # 循环sheet中的行
        row_key = _utf8(sheet.cell_value(i, 0))
        languageres_dict[row_key] = ""

    #生成resDB
    row_texts = ""

    #win32不做plist
    need_raise = False
    if argv_type != 'win32':  #判断平台不是为win32
        for row_key, row_value in plist_dict.iteritems():
            #处理图片
            for j in xrange(0, len(row_value)):
                #拆分目录
                img_flag = row_value[j][0]
                img_name = row_value[j][1]

                img_flag = getImageFlag(img_name)

                if img_flag == IMAGE_FLAG_JSON:
                    continue

                #查找是否多平台文件
                continue_flag, target_name = getPublicresFlag(
                    img_name, publicres_dict, argv_platform)

                if continue_flag:
                    continue
                else:
                    img_name = target_name

                #查找是否多语言文件
                continue_flag, target_name = getLanguageresFlag(
                    img_name, languageres_dict, argv_lang)

                if continue_flag:
                    continue
                else:
                    img_name = target_name

                img_path = os.path.splitext(img_name)[0]  #获得图片路径

                if img_flag == 4:
                    img_path = os.path.splitext(os.path.basename(img_name))[0]

                img_plist = row_key.replace('\\', '/')  #选择代替的标识符

                img_path = img_path.replace('\\', '#')  #继续替换

                type_format = row_value[j][2]  #图片格式

                #检查plist配置的图像转换是否正确
                if argv_type.lower() in ['android', 'wp8']:
                    if not os.path.exists(img_name):
                        print img_name, "not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
                    else:
                        img = Image.open(img_name)
                        if img:
                            if img.mode == 'RGBA':
                                in_list = [
                                    'rgba8888', 'rgba4444', 'rgba5551',
                                    'pvrtc4', 'dxt3', 'selflow', 'selfhigh',
                                    'selfmiddle', 'none'
                                ]
                            elif img.mode == 'RGB':
                                in_list = [
                                    'rgb888', 'rgb565', 'pvrtc4_noalpha',
                                    'dxt1', 'none'
                                ]
                            else:
                                in_list = ['none']
                            need_raise = True
                            for data in in_list:
                                if data in type_format:
                                    need_raise = False
                            if need_raise:
                                print img_name + " convert format error! need " + str(
                                    in_list)
                        else:
                            print img_name + '==open error!'
                            raise

                if need_raise:
                    raise

                if row_key.lower() != 'none':
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                        img_path, img_plist + '.plist', 1, type_format)
                else:
                    type_flag = 0
                    type_img_name = os.path.splitext(
                        img_name.replace('\\', '/'))[0]
                    type_img_ext = os.path.splitext(img_name.replace(
                        '\\', '/'))[1]
                    if type_img_ext.lower() != '.png':
                        type_img_name = img_name.replace('\\', '/')
                    else:
                        if argv_type.lower() in ['ios', 'android', 'wp8']:
                            if type_format == 'none':
                                type_img_name = img_name.replace('\\', '/')
                                type_flag = 0
                            else:
                                type_img_name = type_img_name + '.plist'
                                type_flag = 1
                        else:
                            raise

                    if img_name.find('\\ui\\') >= 0 or img_name.find(
                            '\\audio\\') >= 0 or img_name.find(
                                '\\json\\') >= 0 or img_name.find(
                                    '\\skilleffect\\') >= 0:
                        if argv_type.lower() in ['ios', 'android', 'wp8']:
                            row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                                os.path.splitext(img_name)[0].replace(
                                    '\\', '#'), type_img_name, type_flag,
                                type_format)
                        else:
                            raise
                    else:
                        if argv_type.lower() in ['ios', 'android', 'wp8']:
                            row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                                os.path.splitext(os.path.basename(img_name))
                                [0], type_img_name, type_flag, type_format)
                        else:
                            raise

    #遍历目录
    path_dict = {}
    walkpath("res", path_dict)

    for row_key, row_value in path_dict.iteritems():
        #处理图片
        for j in xrange(0, len(row_value)):
            #拆分目录
            img_path = row_key
            img_name = row_value[j]

            if img_name.find('.png') >= 0 or \
            img_name.find('.mp3') >= 0 or \
            img_name.find('.caf') >= 0 or \
            img_name.find('.m4a') >= 0 or \
            img_name.find('.ExportJson') >= 0 or \
            img_name.find('.json') >= 0 or \
            img_name.find('.csb') > 0 or \
            img_name.find('.plist') > 0 or \
            img_name.find('.fnt') > 0 or \
            img_name.find('.ttf') > 0 or \
            img_name.find('.ogg') >= 0 :
                pass
            else:
                continue

            img_flag = getImageFlag(img_name)

            #json文件夹只处理ExportJson文件
            if img_flag == IMAGE_FLAG_JSON:
                if img_name.find('\\equip\\') >= 0:
                    if img_name.find('.ExportJson') < 0 and img_name.find(
                            '.plist') < 0:
                        continue
                else:
                    if img_name.find('.ExportJson') < 0:
                        continue

            #查找是否已经被plist,win32不做plist
            continue_flag = getPlistedFlag(img_name, plist_dict, argv_type)

            if continue_flag:
                continue

            #查找是否有同名plist

            if img_flag == IMAGE_FLAG_NORMAL:
                found_flag = getPlistExistedFlag(img_name, path_dict, row_key)
                if found_flag:
                    #row_texts = row_texts + '\t["%s"]={"%s",%d,""},\n'%(os.path.splitext(os.path.basename(img_name))[0],os.path.splitext(img_name.replace('\\','/'))[0],1)
                    continue

            #查找是否多平台文件
            continue_flag, target_name = getPublicresFlag(
                img_name, publicres_dict, argv_platform)

            if continue_flag:
                continue
            else:
                img_name = target_name

            #查找是否多语言文件
            continue_flag, target_name = getLanguageresFlag(
                img_name, languageres_dict, argv_lang)

            if continue_flag:
                continue
            else:
                img_name = target_name

            #产生图像格式
            type_format = getImageType(img_name, argv_type)

            type_flag = 0
            type_img_name = os.path.splitext(img_name.replace('\\', '/'))[0]
            type_img_ext = os.path.splitext(img_name.replace('\\', '/'))[1]
            if type_img_ext.lower() != '.png':
                #音效文件特殊处理
                if img_name.find('res\\audio\\') >= 0:
                    if img_name.find('\\' + 'win32' + '\\') <= 0:
                        continue
                    else:
                        img_name = img_name.replace('\\' + 'win32' + '\\',
                                                    '\\')

                type_img_name = img_name.replace('\\', '/')
                if img_name.find('.plist') > 0:
                    type_flag = 1
                else:
                    type_flag = 0
            else:
                if argv_type.lower() == 'ios':
                    type_img_name = type_img_name + '.plist'
                    type_flag = 1
                elif argv_type.lower() == 'android':
                    if type_format == 'none':
                        type_img_name = img_name.replace('\\', '/')
                        type_flag = 0
                    else:
                        type_img_name = type_img_name + '.plist'
                        type_flag = 1
                elif argv_type.lower() == 'wp8':
                    if type_format == 'none':
                        type_img_name = img_name.replace('\\', '/')
                        type_flag = 0
                    else:
                        type_img_name = type_img_name + '.plist'
                        type_flag = 1
                else:
                    type_img_name = img_name.replace('\\', '/')
            if img_name.find('\\ui\\') >= 0 or img_name.find(
                    '\\audio\\') >= 0 or img_name.find(
                        '\\json\\') >= 0 or img_name.find(
                            '\\skilleffect\\') >= 0:
                if argv_type.lower() in ['ios', 'android', 'wp8']:
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                        os.path.splitext(img_name)[0].replace(
                            '\\', '#'), type_img_name, type_flag, type_format)
                else:
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                        os.path.splitext(img_name)[0].replace(
                            '\\', '#'), type_img_name, type_flag, type_format)
            else:
                if argv_type.lower() in ['ios', 'android', 'wp8']:
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                        os.path.splitext(os.path.basename(img_name))[0],
                        type_img_name, type_flag, type_format)
                else:
                    row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % (
                        os.path.splitext(os.path.basename(img_name))[0],
                        type_img_name, type_flag, type_format)

    client_output_dict = {}
    client_output_dict["$RESPATH$"] = row_texts

    gen_file(client_template, client_output, client_output_dict, False)

    print 'plist ok! start convert!'

    #处理文件

    if argv_type == 'win32':

        safeRmTree("..\\..\\client\\res")

        import time
        time.sleep(2)

        while os.path.exists("..\\..\\client\\res"):
            pass

        shutil.copytree('res', "..\\..\\client\\res", False, ignoreFile)
        if os.path.exists("..\\..\\client\\res\\audio"):
            shutil.rmtree("..\\..\\client\\res\\audio", True)
            os.makedirs("..\\..\\client\\res\\audio")
        #win32音效特殊处理
        #for file_name in os.listdir("res\\audio\\win32\\"):
        #    sub_path = os.path.join("res\\audio\\win32\\", file_name)
        #    if os.path.isdir(sub_path):
        #        continue
        #    else:
        #        safeCopy(sub_path,"..\\..\\client\\res\\audio")
        #
        copyFiles("res\\audio\\win32\\", "..\\..\\client\\res\\audio")
        #公共资源改名覆盖
        for publicres_key in publicres_dict.iterkeys():
            print 'win32 copy %s to %s' % (
                "..\\..\\client\\" + publicres_key + "_" + argv_platform +
                ".png", "..\\..\\client\\" + publicres_key + ".png")
            shutil.copy(
                "..\\..\\client\\" + publicres_key + "_" + argv_platform +
                ".png", "..\\..\\client\\" + publicres_key + ".png")

        #多语言资源改名覆盖
        if argv_lang != 'gbk' and argv_lang != 'multi':
            for languageres_key in languageres_dict.iterkeys():
                print 'win32 copy %s to %s' % (
                    "..\\..\\client\\" + languageres_key + "_" + argv_lang +
                    ".png", "..\\..\\client\\" + languageres_key + ".png")
                shutil.copy(
                    "..\\..\\client\\" + languageres_key + "_" + argv_lang +
                    ".png", "..\\..\\client\\" + languageres_key + ".png")

        return

    #处理配置的plist
    safeRmTree("temp\\")

    convert_flag = False

    for row_key, row_value in plist_dict.iteritems():
        #处理图片

        convert_flag = False

        for j in xrange(0, len(row_value)):
            #拆分目录
            img_flag = row_value[j][0]
            img_name = row_value[j][1]
            img_format = row_value[j][2]

            img_path = os.path.dirname(img_name) + '\\'

            if img_flag == 4:
                img_path = ""

            img_flag = getImageFlag(img_name)
            copy_flag = 1
            if img_flag == IMAGE_FLAG_JSON or img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_FONT:
                copy_flag = 0

            if row_key.lower() == 'none':
                if img_name.find('\\ui\\') >= 0 or img_name.find(
                        '\\audio\\') >= 0 or img_name.find(
                            '\\json\\') >= 0 or img_name.find(
                                '\\skilleffect\\') >= 0:
                    pass
                else:
                    img_path = ''

            if not os.path.exists("temp\\" + img_path):
                os.makedirs("temp\\" + img_path)

            #查找是否多平台文件
            continue_flag, target_name = getPublicresFlag(
                img_name, publicres_dict, argv_platform)

            if continue_flag:
                continue
            else:
                img_publicres_name = target_name

            #查找是否多语言文件
            continue_flag, target_name = getLanguageresFlag(
                img_name, languageres_dict, argv_lang)

            if continue_flag:
                continue
            else:
                img_publicres_name = target_name

            if not os.path.exists(img_name):
                print img_name, "not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
            else:
                safeCopy(
                    img_name,
                    "temp\\" + img_path + os.path.basename(img_publicres_name))

            if img_name.replace('\\', '/') in diff_list:
                convert_flag = True

            if row_key.lower() == 'none':
                if (diff_flag and convert_flag) or not diff_flag:
                    cmd_text = "res\\xcopy.bat %s temp %s 0 %d %s" % (
                        '..\\..\\outputClient\\' + argv_type + '\\' +
                        os.path.splitext(img_publicres_name)[0],
                        getFormatFlag(argv_type,
                                      img_format), copy_flag, img_path)
                    os.system(cmd_text)
                    safeRmTree("temp\\")
                    convert_flag = False
                else:
                    safeRmTree("temp\\")
                    convert_flag = False

        if row_key.lower() != 'none':
            if (diff_flag and convert_flag) or not diff_flag:
                cmd_text = "res\\xcopy.bat %s temp %s 1 %d" % (
                    '..\\..\\outputClient\\' + argv_type + '\\' + row_key,
                    getFormatFlag(argv_type, img_format), copy_flag)
                os.system(cmd_text)
                #如果目标图没有生成,那么抛异常
                if (not os.path.exists('..\\..\\outputClient\\' + argv_type +
                                       '\\' + row_key + '.png')
                    ) and (not os.path.exists('..\\..\\outputClient\\' +
                                              argv_type + '\\' + row_key +
                                              '.pvr.ccz')
                           ) and (not os.path.exists('..\\..\\outputClient\\' +
                                                     argv_type + '\\' +
                                                     row_key + '.dds')):
                    raise

                safeRmTree("temp\\")
            else:
                safeRmTree("temp\\")

    #遍历处理其他文件
    for row_key, row_value in path_dict.iteritems():
        #处理图片
        for j in xrange(0, len(row_value)):
            #拆分目录
            img_path = row_key
            img_name = row_value[j]

            img_format = 'none'

            img_path = os.path.dirname(img_name) + '\\'

            if img_name.find('.png') >= 0 or \
            img_name.find('.mp3') >= 0 or \
            img_name.find('.caf') >= 0 or \
            img_name.find('.m4a') >= 0 or \
            img_name.find('.ExportJson') >= 0 or \
            img_name.find('.csb') >= 0 or \
            img_name.find('.json') >= 0 or \
            img_name.find('.tmx') >= 0 or \
            img_name.find('.plist') >= 0 or \
            img_name.find('.fnt') >= 0 or \
            img_name.find('.ttf') >= 0 or \
            img_name.find('.ogg') >= 0 :
                pass
            else:
                continue

            img_flag = getImageFlag(img_name)
            copy_flag = 1
            if img_flag == IMAGE_FLAG_JSON or img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_FONT:
                copy_flag = 0

            #查找是否已经被plist,win32不做plist
            continue_flag = getPlistedFlag(img_name, plist_dict, argv_type)

            if continue_flag:
                continue

            #查找是否有同名plist
            if img_flag == IMAGE_FLAG_NORMAL:
                found_flag = getPlistExistedFlag(img_name, path_dict, row_key)

                if found_flag:
                    #复制过去
                    safeCopy(
                        img_name,
                        "..\\..\\outputClient\\" + argv_type + '\\' + img_path)
                    img_plist = os.path.splitext(img_name)[0] + '.plist'
                    safeCopy(
                        img_plist,
                        "..\\..\\outputClient\\" + argv_type + '\\' + img_path)
                    continue

            #查找是否多平台文件
            continue_flag, target_name = getPublicresFlag(
                img_name, publicres_dict, argv_platform)

            if continue_flag:
                continue
            else:
                img_publicres_name = target_name

            #查找是否多语言文件
            continue_flag, target_name = getLanguageresFlag(
                img_name, languageres_dict, argv_lang)

            if continue_flag:
                continue
            else:
                img_publicres_name = target_name

            convert_flag = False
            if img_name.replace('\\', '/') in diff_list:
                convert_flag = True

            if (diff_flag and convert_flag) or not diff_flag:
                pass
            else:
                continue

            #产生图像格式
            img_format = getImageType(img_name, argv_type)

            img_ext = os.path.splitext(img_name.replace('\\', '/'))[1]
            if img_ext.lower() != '.png':
                if img_flag == IMAGE_FLAG_NORMAL or img_flag == IMAGE_FLAG_FONT:

                    #音效文件特殊处理
                    if img_path.find('res\\audio\\') >= 0:
                        if img_path.find('\\' + 'win32' + '\\') <= 0:
                            continue
                        else:
                            img_path = img_path.replace(
                                '\\' + 'win32' + '\\', '\\')

                    safeCopy(
                        img_name,
                        "..\\..\\outputClient\\" + argv_type + '\\' + img_path)

                elif img_flag == IMAGE_FLAG_JSON:
                    safeCopy(
                        img_name,
                        "..\\..\\outputClient\\" + argv_type + '\\' + img_path)
                elif img_flag == IMAGE_FLAG_MAP:
                    safeCopy(
                        img_name,
                        "..\\..\\outputClient\\" + argv_type + '\\' + img_path)
                elif img_flag == IMAGE_FLAG_CSB:
                    safeCopy(
                        img_name,
                        "..\\..\\outputClient\\" + argv_type + '\\' + img_path)
                print 'copy ' + img_name
            else:
                if img_name.find('\\ui\\') >= 0 or img_name.find(
                        '\\audio\\') >= 0 or img_name.find(
                            '\\json\\') >= 0 or img_name.find(
                                '\\skilleffect\\') >= 0:
                    pass
                else:
                    img_path = ''

                if not os.path.exists(img_name):
                    print img_name, "not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
                else:
                    safeCopy(
                        img_name, "temp\\" + img_path +
                        os.path.basename(img_publicres_name))

                cmd_text = "res\\xcopy.bat %s temp %s 0 %d %s" % (
                    "..\\..\\outputClient\\" + argv_type + '\\' +
                    os.path.splitext(img_publicres_name)[0],
                    getFormatFlag(argv_type, img_format), copy_flag, img_path)
                os.system(cmd_text)
                safeRmTree("temp\\")
Exemplo n.º 7
0
def converter_plist(excel_file, sheet_name, argv_type, argv_lang):
    book = xlrd.open_workbook(excel_file)
    sheet = book.sheet_by_name(sheet_name)
    print sheet.name

    rows_dict = {}

    for i in xrange(1, sheet.nrows):
        # 循环sheet中的行
        if argv_type.lower() == 'ios' and argv_lang.lower() != 'multi':
            row_key = _utf8(sheet.cell_value(i, 0))
        elif argv_type.lower() == 'android' and argv_lang.lower() != 'multi':
            row_key = _utf8(sheet.cell_value(i, 1))
        elif argv_type.lower() == 'wp8' and argv_lang.lower() != 'multi':
            row_key = _utf8(sheet.cell_value(i, 2))
        elif argv_type.lower() == 'ios' and argv_lang.lower() == 'multi':
            row_key = _utf8(sheet.cell_value(i, 3))
        elif argv_type.lower() == 'android' and argv_lang.lower() == 'multi':
            row_key = _utf8(sheet.cell_value(i, 4))
        elif argv_type.lower() == 'wp8' and argv_lang.lower() == 'multi':
            row_key = _utf8(sheet.cell_value(i, 5))
        else:
            row_key = _utf8(sheet.cell_value(i, 0))

        row_flag = _int(sheet.cell_value(i, 6))
        row_value = _utf8(sheet.cell_value(i, 7))

        if argv_type.lower() == 'ios':
            row_format = _utf8(sheet.cell_value(i, 8))
        elif argv_type.lower() == 'android':
            row_format = _utf8(sheet.cell_value(i, 9))
        elif argv_type.lower() == 'wp8':
            row_format = _utf8(sheet.cell_value(i, 10))
        else:
            row_format = _utf8(sheet.cell_value(i, 8))

        #文件
        if row_flag == 1:
            if row_value.find('.png') >= 0:
                if rows_dict.has_key(row_key):
                    rows_dict[row_key].append(
                        [row_flag, row_value, row_format])
                else:
                    rows_dict[row_key] = [[row_flag, row_value, row_format]]
        #目录
        elif row_flag == 2 or row_flag == 4:
            for file_name in os.listdir(row_value):
                if os.path.isdir(row_value + os.path.sep + file_name):
                    continue

                if file_name.find('.png') >= 0:
                    if rows_dict.has_key(row_key):
                        rows_dict[row_key].append([
                            row_flag, row_value + os.path.sep + file_name,
                            row_format
                        ])
                    else:
                        rows_dict[row_key] = [[
                            row_flag, row_value + os.path.sep + file_name,
                            row_format
                        ]]
        #忽略
        elif row_flag == 3:
            if rows_dict.has_key(row_key):
                delete_index = -1
                for i in xrange(0, len(rows_dict[row_key])):
                    if rows_dict[row_key][i][1] == row_value:
                        delete_index = i
                        break
                if delete_index != -1:
                    del rows_dict[row_key][delete_index]
        else:
            pass

    return rows_dict