Browse Source

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>
main
Luca Weiss 5 years ago committed by David Gibson
parent
commit
95ce19c140
  1. 26
      README

26
README

@ -14,45 +14,43 @@ Python library @@ -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

Loading…
Cancel
Save