一、adb 设备命令
1、查看机型时,可以使用以下命令
$ adb shell getprop ro.product.model

2.如果我们忘记具体系统属性的名字
$ adb shell getprop | grep product

3.获取设备号
$ adb shell getprop ro.serialno

4.我们还可以通过 adb devices 命令来查看设备信息:
$ adb devices
查看型号等详细信息使用以下命令
$ adb devices -l

二、
#获取手机名称 NAME = 'adb shell getprop ro.product.model'
#获取手机版本 VERSION = 'adb shell getprop ro.build.version.release'
#获取手机厂商 PRODUCER = 'adb shell getprop ro.product.brand'

获取以上信息python代码:

 import os
deviceName = os.popen('adb shell getprop ro.product.model').read()
print(deviceName)
platformVersion = os.popen('adb shell getprop ro.build.version.release').read() print(platformVersion)
device = os.popen('adb shell getprop ro.product.name ').read()
print(device)

三、获取多个设备号
直接上代码:

 #coding=utf-8
import re
import os #获取设备多台设备号列表
def get_deviceid():
str_init=' '
all_info= os.popen('adb devices').readlines()
print('adb devices 输出的内容是:',all_info) for i in range(len(all_info)):
str_init+=all_info[i]
devices_name=re.findall('\n(.+?)\t',str_init,re.S) print('所有设备名称:\n',devices_name)
return devices_name r=get_deviceid()
print(r[0])

四、---待完善
1、需求
最近需要给多台pad安装apk包,但是之前的串形脚本,一台pad装一个apk需要1分钟,80台就需要80分钟,于是乎我考虑能不能让任务池进行批量并行安装apk。

2、实现思路:
想到使用多进程的方式即使用python的pool.map方法,给每个任务池分配任务,起多任务池并行处理任务,废话不多说,
直接上代码:
#!/usr/bin/env python
# -*- encoding: utf-8
-*- import os
import time
from multiprocessing
import Pool
list=[]

def getDevicesAll():
    #获取devices数量和名称
    devices = []
    try:
        for dName_ in os.popen("adb devices"):
            if "\t" in dName_:
                if dName_.find("emulator") < 0:
                    devices.append(dName_.split("\t")[0])
        devices.sort(cmp=None, key=None, reverse=False)
        print(devices)
    except:
        pass
    print(u"\n设备名称: %s \n总数量:%s台" % (devices, len(devices)))
    return devices

def quickinstall(device):    
    #卸载原有apk
    try:
        os.system('adb -s ' + device + ' uninstall 包名')
        os.system('adb -s ' + device + ' uninstall 包名')
    except:
        print(device + "卸载失败\n")
    print(device + "卸载成功\n")
    try:
        for i in list:
            os.system('adb -s ' + device + ' install ' + i)
    except:
        print(device + "安装失败\n")
    print(device + "安装成功\n")

def qainstall(devices):
    starttime=time.time()
    pool = Pool(8) #创建8个任务池
    result=pool.map(quickinstall,devices)
    endtime=time.time()
    pool.close()
    pool.join()
    print(endtime-starttime) #打印时间
    
if __name__ == "__main__":
    filesname = '/Users/用户名/Desktop/package'    
    #获取安装包
    for parent, dirnames, filnames in os.walk(filesname):
        for filname in filnames:
            path = os.path.join(parent, filname)
            list.append(path)
    try:
        devices = getDevicesAll()
    except:
        print("获取设备出错")
    res = input("输入1开始更新:")
    if int(res) == 1:
        try:
            qainstall(devices)
    except:
        print("更新失败")
    Touch(devices)

最新文章

  1. Linux 下 查看以及修改文件权限
  2. WPF Datagrid删除一行
  3. js判断浏览器
  4. Working with Transactions (EF6 Onwards)
  5. Linux 下WordPress FTP帐号解决办法
  6. 微软职位内部推荐-Senior Software Development Engineer
  7. MYSQL主从不同步延迟原理
  8. Javascript 正确用法 二
  9. Preemption Context Switches 和 Synchronization Context Switches
  10. django开发者模式中的autoreload是怎样实现的
  11. HBase压缩
  12. 【Qt编程】基于Qt的词典开发系列&lt;十三&gt;音频播放
  13. angular Observable
  14. centos 下使用vscode 调试egg.js 注意事项
  15. C-Lodop打印服务没启动怎么办
  16. vue 关于生命周期
  17. hdu1171 Big Event in HDU(多重背包)
  18. luogu2024 食物链 (并查集)
  19. Django项目----快速实现增删改查组件(起步阶段!!!)
  20. 使用DateTime的ParseExact方法实现特殊日期时间的方法详解(转)

热门文章

  1. python编写猜拳代码
  2. 小程序-demo:妹纸图
  3. Navicat: Can&#39;t create a procedure from within another stored routine
  4. 数据库无法访问,用户 NT AUTHORITY/SYSTEM或NT AUTHORITY\NETWORK SERVICE登录失败的解决办法
  5. mybatis基础学习4-插件生成器(根据数据库的表生成文件)
  6. python 闭包 Closure 函数作为返回值
  7. 用set和shopt设置bash选项
  8. Spring AOP 面向切面编程入门
  9. LuoguP1314 聪明的质检员 【二分答案/前缀和】
  10. windows API普通函数跟回调函数有何区别