get log

C:Userswb_changxiang.chenDesktopget_log_adb.py

#! /usr/bin/env python
import os
import sys
import time
import zipfile
import subprocess
import shutil
import urllib2
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import poster


adb_prg = "adb"
def main(outdir):
global adb_prg
timestr = str(time.time())
timestr = timestr[0:10]
os.system("%s root"%adb_prg)
print ("wait-for-device ...")
os.system("%s wait-for-device"%adb_prg)
print ("device is ok.")
dirname = os.path.join(outdir,"upload_log_%s"%timestr)
if not os.path.exists(dirname):
os.makedirs(dirname)
os.system("%s shell getprop ro.yunos.build.version >%s"%(adb_prg,os.path.join(dirname,"version.txt")))
os.system("%s shell getprop >%s"%(adb_prg,os.path.join(dirname,"prop.txt")))
args = [adb_prg,"shell","ls","/data/","/mnt/sdcard/"]
retval,output = execute2(args)
datadir = []
items = output.split(" ")

for item in items:
item = item.strip()
if item == "anr":
datadir.append("/data/anr")
elif item == "apr":
datadir.append("/data/apr")
elif item == "tombstones":
datadir.append("/data/tombstones")
elif item == "tombstones_apr":
datadir.append("/data/tombstones_apr")
elif item == "aee_exp":
datadir.append("/mnt/sdcard/aee_exp")
for dirs in datadir:
os.system("%s pull %s %s >/dev/null 2>&1"%(adb_prg,dirs,dirname))
'''
os.system("%s pull /data/anr/ %s"%(adb_prg,dirname))
os.system("%s pull /data/apr/ %s"%(adb_prg,dirname))
os.system("%s pull /data/tombstones/ %s"%(adb_prg,dirname))
os.system("%s pull /data/tombstones_apr/ %s"%(adb_prg,dirname))
os.system("%s pull /mnt/sdcard/mtklog/aee_exp/ %s"%(adb_prg,dirname))
'''
zipname = dirname + ".zip"
zip = zipfile.ZipFile(zipname,"w",zipfile.ZIP_DEFLATED,True)
filecount = 0
for root,dirs,files in os.walk(dirname):
for file in files:
if file.startswith("anr") or file.startswith("tombstone") or file.startswith("error") or file.startswith("db."):
filename = os.path.join(root,file)
zip.write(filename,file)
filecount += 1
zip.write(os.path.join(dirname,"version.txt"),"version.txt")
zip.write(os.path.join(dirname,"prop.txt"),"prop.txt")
zip.close()
shutil.rmtree(dirname)
if filecount == 0:
os.remove(zipname)
print "Not found anr,apr,tombstone,mtk log file"
else:
print "create zip file %s"%zipname
#upload_file(zipname,"123456789")

def execute2(args):
global adb_prog
p = subprocess.Popen(args,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=False)
str = ""
for line in p.stdout:
str += line
p.wait()
return p.returncode,str


def upload_file(filename,bug_id):
register_openers()
datagen, headers = multipart_encode({"userfile": open(filename, "rb"),"action":"upload_log_file","from":"bugfree","bug_id":bug_id,"log_type":"", "username":"alibaba-test1","access_token":"Yu7&8qse.;<>mm","client_type":"python_client"})
request = urllib2.Request("http://10.125.224.50/php/upload.php", datagen, headers)
print urllib2.urlopen(request).read()


def usage(procname):

procname = os.path.basename(procname)
print " Usage: %s output_dir"%procname
print "example:"
print " %s . "%procname
print " %s log_dir "%procname

print "Syser tools for %s, version 1.0.0"%procname
print "Copyright (C) 2014 make by Wu yanfeng"
quit()

if __name__ == "__main__":
basename = os.path.basename(sys.argv[0])
if basename.endswith("adb.py"):
adb_prg = "adb"
elif basename.endswith("acb.py"):
adb_prg = "acb"
if len(sys.argv) == 1:
usage(sys.argv[0])
quit()
main(sys.argv[1])

C:Userswb_changxiang.chenDesktopget_log_adc.py

