]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
python: installation of binding via make install
authorEric Leblond <eric@regit.org>
Tue, 19 Jun 2018 21:46:53 +0000 (23:46 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 20 Jun 2018 11:51:41 +0000 (13:51 +0200)
setup.py is used to build and install the python binding. Call
to setup.py are done in Makefile to proceed to build and
installation.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Makefile.am
configure.ac
py/.gitignore
py/Makefile.am [new file with mode: 0644]
py/__init__.py [new file with mode: 0644]
py/nftables.py
py/setup.py [new file with mode: 0755]

index 09664c3ecda6e7b8fe935a479463821be215e602..e567d32da9832d5dcdca197023cf8b163c3491cf 100644 (file)
@@ -3,7 +3,8 @@ ACLOCAL_AMFLAGS = -I m4
 SUBDIRS =      src     \
                include \
                files   \
-               doc
+               doc             \
+               py
 
 EXTRA_DIST =   tests   \
                files
index 9f5d0f9a4236530d43f670ed2c1fa5fce323babd..b1a790d0e78d0d3b938579badf78839e75a036e2 100644 (file)
@@ -125,6 +125,22 @@ AC_DEFINE([HAVE_LIBJANSSON], [1], [Define if you have libjansson])
 AC_SUBST(with_json)
 AM_CONDITIONAL([BUILD_JSON], [test "x$with_json" != xno])
 
+AC_ARG_ENABLE(python,
+       AS_HELP_STRING([--enable-python], [Enable python]),,[enable_python=check]
+       )
+
+AC_ARG_WITH([python_bin],
+            [AS_HELP_STRING([--with-python-bin], [Specify Python binary to use])],
+           [PYTHON_BIN="$withval"], [AC_PATH_PROGS(PYTHON_BIN, python python2 python2.7)]
+          )
+
+AS_IF([test "x$PYTHON_BIN" == "x"], [
+       AS_IF([test "x$enable_python" == "xyes"], [AC_MSG_ERROR([Python asked but not found])])
+       AS_IF([test "x$enable_python" == "xcheck"], [AC_MSG_WARN([Python not found, continuing anyway])])
+       ])
+
+AM_CONDITIONAL([HAVE_PYTHON], [test "x$PYTHON_BIN" != "x"])
+
 AC_CONFIG_FILES([                                      \
                Makefile                                \
                libnftables.pc                          \
@@ -140,6 +156,7 @@ AC_CONFIG_FILES([                                   \
                files/Makefile                          \
                files/nftables/Makefile                 \
                doc/Makefile                            \
+               py/Makefile                             \
                ])
 AC_OUTPUT
 
@@ -152,3 +169,10 @@ nft configuration:
   enable pdf documentation:    ${enable_pdf_doc}
   libxtables support:          ${with_libxtables}
   json output support:          ${with_json}"
+
+AS_IF([test "x$PYTHON_BIN" != "x"], [
+       echo "  enable Python:          yes (with $PYTHON_BIN)"
+       ], [
+       echo "  enable Python:          no"
+       ]
+       )
index 0d20b6487c61e7d1bde93acf4a14b7a89083a16d..09c1e62bbd1285295012cfdf13a21c39c89d37f7 100644 (file)
@@ -1 +1,5 @@
 *.pyc
+build/
+dist/
+lib.*/
+nftables.egg-info/
diff --git a/py/Makefile.am b/py/Makefile.am
new file mode 100644 (file)
index 0000000..0963535
--- /dev/null
@@ -0,0 +1,31 @@
+EXTRA_DIST = setup.py __init__.py nftables.py
+
+if HAVE_PYTHON
+
+all-local:
+       cd $(srcdir) && \
+               $(PYTHON_BIN) setup.py build --build-base $(abs_builddir)
+
+install-exec-local:
+       cd $(srcdir) && \
+               $(PYTHON_BIN) setup.py build --build-base $(abs_builddir) \
+               install --prefix $(DESTDIR)$(prefix)
+
+uninstall-local:
+       rm -rf $(DESTDIR)$(prefix)/lib*/python*/site-packages/nftables
+       rm -rf $(DESTDIR)$(prefix)/lib*/python*/dist-packages/nftables
+       rm -rf $(DESTDIR)$(prefix)/lib*/python*/site-packages/nftables-[0-9]*.egg-info
+       rm -rf $(DESTDIR)$(prefix)/lib*/python*/dist-packages/nftables-[0-9]*.egg-info
+       rm -rf $(DESTDIR)$(prefix)/lib*/python*/site-packages/nftables-[0-9]*.egg
+       rm -rf $(DESTDIR)$(prefix)/lib*/python*/dist-packages/nftables-[0-9]*.egg
+
+clean-local:
+       cd $(srcdir) && \
+               $(PYTHON_BIN) setup.py clean \
+               --build-base $(abs_builddir)
+       rm -rf scripts-* lib* build dist bdist.* nftables.egg-info
+       find . -name \*.pyc -print0 | xargs -0 rm -f
+
+distclean-local:
+       rm -f version
+endif
diff --git a/py/__init__.py b/py/__init__.py
new file mode 100644 (file)
index 0000000..7567f09
--- /dev/null
@@ -0,0 +1 @@
+from .nftables import *
index e6e66fb776be72701de288310e3c473baa458c99..d6135054e4b320f54176a107b4037041b9e85db9 100644 (file)
@@ -2,6 +2,8 @@ import json
 from ctypes import *
 import sys
 
+NFTABLES_VERSION = "0.1"
+
 class Nftables:
     """A class representing libnftables interface"""
 
diff --git a/py/setup.py b/py/setup.py
new file mode 100755 (executable)
index 0000000..ef143c4
--- /dev/null
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+from distutils.core import setup
+from nftables import NFTABLES_VERSION
+
+setup(name='nftables',
+      version=NFTABLES_VERSION,
+      description='Libnftables binding',
+      author='Netfilter project',
+      author_email='coreteam@netfilter.org',
+      url='https://netfilter.org/projects/nftables/index.html',
+      packages=['nftables'],
+      provides=['nftables'],
+      package_dir={'nftables':'.'},
+      classifiers=[
+          'Development Status :: 4 - Beta',
+          'Environment :: Console',
+          'Intended Audience :: Developers',
+          'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
+          'Operating System :: POSIX :: Linux',
+          'Programming Language :: Python',
+          'Topic :: System :: Networking :: Firewalls',
+          ],
+      )