#!/usr/bin/env python
import wx
import os
import sys
import time
from threading import Thread
#执行adb命令函数
#使用到的线程:RunMonkeyThread(),KillMonkeyThread(),ExportLogThread()
def excuOrder(orderName):
c = os.system(orderName)
print(c)
return c
#将指定内容写入指定文件(写入monkey日志报错信息)
#使用到的函数:findException()
def writeFile(FileName, content):
FName = open(FileName, 'a')
FName.write(content)
FName.close()
#查找指定文件里指定字符串的个数,并输出字符串所在行的内容
#使用到的线程:ExportLogThread()
def findException(tfile,sstr):
try:
lines=open(tfile,'r').readlines()
flen=len(lines)-1
acount = 0
fileException = "%s_%s" % (tfile,sstr)
tfileException = "%s.txt" % fileException
writeFile(tfileException,"%s keywords:\n" % fileException)
for i in range(flen):
if sstr in lines[i]:
lineException = '\t%s\n'% lines[i]
writeFile(tfileException,lineException)
acount+= 1
writeFile(tfileException,"%s frequency:%s" % (fileException,acount))
print('Please check Exception keywords in the "%s"\n' % tfileException)
except Exception as e:
print(e)
class RunMonkeyThread(Thread):
def __init__(self):
#线程实例化是立即启动
Thread.__init__(self)
self.logNameST = logNameST
self.start()
def run(self):
print("Start running monkey ...\n")
self.packageName=packageText.GetValue()
self.MonkeyTime=MTText.GetValue()
self.MonkeyCount=MCText.GetValue()
self.strTime = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
self.logName = '%s_%s_monkey.log'%(self.packageName,self.strTime)
open(r"logname.txt",'w').write(self.logName)
self.logNameST.SetLabel("%s" % self.logName)
self.orderName1='adb shell "monkey -p %s --throttle %s --ignore-crashes --monitor-native-crashes \
--ignore-security-exceptions --ignore-timeouts --ignore-native-crashes --pct-syskeys\
0 --pct-nav 20 --pct-majornav 20 --pct-touch 40 --pct-appswitch 10 -v -v -v %s\
> /sdcard/%s&" '% (self.packageName,self.MonkeyTime,self.MonkeyCount,self.logName)
&nb