diff --git a/python/Makefile.am b/python/Makefile.am index d835312524c0199ae83e82852fae9b9811f274c1..7346416e14763e52d66c5955d61e2e3520f2b66e 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -2,6 +2,7 @@ EXTRA_DIST = \ libknot/__init__.py.in \ libknot/control.py \ libknot/probe.py \ + README.md \ setup.py.in clean-local: diff --git a/python/README.md b/python/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9339f37d1811fe95b317ce7c69bc76fbc0763d73 --- /dev/null +++ b/python/README.md @@ -0,0 +1,52 @@ +# Libknot API in Python + +## Control API + +Example: + +```python3 +import json +import libknot.control + +#import libknot +#libknot.Knot("/usr/lib/libknot.so") + +ctl = libknot.control.KnotCtl() +ctl.connect("/var/run/knot/knot.sock") + +try: + ctl.send_block(cmd="conf-begin") + resp = ctl.receive_block() + + ctl.send_block(cmd="conf-set", section="zone", item="domain", data="test") + resp = ctl.receive_block() + + ctl.send_block(cmd="conf-commit") + resp = ctl.receive_block() + + ctl.send_block(cmd="conf-read", section="zone", item="domain") + resp = ctl.receive_block() + print(json.dumps(resp, indent=4)) +finally: + ctl.send(libknot.control.KnotCtlType.END) + ctl.close() +``` + +## Probe API + +Example: + +```python3 +import libknot.probe + +#import libknot +#libknot.Knot("/usr/lib/libknot.so") + +probe = libknot.probe.KnotProbe("/run/knot") + +data = libknot.probe.KnotProbeDataArray(8) +while (True): + if probe.consume(data) > 0: + for item in data: + print(item) +``` diff --git a/python/libknot/control.py b/python/libknot/control.py index b618bca1f8641cd85e4986ff1a72f3df5f55de32..48f49d424181d735e741ccf3c255a53308ac535c 100644 --- a/python/libknot/control.py +++ b/python/libknot/control.py @@ -1,33 +1,4 @@ -"""Libknot server control interface wrapper. - -## Example ## - -import json -import libknot.control - -#import libknot -#libknot.Knot("/usr/lib/libknot.so") - -ctl = libknot.control.KnotCtl() -ctl.connect("/var/run/knot/knot.sock") - -try: - ctl.send_block(cmd="conf-begin") - resp = ctl.receive_block() - - ctl.send_block(cmd="conf-set", section="zone", item="domain", data="test") - resp = ctl.receive_block() - - ctl.send_block(cmd="conf-commit") - resp = ctl.receive_block() - - ctl.send_block(cmd="conf-read", section="zone", item="domain") - resp = ctl.receive_block() - print(json.dumps(resp, indent=4)) -finally: - ctl.send(libknot.control.KnotCtlType.END) - ctl.close() -""" +"""Libknot server control interface wrapper.""" import ctypes import enum diff --git a/python/libknot/probe.py b/python/libknot/probe.py index 5ad88978b798e4c2adcd78c2984fb463ee7ac1e7..08565cd866133355816ed98705874dc1903e5916 100644 --- a/python/libknot/probe.py +++ b/python/libknot/probe.py @@ -1,20 +1,4 @@ -"""Libknot probe interface wrapper. - -## Example ## - -import libknot.probe - -#import libknot -#libknot.Knot("/usr/lib/libknot.so") - -probe = libknot.probe.KnotProbe("/run/knot") - -data = libknot.probe.KnotProbeDataArray(8) -while (True): - if probe.consume(data) > 0: - for item in data: - print(item) -""" +"""Libknot probe interface wrapper.""" import ctypes import enum diff --git a/python/setup.py.in b/python/setup.py.in index d40702e6971d041ca22b0c221754a25abc0a9025..7316247de6cb748405dc6122d725ef6398fbccc7 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -1,19 +1,25 @@ +import os +import pathlib import setuptools -from os import path -here = path.dirname (path.realpath (__file__)) +here = os.path.dirname(os.path.realpath (__file__)) + +p = pathlib.Path("README.md") +if p.exists(): + long_description = p.read_text() setuptools.setup( name='libknot', version='@PACKAGE_VERSION@', description='Python bindings for libknot', + long_description=long_description, author='Daniel Salzman', author_email='daniel.salzman@nic.cz', url='https://gitlab.nic.cz/knot/knot-dns', license='GPL-3.0', packages=['libknot'], package_dir = { - 'libknot': path.join (here, 'libknot'), + 'libknot': os.path.join(here, 'libknot'), }, classifiers=[ # See https://pypi.org/classifiers 'Development Status :: 5 - Production/Stable',