pure-python-adb
源码地址:https://github.com/Swind/pure-python-adb
问题:使用python 操作adb,上传文件,安装apk等。
#!/bin/bash
path=`pwd`
echo $path
adb_kill=`adb kill-server`
echo $adb_kill
adb_start=`adb start-server`
echo $adb_start
adb_connect=`adb connect 10.19.108.226:12345`
echo $adb_connect
adb_connect=`adb connect 10.19.108.226:12345``
echo $adb_connect
adb_devices=`adb devices`
echo $adb_devices
echo adb install /Users/demo/apkpath
adb push /Users/demo/somefind.dex /data/local/tmp
adb_forward_27042=`adb forward tcp:27042 tcp:27042`
echo $adb_forward_27042
adb_forward_27043=`adb forward tcp:27043 tcp:27043`
echo $adb_forward_27043
# adbshell=`adb shell `
echo $adbshell
以上这种方式使用python调用shell脚本,太麻烦了。
解决方式:使用pure-python-adb来构建对adb命令的集成。
from ppadb.client import Client as AdbClient
client = AdbClient(host="127.0.0.1", port=5037)
client.remote_connect("10.19.108.226", 12345)
device = client.device("110.19.108.226:12345")
# 检查对应的okhttpfind.dex是否存在
result = device.shell("ls /data/local/tmp")
if 'somefind.dex' in result:
print('somefind.dex exist')
else:
result = device.push("/Users/demo/Downloads/somefind.dex", "/data/local/tmp/somefind.dex",progress=show_progress)
bInstall = device.is_installed('apk file path ')
if bInstall == False:
print('start install apk')
result = device.install(apk file path')
else:
print('apk already installed')
网友评论