Skip to content

Pure python hdc library for harmony hdc service. Support querying hdc cmd and doc via adb cmd

License

Notifications You must be signed in to change notification settings

lanbaoshen/hdcutils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HDC Utils

Pure python hdc library for harmony hdc service.

Support querying corresponding hdc commands and documentation via adb command.

Screenshot 2025-07-09 at 17 02 36

Requires

  • Python 3.10+
  • hdc
Install hdc without DevEco Studio
  1. Find command-line-tools in Download Center, and choose a release version to download. If the path is zh, you need to log in to your Huawei account first.
  2. Unzip the downloaded file to a directory, e.g ~/Library/Harmony/command-line-tools
  3. Set environment variable like:
export HARMONY_HOME=~/Library/Harmony
export PATH=${HARMONY_HOME}/command-line-tools/bin:${HARMONY_HOME}/command-line-tools/sdk/default/openharmony/toolchains:${PATH}
  1. Run hdc command to check if it works:
hdc checkserver
# Client version:Ver: 3.1.0e, server version:Ver: 3.1.0e

Install

pip3 install hdcutils

Usage

Search method & doc via adb command

from hdcutils import adb_mapping
result = adb_mapping.search_cmd(cmd='adb logcat -c')
print(result['example'])  # HDCClient().device().hilog.remove_buffer_log
print(result['doc'])  # https://developer.huawei.com/consumer/en/doc/harmonyos-guides/hilog#clearing-the-log-buffer

# Print full mapping
print(adb_mapping.mapping)

List all the devices and get device object

from hdcutils import HDCClient

# hdc = HDCClient(hdc='/path/to/hdc')
# If you don't set `hdc` path, it will try to find it in $PATH.
hdc = HDCClient()
for target in hdc.list_targets():
    d = hdc.device(connect_key=target)

Run shell command

from hdcutils import HDCClient
hdc = HDCClient()
# d = hdc.device(connect_key='device_connect_key')
# If you only have one device, you can use `hdc.device()` without arguments.
d = hdc.device()
out, err = d.shell(['echo', 'Hello World!'])
print(out)

Restart and wait for the reboot to complete

from hdcutils import HDCClient

d = HDCClient().device()
d.boot()
d.wait()
d.param.wait('bootevent.boot.completed', 'true')

License

Licensed under MIT - see LICENSE file. This is not an official Harmony product.

About

Pure python hdc library for harmony hdc service. Support querying hdc cmd and doc via adb cmd

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages