python-操作adb多线程批量安装,卸载app

2017-01-01 10:46
  • 多线程
import threading
import  time
class base_thread(threading.Thread):
    def __init__(self, func):
        threading.Thread.__init__(self)
        self.func = func
        #print(type(self.func))
    def run(self):
        self.func
  • 操作adb
# -*- coding: utf-8 -*-

import os
import time
import sys
import glob
from Base.Threads import base_thread

#单文件安装
def install(filename):
    print(filename)
    os.popen("adb install %s" % filename)

#批量安装app,多线程安装
def bact_install(dir):
    if os.path.isdir(dir):
        starttime = time.time()
        filelist= glob.glob(dir + "*.apk")
        threads = []
        for i in range(0, len(filelist)):
            threads.append(base_thread(install(filelist[i])))
        for j in range(0, len(filelist)):
            threads[j].start()
        for k in range(0, len(filelist)):
            threads[k].join()
        print("总运行时间"+str(time.time() - starttime))
    else:
        print("目录不存在")
        sys.exit(0)

#卸载app
def uninstall(packageName):
    os.popen("adb wait-for-device")
    print("start uninstall...")
    os.popen("adb uninstall %s" % packageName)