diff options
author | Luca Weiss <luca@z3ntu.xyz> | 2019-08-17 23:25:32 +0200 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2019-08-29 11:06:11 +1000 |
commit | 95ce19c14064170e2a3998e487892f07fc5cbdac (patch) | |
tree | 90d9bde4816f474b281dc397c36fb97bc016fb68 /README | |
parent | 5345db19f615b9147b3d0d8e04e83767b7457e92 (diff) | |
download | dtc-95ce19c14064170e2a3998e487892f07fc5cbdac.zip dtc-95ce19c14064170e2a3998e487892f07fc5cbdac.tar.gz dtc-95ce19c14064170e2a3998e487892f07fc5cbdac.tar.bz2 |
README: update for Python 3
Convert the usage to be compatible with Python 3 and the current API.
Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
Message-Id: <20190817212532.15661-2-luca@z3ntu.xyz>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'README')
-rw-r--r-- | README | 26 |
1 files changed, 12 insertions, 14 deletions
@@ -14,45 +14,43 @@ Python library A Python library is also available. To build this you will need to install swig and Python development files. On Debian distributions: - sudo apt-get install swig python-dev + sudo apt-get install swig python3-dev The library provides an Fdt class which you can use like this: -$ PYTHONPATH=../pylibfdt python +$ PYTHONPATH=../pylibfdt python3 >>> import libfdt ->>> fdt = libfdt.Fdt(open('test_tree1.dtb').read()) +>>> fdt = libfdt.Fdt(open('test_tree1.dtb', mode='rb').read()) >>> node = fdt.path_offset('/subnode@1') ->>> print node +>>> print(node) 124 >>> prop_offset = fdt.first_property_offset(node) >>> prop = fdt.get_property_by_offset(prop_offset) ->>> print '%s=%r' % (prop.name, prop.value) -compatible=bytearray(b'subnode1\x00') ->>> print '%s=%s' % (prop.name, prop.value) +>>> print('%s=%s' % (prop.name, prop.as_str())) compatible=subnode1 >>> node2 = fdt.path_offset('/') ->>> print fdt.getprop(node2, 'compatible') +>>> print(fdt.getprop(node2, 'compatible').as_str()) test_tree1 You will find tests in tests/pylibfdt_tests.py showing how to use each method. Help is available using the Python help command, e.g.: $ cd pylibfdt - $ python -c "import libfdt; help(libfdt)" + $ python3 -c "import libfdt; help(libfdt)" If you add new features, please check code coverage: - $ sudo apt-get install python-pip python-pytest - $ sudo pip install coverage + $ sudo apt-get install python3-coverage $ cd tests - $ coverage run pylibfdt_tests.py - $ coverage html + # It's just 'coverage' on most other distributions + $ python3-coverage run pylibfdt_tests.py + $ python3-coverage html # Open 'htmlcov/index.html' in your browser To install the library via the normal setup.py method, use: - ./pylibfdt/setup.py [--prefix=/path/to/install_dir] + ./pylibfdt/setup.py install [--prefix=/path/to/install_dir] If --prefix is not provided, the default prefix is used, typically '/usr' or '/usr/local'. See Python's distutils documentation for details. You can |