From: Arvin Schnell Date: Tue, 13 Sep 2011 14:07:26 +0000 (+0200) Subject: - framework for swig python bindings X-Git-Tag: v0.1.3~298 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=d6e35e443eeb641545a142c0f28b035da5b7d783;p=thirdparty%2Fsnapper.git - framework for swig python bindings --- diff --git a/bindings/Makefile.am b/bindings/Makefile.am new file mode 100644 index 00000000..25b67293 --- /dev/null +++ b/bindings/Makefile.am @@ -0,0 +1,5 @@ +# +# Makefile.am for libsnapper/bindings +# + +SUBDIRS = python diff --git a/bindings/python/.gitignore b/bindings/python/.gitignore new file mode 100644 index 00000000..67a51328 --- /dev/null +++ b/bindings/python/.gitignore @@ -0,0 +1,3 @@ +libsnapper.py +libsnapper_wrap.* +_libsnapper* diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am new file mode 100644 index 00000000..18d4ef39 --- /dev/null +++ b/bindings/python/Makefile.am @@ -0,0 +1,39 @@ +# +# Makefile.am for libsnapper/bindings/python +# + +EXTRA_DIST = libsnapper.i + +AM_CXXFLAGS = -fPIC -DPIC + +PYLIBVER ?= python$(PYTHON_VERSION) + +INCLUDES = -I. -I${top_srcdir} -I/usr/include/$(PYLIBVER) + +DEPENDENCIES = \ + ${top_srcdir}/snapper/Factory.h \ + ${top_srcdir}/snapper/Snapper.h \ + ${top_srcdir}/snapper/Snapshot.h \ + ${top_srcdir}/snapper/File.h \ + ${top_srcdir}/snapper/Comparison.h \ + ${top_srcdir}/snapper/Exception.h + +LIBS = $(top_builddir)/snapper/libsnapper.la + +python_PYTHON = libsnapper.py + +pyexec_LTLIBRARIES = _libsnapper.la + +_libsnapper_la_LDFLAGS = -module -avoid-version +_libsnapper_la_HEADERS: $(top_builddir)/config.h + +_libsnapper_la_DEPENDENCIES = \ + $(DEPENDENCIES) \ + ${top_builddir}/snapper/libsnapper.la + +nodist__libsnapper_la_SOURCES = libsnapper_wrap.cxx + +libsnapper.py libsnapper_wrap.cxx: libsnapper.i $(DEPENDENCIES) + swig -o libsnapper_wrap.cxx -c++ -python ${INCLUDES} libsnapper.i + +CLEANFILES = libsnapper.py libsnapper_wrap.cxx diff --git a/bindings/python/examples/create.py b/bindings/python/examples/create.py new file mode 100755 index 00000000..2cabdcd0 --- /dev/null +++ b/bindings/python/examples/create.py @@ -0,0 +1,11 @@ +#!/usr/bin/python + +import libsnapper + + +sh = libsnapper.createSnapper("root", False) + +sh.createSingleSnapshot("python test") + +libsnapper.deleteSnapper(sh) + diff --git a/bindings/python/libsnapper.i b/bindings/python/libsnapper.i new file mode 100644 index 00000000..b6f69804 --- /dev/null +++ b/bindings/python/libsnapper.i @@ -0,0 +1,38 @@ +// +// Python interface definition for libsnapper +// + +%module libsnapper + +%{ +using namespace std; + +#include +#include +#include +#include +#include +#include +%} + +using namespace std; + +%include "std_string.i" +%include "std_vector.i" +%include "std_list.i" + +%typemap(out) std::string* { + $result = PyString_FromString($1->c_str()); +} + +%include "../../snapper/Factory.h" +%include "../../snapper/Snapshot.h" +%include "../../snapper/Snapper.h" +%include "../../snapper/File.h" +%include "../../snapper/Comparison.h" +%include "../../snapper/Exception.h" + +using namespace snapper; + +%template(vectorstring) vector; + diff --git a/configure.in b/configure.in index 9a2bf7c9..cf6ba0d7 100644 --- a/configure.in +++ b/configure.in @@ -21,6 +21,7 @@ AC_DISABLE_STATIC AC_PROG_CXX AC_PROG_LIBTOOL AM_PROG_LIBTOOL +AM_PATH_PYTHON AC_PREFIX_DEFAULT(/usr)