python+adb實現批量解除安裝安裝apk檔案
阿新 • • 發佈:2022-03-15
一、電腦連線手機獲取devices列表
import os # 獲取devices數量和名稱 def getDevicesAll(): devices = [] try: for dName_ in os.popen('adb devices'): if '\t' in dName_: if dName_.find('emulator')<0: devices.append(dName_.split('\t')[0]) except: pass# print(devices) return devices # getDevicesAll()
二、解除安裝安裝app任務
# 解除安裝app def uninstall_app(Ghost_package,device): try: os.system('adb -s ' + device + ' uninstall {}'.format(Ghost_package)) except: print(device + '解除安裝失敗\n') print(device + '解除安裝成功\n') # 安裝app def adb(Ghost_package,adress,device): uninstall_app(Ghost_package,device)try: flies = os.listdir("pack/{}".format(adress)) for ff in flies: print("正在安裝...") os.system('adb -s ' + device + ' install pack/{}/'.format(adress) + ff) time.sleep(1) except: print(device + '安裝失敗\n') print(device + '安裝成功\n')
三、建立任務池
# 任務池批量安裝 deftaskPlool(Ghost_package,adress,devices): starttime = time.time() pool = Pool(4) # 任務函式有多個引數時處理方案 func = partial(adb,Ghost_package,adress) result = pool.map(func,devices) endtime = time.time() pool.close() pool.join() print(endtime-starttime)
四、批量安裝
if __name__ == '__main__': taskPlool(Ghost_package,adress,devices)