-
Notifications
You must be signed in to change notification settings - Fork 4
/
check.py
106 lines (98 loc) · 3.1 KB
/
check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# coding:utf-8
#############################################
# 查找文件中出现的中文字符串 #
#############################################
import os
import re
import sys
reload(sys)
sys.setdefaultencoding('utf8')
#输出查找结果的路径
savePath = "chinese.txt"
#需要查找的根文件夹
resPath = r"F:\\XGame\\Assets\\Lua\\System\\Chat"
#查找的匹配模式(单引号,双引号)
patterns = [r"'(.*?)'",r'"(.*?)"']
#读文件
def start_find_chinese(filePath):
find_count = 0;
if check_file_need_replace(filePath):
file = open(savePath, "a")
file.write("\n//-------------------" + filePath + "-------------------\n")
file.close()
count = 0
with open(savePath, 'a') as outfile:
with open(filePath, 'rb') as infile:
while True:
content = infile.readline()
count = count + 1
# if re.findall(patterns[0], content) or re.findall(patterns[1],content):
# if check_contain_chinese(content):
# if check_str_log(content):
# outfile.write(content)
# find_count += 1;
# pass
# pass
# pass
if content.find("FindNode") != -1:
print content
print count
pass
if not content:
return find_count
#剪裁文本文件是否有需要替换的文本
def check_file_need_replace(filePath):
find_count = 0
with open(filePath,"rb") as infile:
while True:
content = infile.readline()
if re.findall(patterns[0],content) or re.findall(patterns[1],content):
if check_contain_chinese(content):
if check_str_log(content):
find_count += 1
break
if not content:
break
return find_count > 0
pass
#判断字符是不是日志类型
def check_str_log(str):
if str.find("print") != -1:
return False
pass
if str.find("error") != -1:
return False
pass
if str.find("warn") != -1:
return False
pass
if str.find("log") != -1:
return False
pass
return True
pass
#判断是否中文+
def check_contain_chinese(check_str):
for ch in check_str.decode('utf-8'):
if u'\u4e00' <= ch <= u'\u9fff':
return True
return False
#获取所有文件
def get_files(path, rule=".lua"):
all = []
for fpathe,dirs,fs in os.walk(path): # os.walk是获取所有的目录
for f in fs:
filename = os.path.join(fpathe,f)
if filename.endswith(rule): # 判断是否是"xxx"结尾
all.append(filename)
return all
# main
if __name__ == '__main__':
file = open(savePath,"wb")
file.write("")
file.close()
files = get_files(resPath)
for i in files:
start_find_chinese(i)
print("search \t" + i + "\tover")
print("查找结束")