genstr.py
#!/usr/bin/python
#-*- coding:utf-8 –*- import os
import sys
import re
import shutil
import xlrd
import xlwt
import getopt
import math
from xlutils.copy import copy '''
脚本使用:
设置strUiPorject ui项目名称,取值如下 "mstar"/"formal"/"haier"/"videocon"/"bbk"/"atv_project"
删除无用字串: ./genstr -d
特殊标记的字串优先排序: ./genstr -p
给已整理好优先级高的字串添加strMark..../genstr -a
读取 优先级字串整理.h 中的字串进行比对添加标记(未整理)./genstr -c 脚本功能:
1、根据strUiPorject设置的UI名称,迭代过滤UI目录的所有源文件和头文件,获取项目使用字串总数,并删除UIL多余字串
2、对某一种语言做特殊标记strMark,标记的字串会放在翻译的最前面
3、mstar优先级字串整理在mstarPrimaryString.h,已使用字串整理在UsedString.h中,
formal优先级字串整理在PrimaryString.h
执行过程:
1、设置UI项目名称
2、根据UI名称,配置过滤路径和UIL删除路径(filterPath/strUilPath)
3、再根据配置的路径执行过滤和删除动作 注意:
SourceCode中,有一些是 TV_IDS_String_ID+Offset方式获取新字串的,这些字串要手动加到脚本,以防误删
如:TV_IDS_String_GMT_0 字串
''' #=======注意此处设置UI项目================================#
#=="mstar"/"formal"/"haier"/"videocon"/"bbk"/"atv_project"=#
strUiPorject = "mstar"
#========================================================# g_deleteMode = 0
g_priorityMode = 0
g_AddmarkMode = 0
g_CompareMode = 0 setStr = set()
tupleStr = ()
strMark = "aaaa" #=======================以下不需要设置=======================#
if "bbk" in strUiPorject:
filterPath = "aps/application/radisson/formal"
strUilPath = "aps/application/radisson/formal/UI_Project/TV_UIProject/Languages"
elif "formal" in strUiPorject:
filterPath = "aps/application/radisson/formal"
strUilPath = "aps/application/radisson/formal/UI_Project/TV_UIProject_new/Languages"
else:
filterPath = "aps/application/radisson/%s" % strUiPorject
strUilPath = "aps/application/radisson/%s/UI_Project/TV_UIProject/Languages" % strUiPorject
gamePath = "aps/game" listPath = [filterPath,gamePath] def filterUsefulString():
listStrId = []
for path in listPath:
for dirPath, dirNames, fileNames in os.walk(path):
for sourceFile in fileNames:
filePath = dirPath+"/"+sourceFile
if (re.search(".*\.c.*",sourceFile) or re.search(".*\.h.*",sourceFile)) \
and sourceFile != "TV_strid.h":
for line in open(filePath,"r"):
if "TV_IDS_String" in line:
if line.count("TV_IDS_String") > 2:
print "\n\nthe number of string are more than 2 in a row \n\n "
print sourceFile
print "\n"
continue
if re.search(".*TV_(IDS_String\w*).*TV_(IDS_String\w*).*",line):
tupleStr=re.search(".*TV_(IDS_String\w*).*TV_(IDS_String\w*).*",line).groups()
for i in range(len(tupleStr)):
setStr.add(tupleStr[i])
else:
setStr.add(re.search(".*TV_(IDS_String\w*).*",line).group(1))
elif "TV_IDS_Game_Menu_OSD_String" in line:
setStr.add("IDS_Game_Menu_OSD_String") print "\n\n程序中共使用 %d 个字串。\n保存在当前目录 UsedString.h-文件中\n\n" % len(setStr)
for line in setStr:
listStrId.append(line)
listStrId.append("\n")
open("UsedString.h","w").writelines(listStrId) '''
#读EXCEL到映射表
def excelSetting()
setElStr = set()
mapStr = {}
listFirst = []
setDiff = set()
book = xlrd.open_workbook(r'Languages.xls')
sheet = book.sheet_by_index(0) listFirst = sheet.row_values(0) for row in range(sheet.nrows):
cellStr = str(sheet.cell(row,0).value)
cellStr.rstrip()
if cellStr in setStr:
mapStr[cellStr] = sheet.row_values(row) #setElStr = set(mapStr.keys())
#setDiff = setElStr - setStr #写EXCEL
wboot = xlwt.Workbook()
sheet = wboot.add_sheet("Language")
#操作第一行,抬头
for col in range(len(listFirst)):
sheet.write(0,col,listFirst[col]) #其它行
row = 1
for (k,v) in mapStr.items():
for col in range(len(v)):
sheet.write(row,col,v[col])
row = row + 1
wboot.save(r'Language_.xls') '''
#处理UIL文件,对比setStr集合,删除无用字串
def deleteString():
delCount = 0
lanList = []
for dirPath,dirNames,fileNames in os.walk(strUilPath):
for sourceFile in fileNames:
filePath = dirPath + "/" + sourceFile
for line in open(filePath,"r"):
#==============================================#
#有些字串在code中是以偏移量的方式使用,不能删除
if "IDS_String_GMT_" in line:
lanList.append(line)
continue
elif re.search(".*IDS_String_\d{1,2}\".*",line) or ("IDS_String_LNB" in line):
lanList.append(line)
continue
# ==============================================# if "<String ID=" in line:
if re.search("\s*<String ID=\"(\w*)\".*",line).group(1) in setStr:
lanList.append(line)
else:
delCount = delCount+1
else:
lanList.append(line)
open(filePath,"w").writelines(lanList)
print(sourceFile + "删除 %s" %delCount)
lanList = []
delCount = 0 #处理UIL文件,迭代lanFist集合,标记字串放在UIL文件前面
def priorityString():
lanFist = []
lanList1 = []
lanList2 = []
lanList3 = []
pat = re.compile(".*\"(IDS_String\w*)\".*")
for line in open(strUilPath+"/English.uil","r").readlines():
if strMark in line and pat.search(line):
lanFist.append(pat.search(line).group(1))
open("PrimaryString.h", "a").writelines([x + "\n" for x in lanFist])
print "优先级字串共%d,如下:" %len(lanFist)
print lanFist for dirPath, dirNames, fileNames in os.walk(strUilPath):
for sourceFile in fileNames:
filePath = dirPath + "/" + sourceFile
for line in open(filePath, "r"):
if pat.search(line) and pat.search(line).group(1) in lanFist:
line = line.replace(strMark,"")
lanList1.append(line)
elif "IDS_String_spliteLine" in line:
lanList3.append(line)
else:
lanList2.append(line)
if(len(lanList1) and len(lanList2)>=3):
lanList2 = lanList2[0:2] +lanList1 + lanList3+lanList2[2:]
open(filePath, "w").writelines(lanList2)
lanList1 = []
lanList2 = [] #给已整理好优先级高的字串添加strMark
def AddMark():
StringList = []
a = 0
for line in open(strUilPath+"/English.uil","r") :
if ("<String ID=" in line):
if re.search("IDS_String_spliteLine",line):
a = 1
elif(a == 0):
line = line.replace('Value="','Value="'+strMark)
StringList.append(line)
open(strUilPath+"/English.uil","w").writelines(StringList)
print "\n添加StrMark完成\n" #读取 优先级字串整理.h 中的字串进行比对添加标记(未整理)
def CompareAddMark():
strSet = set()
strList = []
for line in open("PrimaryString.h", "r"):
strSet.add(re.search(".*(IDS_String_.*).*",line).group(1))
print strSet
for line in open(strUilPath+"/English.uil","r") :
if "<String ID=" in line:
if re.search("\s*<String ID=\"(\w*)\".*", line).group(1) in strSet:
print "a\n"
line = line.replace('Value="','Value="'+strMark)
strList.append(line)
open(strUilPath+"/English.uil","w").writelines(strList) def fun_parse_InputParam():
global g_deleteMode
global g_priorityMode
global g_AddmarkMode
global g_CompareMode
try:
opts, args = getopt.getopt(sys.argv[1:], 'dpac')
except getopt.GetoptError, err:
#print str(err)
sys.exit() for op, value in opts:
if op == "-d":
g_deleteMode = 1
elif op == "-p":
g_priorityMode = 1
elif op == "-a":
g_AddmarkMode = 1
elif op == "-c":
g_CompareMode = 1
else:
print("unhandled option")
sys.exit() if __name__ == "__main__":
fun_parse_InputParam()
if g_deleteMode:
filterUsefulString()
deleteString()
if g_priorityMode:
priorityString()
if g_AddmarkMode:
AddMark()
if g_CompareMode:
CompareAddMark()
genstr.py的更多相关文章
- python调用py中rar的路径问题。
1.python调用py,在py中的os.getcwd()获取的不是py的路径,可以通过os.path.split(os.path.realpath(__file__))[0]来获取py的路径. 2. ...
- Python导入其他文件中的.py文件 即模块
import sys sys.path.append("路径") import .py文件
- import renumber.py in pymol
cp renumber.py /usr/local/lib/python2.7/dist-packages/pymol import renumber or run /path/to/renumber ...
- python gettitle.py
#!/usr/bin/env python # coding=utf-8 import threading import requests import Queue import sys import ...
- 解决 odoo.py: error: option --addons-path: The addons-path 'local-addons/' does not seem to a be a valid Addons Directory!
情况说明 odoo源文件路径-/odoo-dev/odoo/: 我的模块插件路径 ~/odoo-dev/local-addons/my-module 在my-module中创建了__init__.py ...
- caffe机器学习自带图片分类器classify.py实现输出预测结果的概率及caffe的web_demo例子运行实例
caffe机器学习环境搭建及python接口编译参见我的上一篇博客:机器学习caffe环境搭建--redhat7.1和caffe的python接口编译 1.运行caffe图片分类器python接口 还 ...
- 【转】Windows下使用libsvm中的grid.py和easy.py进行参数调优
libsvm中有进行参数调优的工具grid.py和easy.py可以使用,这些工具可以帮助我们选择更好的参数,减少自己参数选优带来的烦扰. 所需工具:libsvm.gnuplot 本机环境:Windo ...
- MySqlNDB使用自带的ndb_setup.py安装集群
在用Mysql做集群时,使用Mysql的NDB版本更易于集群的扩展,稳定和数据的实时性. 我们可以使用Mysql自带的工具进行集群安装与管理:ndb_setup.py.位于Mysql的安装目录bin下 ...
- 将做好的py文件打包成模块,供别人安装调用
现在要将写完的3个py文件,打包. 步骤: 1.新建一个文件夹setup(名字随便取),在setup文件夹下,再新建一个文件夹financeapi. 2.将上面4个py文件拷贝至financeapi文 ...
随机推荐
- CF294C Shaass and Lights
题目大意: 有n盏灯,(0<=n<=1000),有m盏已经点亮,每次只能点亮与已经点亮的灯相邻的灯,求总方案数,答案对1e9+7取模 第一行:两个整数n,m表示灯的总数和已点亮的灯的数目 ...
- 【模板】Tarjan scc缩点
代码如下 #include <bits/stdc++.h> using namespace std; const int maxv=1e4+10; const int maxe=1e5+1 ...
- redux与react-redux
Redux是一个数据状态管理插件,论是移动端还是 pc 端,当你使用 React 或者 vue 开发组件化的 SPA 程序时, 组件之间共享信息是一个非常大的问题.在react开发中,使用 React ...
- java.lang.OutOfMemoryError及解决方案
主要有3种比较常见的OutOfMemory Error: java.lang.OutOfMemoryError: Java heap space java.lang.OutOfMemoryError: ...
- 许仙章鱼TV
http://v.youku.com/v_show/id_XMTY3NTYwNTE4MA==.html?from=s1.8-1-1.2&spm=a2h0k.8191407.0.0 201608 ...
- VS2010程序崩溃,报错Unhandled exception at **.exe:0xC0000005: Access violation reading location 0x000000008899.
最近被派到另外一个组支援,从而从Linux下开发暂转到Windows下开发,个人觉得Windows自己搞的一套并不那么完美,坑多. 网文可能出现的原因: 未处理的异常: 0xC0000005: 读取位 ...
- Yosimite10.10(Mac os)安装c/c++内存检测工具valgrind
1.下载支持包m4-1.4.13.tar.gz $ curl -O http://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz 2. 解压m4-1.4.13.t ...
- Linux网络协议栈(一)——Socket入门(2)
转自: http://www.cnblogs.com/hustcat/archive/2009/09/17/1568765.html 3.套接字的实现套接字最先是在UNIX的BSD版本实现的,所以也叫 ...
- Scala进阶之路-Spark独立模式(Standalone)集群部署
Scala进阶之路-Spark独立模式(Standalone)集群部署 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我们知道Hadoop解决了大数据的存储和计算,存储使用HDFS ...
- 函数和常用模块【day04】:函数介绍(一)
本节内容 1.函数介绍 2.函数定义 3.为什么要使用函数 一.介绍 在我们以往的学习编程的过程当中,碰到的最多的两张编程方式或者说编程方法:面向过程和面向对象.其实不管是哪一种,其实都是编程的方法论 ...