#! /usr/bin/env python
import os
import sys
import time
import zipfile
import subprocess
import shutil
import urllib2
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import poster


adb_prg = "adb"
def main(outdir):
global adb_prg
timestr = str(time.time())
timestr = timestr[0:10]
os.system("%s root"%adb_prg)
print ("wait-for-device ...")
os.system("%s wait-for-device"%adb_prg)
print ("device is ok.")
dirname = os.path.join(outdir,"upload_log_%s"%timestr)
if not os.path.exists(dirname):
os.makedirs(dirname)
os.system("%s shell getprop ro.yunos.build.version >%s"%(adb_prg,os.path.join(dirname,"version.txt")))
os.system("%s shell getprop >%s"%(adb_prg,os.path.join(dirname,"prop.txt")))
args = [adb_prg,"shell","ls","/data/","/mnt/sdcard/"]
retval,output = execute2(args)
datadir = []
items = output.split(" ")

for item in items:
item = item.strip()
if item == "anr":
datadir.append("/data/anr")
elif item == "apr":
datadir.append("/data/apr")
elif item == "tombstones":
datadir.append("/data/tombstones")
elif item == "tombstones_apr":
datadir.append("/data/tombstones_apr")
elif item == "aee_exp":
datadir.append("/mnt/sdcard/aee_exp")
for dirs in datadir:
os.system("%s pull %s %s >/dev/null 2>&1"%(adb_prg,dirs,dirname))
'''
os.system("%s pull /data/anr/ %s"%(adb_prg,dirname))
os.system("%s pull /data/apr/ %s"%(adb_prg,dirname))
os.system("%s pull /data/tombstones/ %s"%(adb_prg,dirname))
os.system("%s pull /data/tombstones_apr/ %s"%(adb_prg,dirname))
os.system("%s pull /mnt/sdcard/mtklog/aee_exp/ %s"%(adb_prg,dirname))
'''
zipname = dirname + ".zip"
zip = zipfile.ZipFile(zipname,"w",zipfile.ZIP_DEFLATED,True)
filecount = 0
for root,dirs,files in os.walk(dirname):
for file in files:
if file.startswith("anr") or file.startswith("tombstone") or file.startswith("error") or file.startswith("db."):
filename = os.path.join(root,file)
zip.write(filename,file)
filecount += 1
zip.write(os.path.join(dirname,"version.txt"),"version.txt")
zip.write(os.path.join(dirname,"prop.txt"),"prop.txt")
zip.close()
shutil.rmtree(dirname)
if filecount == 0:
os.remove(zipname)
print "Not found anr,apr,tombstone,mtk log file"
else:
print "create zip file %s"%zipname
#upload_file(zipname,"123456789")

def execute2(args):
global adb_prog
p = subprocess.Popen(args,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=False)
str = ""
for line in p.stdout:
str += line
p.wait()
return p.returncode,str


def upload_file(filename,bug_id):
register_openers()
datagen, headers = multipart_encode({"userfile": open(filename, "rb"),"action":"upload_log_file","from":"bugfree","bug_id":bug_id,"log_type":"", "username":"alibaba-test1","access_token":"Yu7&8qse.;<>mm","client_type":"python_client"})
request = urllib2.Request("http://10.125.224.50/php/upload.php", datagen, headers)
print urllib2.urlopen(request).read()


def usage(procname):

procname = os.path.basename(procname)
print " Usage: %s output_dir"%procname
print "example:"
print " %s . "%procname
print " %s log_dir "%procname

print "Syser tools for %s, version 1.0.0"%procname
print "Copyright (C) 2014 make by Wu yanfeng"
quit()

if __name__ == "__main__":
basename = os.path.basename(sys.argv[0])
if basename.endswith("adb.py"):
adb_prg = "adb"
elif basename.endswith("acb.py"):
adb_prg = "acb"
if len(sys.argv) == 1:
usage(sys.argv[0])
quit()
main(sys.argv[1])

原文地址:https://www.cnblogs.com/ccxniit2004/p/3616793.html