标签:
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
#!/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