# -*- coding: cp936 -*-
## function: remove file
## remark: python version --
import os,sys
import logging,re
import time, datetime
PART = "file"
LOG_PATH = "./rmfile.log"
##global del_number=
del_number =
## 写日志
logger = logging.getLogger()
formatter =logging.Formatter ("%(asctime)s - %(levelname)s - %(message)s")
file_handler = logging.FileHandler(LOG_PATH)
file_handler.setFormatter(formatter)
stream_handler = logging.StreamHandler(sys.stderr)
logger.addHandler(file_handler)
logger.addHandler(stream_handler)
logger.setLevel(logging.DEBUG)
def rmfile():
try:
res_rm =
os.system("adb shell ls /mnt/sdcard > ./filename.txt")
## print "find file and remove"
fd = open("./filename.txt")
##如果文件中没有内容,连接失败,退出
if os.stat ("./filename.txt").st_size ==:
res_rm = -
## print "connect devices failed, in rm ()"
logger.debug("connect devices failed")
return res_rm
for eachline in fd:
## print "each line",eachline
if re.search(PART,eachline):
## print "file is here"
global del_number
del_number = del_number +
os.system("adb shell rm /mnt/sdcard/file")
## print "delete file"
logger.debug("file id here,delete file")
##
logger.debug("start iperf explorer")
os.system ("E:/jperf-2.0.0/jperf-2.0.0/bin/iperf.exe -c ***.***.***.*** -u -i 1 -t 20 -b 800K -l 500 > D:/Pyehon2_7_3/iperf.log")
fd_iperf = open("./iperf.log")
for eachline_iperf in fd_iperf:
print eachline_iperf
logger.debug(eachline_iperf)
logger.debug("end iperf explorer")
return res_rm
except Exception,e:
print str(e)
res_rm = -
logger.error("[Exception]"+str(e))
return res_rm
def main():
global del_number
## AVG_bw =
TOL_bw =
try:
logger.debug("============start==============")
for i in range(,):
## 60s 检查一次文件,检查1000次
logger.debug("nu "+str(i)+" start")
res = rmfile()
if res == -:
## print "connect devices failed" ,res
logger.error("connect devices failed")
logger.debug("=============end================")
return res
time.sleep()
## print i,"find 1000"
logger.debug("nu "+str(i)+" end")
logger.debug("********iperf explorer"+str(del_number)+"********")
logger.debug("***********iperf explorer"+"res"+"***************")
fd_iperf = open("./iperf.log")
for eachline in fd_iperf:
## print eachline
par1 = re.search ("0.0-",eachline)
par2 = re.search ("%",eachline)
if par1 and par2:
logger.debug(eachline)
TOL_bw = TOL_bw + int(eachline.split(" ")[])
## print "TOL_bw",TOL_bw
## print "del_number" ,del_number
AVG_bw = float(TOL_bw)/float(del_number)
## print "AVG_bw",AVG_bw
logger.debug("*******iperf explorer AVG "+str(AVG_bw)+"********")
logger.debug("********del file "+str(del_number)+"********")
logger.debug("=============end===============")
return
except Exception,e:
print str(e)
logger.error("[Exception]"+str(e))
res = -
return res
if __name__ == "__main__":
main()