Wetest USB Tethering
Wetest USB Tethering 用于开启 Android 设备的 USB 共享功能,并进行高速文件下载
- 开启 USB 共享功能:通过 uiautomator2 提供的控件操作能力实现
- 高速文件下载:借助 fastpusher 提供的从任务容器到 Android 设备的文件传输功能
使用指南
安装
支持 Python 3.8 及以上版本
python -m pip install wetest-usb-tethering --upgrade --extra-index-url https://mirrors.tencent.com/repository/pypi/tencent_pypi/simple
快速上手
from wetest.usbtethering import create_device
# 创建设备实例
device = create_device("your_android_serial")
# 检查设备 adb 和 uiautomator2 是否正常工作
assert device.is_connected()
# 开启 USB 共享功能
device.enable_usb_tethering()
# 检查 USB 共享功能是否已开启
assert device.is_usb_tethering_enabled()
# 下载文件到 Android 设备
device_file_path = device.download_file(download_file, "/sdcard/" + download_file)
# 释放设备资源,清理 uiautomator2 和 fastpusher 进程
# 不会自动关闭 USB 共享功能
device.release()
更多示例请参考 examples 目录
版本记录请参考 CHANGELOG.md
原理说明
项目架构
本项目主要包含以下几个核心模块:
src/wetest/usbtethering/
├── device_factory.py # 设备工厂,负责自动识别设备品牌并创建对应实例
├── uiautomator_manager.py # UIAutomator 管理器,处理设备连接和冲突问题
├── fastpusher_manager.py # fastpusher 管理器,管理 fastpusher 进程的启动和停止
└── devices/
├── base.py # 设备基类,定义开启 USB 共享功能的通用接口
└── ... # 其他设备类,实现各自品牌的 USB 共享功能开启逻辑
└── resources/
├── fastpusher_linux_x86_64 # fastpusher 工具,从 https://git.woa.com/CloudTesting/UDT/fastpusher/-/tags 获取
扩展支持
要支持新的设备品牌,只需:
- 在
devices/目录下创建新的设备类,继承BaseDevice,并定义对应的 BRAND_MODELS 常量 - 实现
_toggle_usb_tethering_on和_open_usb_tethering_page(如有必要) ,用于开启 USB 共享功能 - 在
devices/__init__.py中导入新创建的设备类 - 在
device_factory.py中添加新的品牌映射关系到 SUPPORTED_BRANDS 常量
构建流程
构建项目
在 dist/ 目录下生成 wetest-usb-tethering-0.0.x.whl 文件
make build
清理构建产物
删除 dist/ 目录下的所有文件和 src/wetest/usbtethering/resources/fastpusher_linux_x86_64 文件
make clean
作者信息&致谢
Tencent WeTest Team
特别感谢以下开源项目的启发:
Metadata
Release files for wetest-usb-tethering 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wetest_usb_tethering-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for wetest_usb_tethering-0.0.9-py3-none-any.whl |
Release files / wetest_usb_tethering-0.0.9-py3-none-any.whl
| Download URL | wetest_usb_tethering-0.0.9-py3-none-any.whl |
|---|---|
| Size | 3.3 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7dd23baf22f67ad12fce26280a2d51c74e93a2e43b7810d85fecda28fb52e795
|
|
BLAKE2b-256 checksum How to use checksums |
3a178251f032a1f66fc852f767ca754835abcf70a9faf5fbc7f3b5b4b64005e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.23
|
Security for wetest-usb-tethering 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.