From 95ce19c14064170e2a3998e487892f07fc5cbdac Mon Sep 17 00:00:00 2001 From: Luca Weiss Date: Sat, 17 Aug 2019 23:25:32 +0200 Subject: README: update for Python 3 Convert the usage to be compatible with Python 3 and the current API. Signed-off-by: Luca Weiss Message-Id: <20190817212532.15661-2-luca@z3ntu.xyz> Reviewed-by: Simon Glass Signed-off-by: David Gibson --- README | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'README') diff --git a/README b/README index 15232ab..9465ee5 100644 --- a/README +++ b/README @@ -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 -- cgit v1.1