码迷,mamicode.com
首页 > 编程语言 > 详细

写个python脚本,处理bitmap.fnt文件,将信息存放入.csv文件中

时间:2016-05-13 01:42:58      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

file_util.py

#!/usr/bin/python
# encoding:utf-8
r'''
 处理文件
'''
import os

__author__ = 'andrew'


def list_files_with_filter(root, suffix):
    hint="list_files_with_filter"
    for f in os.listdir(root):
        if (f.endswith(suffix)):
            path = os.sep.join((root, f))
            yield path

define.py

#!/usr/bin/python
# encoding:utf-8
import os

cur=os.getcwd()
g_xcf_root=os.sep.join((cur,"..","dy_cike_xcf"))
g_xcf_assets=os.sep.join((g_xcf_root,"assets"))
g_xcf_config=os.sep.join((g_xcf_assets,"config"))
g_xcf_cocos=os.sep.join((g_xcf_assets,"cocostudio"))
g_xcf_skeleton=os.sep.join((g_xcf_assets,"skeleton"))
g_xcf_font=os.sep.join((g_xcf_assets,"font"))
g_working_root=os.sep.join((cur,"android","assets"))
g_working_config=os.sep.join((g_working_root,"config"))
g_working_skeleton=os.sep.join((g_working_root,"skeleton"))
g_working_font=os.sep.join((g_working_root,"font"))

fnt_inform.py

#!/usr/bin/python
# encoding:utf-8

r"""
分析assets/font/*.fnt各个字体信息,
将size等信息提取出来,存入assets/config/fnt_inform_config_r2.csv中
"""
import csv
import os

import define
import file_util


def fetch_fnt_inform():
    config_path = os.sep.join((define.g_xcf_config, "fnt_inform_config_r2.csv"))
    out = csv.writer(open(config_path, "wb+")) #一定要以二进制b的格式打开,否则两行数据间会插入空行
    key_name = "fntName"
    key_size = "size"
    key_line_height = "lineHeight"

    out.writerow([key_name, key_size, key_line_height])
    out.writerow([key_name, key_size, key_line_height])

    fnt_paths = file_util.list_files_with_filter(define.g_xcf_font, ".fnt")
    for path in fnt_paths:
        row_dic = {key_name: "", key_size: "", key_line_height: ""}
        line_count = 0
        fnt_file = open(path, "r")
        for line in fnt_file.readlines(100):
            for one_group in line.split():
                if (len(one_group) > 0):
                    kv=one_group.split("=")
                    if (len(kv) == 2):
                        key=kv[0]
                        value=kv[1]
                        if row_dic.has_key(key):
                            row_dic[key]=value
            line_count += 1
            if (line_count > 3):
                break

        csv_row=[path.split(os.sep)[-1],row_dic[key_size],row_dic[key_line_height]]
        print(csv_row)
        out.writerow(csv_row)

if __name__ == "__main__":
    fetch_fnt_inform()


写个python脚本,处理bitmap.fnt文件,将信息存放入.csv文件中

标签:

原文地址:http://blog.csdn.net/wulong710/article/details/51345392

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!