Synchronous Python client for OpenHarmony Device Connector (HDC)
Project description
hdctool
Python 实现的 HDC(Harmony Device Connector) 同步客户端,用于列举设备、Shell、端口转发、安装包、UiDriver(Hypium/uitest) 等。
安装
pip install -e .
开发依赖:pip install -e ".[dev]"
用法
import hdctool
client = hdctool.create_client()
for key in client.list_targets():
t = client.get_target(key)
print(t.get_parameters().get("const.product.name"))
纯 HDC(子进程,不经由 TCP 会话)
适合简单 shell、与现有 Target.shell(长连接)互补:
out = t.hdc_shell("param get const.product.name")
raw = t.hdc(["shell", "whoami"])
不带 -t 的全局命令:
client.hdc(["list", "targets"])
超时与异常
create_client 支持关键字参数:
connect_timeout:连接本机 HDC 端口超时(秒,默认30)read_timeout:已连接套接字读超时;None表示阻塞(默认None,适合大体积 shell 输出)hdc_subprocess_timeout:hdcCLI 子进程默认超时(默认120,可为None表示不设限)
失败时可能抛出 hdctool.HdcTcpError、HdcHandshakeError、HdcSubprocessError 等,异常对象带 context 字典便于记录。
日志
设置环境变量 HDCTOOL_LOG_LEVEL=DEBUG(或 INFO 等)后,包内使用 logging.getLogger("hdctool") 的日志会按级别输出;也可在代码中调用 hdctool.configure_logging()。
UiDriver 子系统
UiDriver 提供属性:gestures、app_manager、screen、storage、system、hilog、uinput(手势/键鼠/表冠、应用与包信息、亮灭屏与录屏、文件 push/pull、系统参数、hilog 监听、按键注入等)。未封装的设备侧能力可用 call_driver / call_rpc。实现见 src/hdctool/ui/subsystems.py。
示例脚本见 examples/hdc_demo.py。
布局(src)
src/hdctool/— 包根,py.typed标明支持类型检查src/hdctool/uitestkit_sdk/— uitest agent(uitest_agent_*.so)随仓库提交,供UiDriver推送到设备;若克隆后缺失请从本地 Harmony/OpenHarmony uitest 工具链拷贝同名文件examples/— 可运行示例tests/— pytest.github/workflows/ci.yml— CI(Ruff + pytest,Ubuntu / Windows × Python 3.10–3.12)
版本与变更
hdctool.__version__ 与 pyproject.toml 中 [project].version 一致。用户可见变更见根目录 CHANGELOG.md。维护者发布流程见 RELEASING.md。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hdctool-0.4.2.tar.gz.
File metadata
- Download URL: hdctool-0.4.2.tar.gz
- Upload date:
- Size: 397.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebb47ead39fe9fbf35782efdef04a62a201e59123c19a95c72b3e7d88075933f
|
|
| MD5 |
65ee8cf2e4f1a7c70af6103d6e24034b
|
|
| BLAKE2b-256 |
3c4170c90b4ce79e867f8aa0726770a021d471eda9b84d5021faec8ee4e0caae
|
File details
Details for the file hdctool-0.4.2-py3-none-any.whl.
File metadata
- Download URL: hdctool-0.4.2-py3-none-any.whl
- Upload date:
- Size: 402.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afb60240423be2ebe9da505e23ef396bf33f90e8de1ff62c548c6596f0109f11
|
|
| MD5 |
6ed18e92e90ef938b0a70c8d256add68
|
|
| BLAKE2b-256 |
3c7b86a7a17f0641f69fa3168f6ed6d596eefc43899194985c2752d596204e83
|