python 多裝置同時安裝app包

2022-08-13 17:24:14 字數 3092 閱讀 4608

上**

1

#!/usr/bin/env python 2#

-*- encoding: utf-8 -*-

3import

os 4

import

time

5from multiprocessing import

pool

6 list= 78

defgetdevicesall(): 9#

獲取devices數量和名稱

10 devices =

11try

: 12

for dname_ in os.popen("

adb devices

"):

13if"\t

"indname_:

14if dname_.find("

emulator

") <0: \t"

)[0])

16 devices.sort(cmp=none, key=none, reverse=false)

17print

(devices)

18except

: 19

pass

20print(u"

\n裝置名稱: %s \n總數量:%s臺

" %(devices, len(devices)))

21return

devices

2223

defquickinstall(device):

24 packagename="

com.ishugui"25

#解除安裝原有apk

26try:27

28 os.system('

adb -s

' + device + '

uninstall %s

'%packagename)

29 os.system('

adb -s

' + device + '

uninstall %s

'%packagename)

30print(device + "

解除安裝成功\n")

31except

: 32

print(device + "

解除安裝失敗\n")

3334

try:

35print('

-----list-----

',list)

3637

for i in

list:

38 os.system('

adb -s

' + device + '

install

' +i)

3940

except

: 41

print(device + "

安裝失敗\n")

42print(device + "

安裝成功\n")

4344

defqainstall(devices,):

45 starttime=time.time()

46 pool = pool(2) #

建立8個任務池

47 result=pool.map(quickinstall,devices)

48 endtime=time.time()

49pool.close()

50pool.join()

51print(endtime-starttime) #

列印時間

5253

defget_apk(filename):

54global

list55#

filesname = 'f:/download/apk'56#

獲取安裝包

57print

(filesname)

58for parent, dirnames, filnames in

os.walk(filesname):

59for filname in

filnames:

60 path =os.path.join(parent, filname)

6162

print('

-----list-----

', list)

63return

list

6465

#包路徑

66 filesname = '

f:/download/apk'67

#獲取安裝包

68print

(filesname)

69for parent, dirnames, filnames in

os.walk(filesname):

70for filname in

filnames:

71 path =os.path.join(parent, filname)

7273

print('

-----list-----

', list)

7475

76if

__name__ == "

__main__":

7778 filesname = '

f:/download/apk

'79 list=get_apk(filesname)

8081

try:

82 devices =getdevicesall()

83except

: 84

print("

獲取裝置出錯")

85 res = input("

輸入1開始更新:")

8687

if int(res) == 1:

88try:89

qainstall(devices)

90except:91

print("

更新失敗")

92#touch(devices)

python中如何用input 同時輸入多個資料

a,b,c input 輸入a,b空格隔開 split print type a print type b print type c 這種方式輸入的字元格式為字串型別 輸入a,b,c空格隔開 1 2 3 或者可以用 隔開 a,b,c input 輸入a,b,c用,隔開 split print typ...

python 安裝多版本

2.按預設進行安裝,不新增路徑到系統path中 3.修改系統環境變數 1 將python36和python38分別新增到系統path中 2 將各自的scripts新增到系統path中 上面的為預設啟動時優先選擇的命令查詢路徑 4.修改命令名稱 python36中的python.exe複製修改為pyt...

python安裝多版本

39.107.96.81 root 123123 pyenv 可以實現python多版本控制與切換 pyenv local 3.5.1 ipython 更方便的編寫python,可以補全命令彩色顯示等功能 yum y install gcc gcc c make git patch openssl ...