#!/usr/bin/python #coding =utf-8
Import SYS import OS import shutil import struct import hashlib import re
G_work_path = "E:\phoneclient" G_target_path = [#lua: ["%s/sdz/script", "(. *\.lua)",],] g_output_list = []
#跳转至当前目录 Os.chdir (Os.path.abspath (sys.path[0)) os.environ[' LANG '] = "Zh_cn.utf8"
#检查中文内容 def Check (): Global G_work_path Global G_target_path
For target_path in G_target_path:final_path = Target_path[0]%g_work_path
Match_str = "" If Len (target_path) > 1:match_str = target_path[1]
#判断是文件还是文件夹 if Os.path.isfile (final_path): Checksinglefile (final_path) Continue Else:final_path = Checkendwi Thossep (Final_path)
For Dir_info in Os.walk (final_path): #跳过隐藏文件夹 if-1! = Dir_info[0].find ("/.") Or-1! = dir_info[0].find ("\ \"): Continue
Tmp_path = Dir_info[0][len (Final_path):] If ""! = Tmp_path:tmp_path = Checkendwithossep (Tmp_path)
For I in dir_info[2]: #这几个文件是ANSI编码, no Chinese, temporarily shielded if "reslvlogicdumper.lua" = = I or "protocalonlinegift.lua" = = I or "Equipexchangelayer.lua" = = I or "facechatexlayer.lua" = = I:continue
If ""! = Match_str:match_ret = Re.match (Match_str, "%s%s"% (Tmp_path, i)) if Match_ret and Len (Match_ret.groups ( ) > 0:checksinglefile ("%s%s%s"% (Final_path, Tmp_path, i)) else:checksinglefile ("%s%s%s"% (Final_path, Tmp_path, i))
#检查单个文件 def checksinglefile (file_path): Global g_output_list
Tmp_file = open (File_path, "rb+") File_info = Tmp_file.readlines () tmp_file.close ()
Found = False Line_Count = 0 for Str_line in File_info:line_count + 1 if Checksingleline (Onlystr (str_line)): If Not found:found = True g_output_list.append (file_path + "\ n") #记录文件名和行数 g_output_list.append (str (Line_coun T) + "\ n")
#检查单独一行 def checksingleline (str_line): If "--" = = Str_line[:2]: return False
zh_match = Re.match (ur ". *[\ ' \"].*[\u4e00-\u9fa5]+.*[\ ' \ "].*", Str_line.decode ("UTF8")) #排除输出日志内容 Log_match = Re.match (Ur ". * (?:P rintlog|colog|cmd_colog). *[\ ' \"].*[\u4e00-\u9fa5]+.*[\ ' \ "].*", Str_line.decode ("UTF8")) return Zh_match And not Log_match
#补充斜杠 def checkendwithossep (path_str): If Path_str.endswith ("/") or Path_str.endswith ("\ \"): Return PATH_STR return PA Th_str + os.path.sep
#剔除空白字符 def onlystr (tmp_str): return Tmp_str.strip ("\ r \ n"). Strip ("\ n"). Strip ("\ T"). Strip ()
#输出结果 def writeresult (): Global g_output_list
Tmp_file = open ("Check.txt", "W") Tmp_file.writelines (g_output_list) tmp_file.close ()
if __name__ = = "__main__": Check () Writeresult ()
Python reads all LUA files that contain Chinese strings in the folder and its subfolders