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

  • 多线程
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)



    原文作者:望月成三人
    原文地址: https://www.jianshu.com/p/a8e1bd7f0d26
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