安裝當前目錄下所有apk的腳本

今天要安裝幾十個apk,就寫瞭個腳本,遞歸查找當前目錄下所有的apk文件,找到一個安裝一個。
安裝環境:ubuntu10.04LTS + python2.6.5
1. 打開android設備“USB調試”
2. 重啟ADB: $sudo adb kill-server
                          $sudo adb start-server
3寫腳本findAndInstall.py:
[python]
#-*- coding: cp936 -*- 
''''' search apk and install under current folder and sub-folders 
    PythonVersion: 2.6 
     ''' 
 
__author__ = "Herbert dai wen yuan" 
__version__ = "$Revision: 1.0 $" 
__date__ = "$Date: 2012-4-24$" 
__copyright__ = "Copyright (c) 2012 HowFun" 
__license__ = "Python 2.x" 
 
import os 
 
PATH = "./" 
 
    
def findToInstall(filePath, level): 
     
    for item in os.listdir(filePath): 
        print(item + '\n'); 
        curItem = filePath + '/' + item 
        if os.path.isdir(curItem): 
            print("Enter folder: " + curItem); 
            findToInstall(curItem, level + 1) 
        elif os.path.isfile(curItem): 
            if (".apk" == os.path.splitext(item)[1]): 
                print("installing " + item + "……"); 
                os.system("sudo adb install " + curItem.replace(" ", "\ "));  
     
 
if __name__ == "__main__": 
 
    print ("Start install>>>>>>>>>>>>>>>>>>>\n"); 
 
    findToInstall(PATH, 0) 
 
    print ("Install Finished>>>>>>>>>>>>>>>>>>>\n"); 
 
     

4.運行腳本:$sudo python findAndInstall.py

摘自 herbert的知識庫

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。