python multi-device package installed app

python multi-device package installed app

The Code

 1 #!/usr/bin/env python 
 2 # -*- encoding: utf-8 -*-
 3 import os 
 4 import time 
 5 from multiprocessing import Pool 
 6 list=[] 
 7 
 8 def getDevicesAll(): 
 9     #获取devices数量和名称 
10     devices = [] 
11     try: 
12         for dName_ in os.popen("adb devices"): 
13             if "\t" in dName_: 
14                 if dName_.find("emulator") < 0: 
15                     devices.append(dName_.split("\t")[0]) 
16         devices.sort(cmp=None, key=None, reverse=False) 
17         print(devices) 
18     except: 
19         pass 
20     print(u"\n设备名称: %s \n总数量:%s台" % (devices, len(devices))) 
21     return devices 
22 
23 def quickinstall(device):
24     packagename="com.ishugui"
25     #卸载原有apk 
26     try:
27 
28         os.system('adb -s ' + device + ' uninstall %s'%packagename)
29         os.system('adb -s ' + device + ' uninstall %s'%packagename)
30         print(device + " 卸载成功\n")
31     except: 
32         Print (+ Device " uninstall failed \ n- " )
 33 is  
34 is      the try :
 35          Print ( ' ----- ----- List ' , List)
 36  
37 [          for I in List: 
 38 is              the os.system ( ' the adb -s ' + + Device ' the install ' + I)
 39  
40      the except : 
 41 is          Print (+ Device " installation failed \ n- " )
 42 is      Print (+ Device "Successfully installed \ n- " )
 43 is  
44 is  DEF qainstall (Devices,):
 45      startTime = the time.time () 
 46 is      the pool = Pool (2) # create eight task pool 
47      Result = pool.map (QuickInstall, Devices)
 48      the endtime = the time.time () 
 49      pool.close () 
 50      pool.join () 
 51 is      Print (the endtime-startTime) # print time 
52 is  
53 is  DEF get_apk (filename):
 54 is      Global   List
 55      # filesname = 'F.: / downloads / APK' 
56      #Obtain the installation package 
57 is      Print (filesname)
 58      for parent, dirnames, filnames in os.walk (filesname):
 59          for FILNAME in filnames:
 60              path = the os.path.join (parent, FILNAME)
 61 is              list.append (path)
 62 is      Print ( ' ----- ----- List ' , List)
 63 is      return   List
 64  
65  # packet path 
66 filesname = ' F.: / downloads / APK ' 
67  # obtain the installation package 
68  Print(filesname)
69 for parent, dirnames, filnames in os.walk(filesname):
70     for filname in filnames:
71         path = os.path.join(parent, filname)
72         list.append(path)
73 print('-----list-----', list)
74 
75 
76 if __name__ == "__main__":
77 
78     filesname = 'F:/download/apk'
79     list=get_apk(filesname)
80  
81      the try :
 82          Devices = getDevicesAll () 
 83      the except : 
 84          Print ( " Get Device Error " ) 
 85      RES = INPUT ( " Enter Start Update 1: " ) 
 86  
87      IF int (RES) == 1 : 
 88          the try :
 89              qainstall (Devices)
 90          the except :
 91              Print ( " update failed " )
 92      # Touch (Devices)

 

Guess you like

Origin www.cnblogs.com/lisa2016/p/11209215.html