安装当前目录下所有apk 的脚本(python2.x)

来源:互联网 发布:c语言九九乘法表的输出 编辑:程序博客网 时间:2024/06/07 22:52

今天要安装几十个apk,就写了个脚本,递归查找当前目录下所有的apk文件,找到一个安装一个。

安装环境:ubuntu10.04LTS + python2.6.5

1. 打开android设备“USB调试”

2. 重启ADB: $sudo adb kill-server

                          $sudo adb start-server

3写脚本findAndInstall.py

#-*- 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 osPATH = "./"   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


原创粉丝点击