-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrash.py
97 lines (80 loc) · 2.56 KB
/
crash.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
#!/usr/bin/python
#-*- coding: utf-8 -*-
#encoding=utf-8
__author__ = 'zengmingjian'
import os
import sys
import commands
def crashFileValid(excuteFile,dsymFile):
if len(excuteFile) < 4:
return
excuteCmd = "dwarfdump --uuid " + excuteFile + "/" + excuteFile[0:len(excuteFile) - 4]
print excuteCmd
dsymCmd = "dwarfdump --uuid " + dsymFile
lines1 = os.popen(excuteCmd).readlines()
lines2 = os.popen(dsymCmd).readlines()
for line in lines1:
uuidString1 = line.split(' ')[1]
for line in lines2:
uuidString2 = line.split(' ')[1]
if (uuidString1 == uuidString2):
print ("uuidString = " + uuidString1)
return True
else:
print ("uuidString1 = " + uuidString1)
print ("uuidString2 = " + uuidString2)
print("!!!!!dsym 文件 和 可执行app文件不匹配!!!!!")
return False
#解析设置环境
def setEnvironment():
os.environ["DEVELOPER_DIR"]="/Applications/Xcode.app/Contents/Developer/" #DISPLAY是环境变量名,:0.0是要设置的值
os.system('$DEVELOPER_DIR')
#检测是否存在symbolicatecrash工具,如果不存在,则在xcode拷贝到当前目录
def getSymbolicatecrashTool():
currentDir = os.getcwd()
symbolDir = "/Applications/Xcode.app/Contents/SharedFrameworks/DTDeviceKitBase.framework/Versions/A/Resources/symbolicatecrash"
for root,dirs,files in os.walk(currentDir):
if os.path.exists(root + "/" + "symbolicatecrash"):
print("=================")
setEnvironment()
return
else:
os.system("cp " + symbolDir + " " + currentDir)
setEnvironment()
break
#遍历当前目录,解析文件
def parseCrashLog():
dirList = os.listdir(os.getcwd())
print dirList
crashList = []
dsymName = ""
appName = ""
for d in dirList:
if d.endswith(".crash") or d.endswith(".ips"):
crashList.append(d)
if d.endswith(".dSYM"):
dsymName = d
if d.endswith(".app"):
appName = d
#不存在dsym文件
if dsymName == "":
print "error:请将dsym文件考到当前目录!!!!!"
return
if appName == "":
print "error:请将app文件考到当前目录!!!!"
return
#检测dsym文件 和app文件是否匹配
if (crashFileValid(appName, dsymName) == False):
return
for crashFile in crashList:
if crashFile.endswith(".crash"):
print crashFile
print dsymName
os.system("./symbolicatecrash "+ crashFile + " " + dsymName + " >> " + crashFile.replace(".crash",".log"))
elif crashFile.endswith(".ips"):
os.system("./symbolicatecrash "+ crashFile + " " + dsymName +" >> " + crashFile.replace(".ips",".log"))
def startPaser():
getSymbolicatecrashTool()
parseCrashLog()
if __name__ == '__main__':
startPaser()