Initial import for the Python bindings (incomplete)
This commit is contained in:
parent
593664b7da
commit
7d823fc736
4
Makefile
4
Makefile
|
@ -45,6 +45,10 @@ dist:
|
|||
$(PACKAGE)-$(VERSION)/include/Database/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/src/database.c \
|
||||
$(PACKAGE)-$(VERSION)/src/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/src/python/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/src/python/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/src/python/libDatabase.c \
|
||||
$(PACKAGE)-$(VERSION)/src/python/libDatabase.py \
|
||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/src/engines/pdo.c \
|
||||
$(PACKAGE)-$(VERSION)/src/engines/pgsql.c \
|
||||
|
|
|
@ -3,7 +3,7 @@ targets=libDatabase
|
|||
cppflags_force=-I ../include
|
||||
cflags_force=-W -fPIC
|
||||
cflags=-Wall -g -O2 -pedantic
|
||||
dist=Makefile
|
||||
dist=Makefile,python/project.conf,python/Makefile,python/libDatabase.c,python/libDatabase.py
|
||||
|
||||
[libDatabase]
|
||||
type=library
|
||||
|
|
52
src/python/Makefile
Normal file
52
src/python/Makefile
Normal file
|
@ -0,0 +1,52 @@
|
|||
MKDIR = mkdir -m 0755 -p
|
||||
INSTALL = install
|
||||
RM = rm -f
|
||||
TARGETS = _libDatabase.so
|
||||
PREFIX = /usr/local
|
||||
DESTDIR =
|
||||
LIBDIR = $(PREFIX)/lib
|
||||
CC = cc
|
||||
CPPFLAGSF= -I ../../include
|
||||
CPPFLAGS=
|
||||
CFLAGSF = -W `pkg-config --cflags python-2.7 libDatabase` -fPIC
|
||||
CFLAGS = -Wall -g -O2
|
||||
LDFLAGSF= `pkg-config --libs python-2.7 libDatabase`
|
||||
LDFLAGS = -L.. -L$(LIBDIR) -Wl,-rpath,$(LIBDIR)
|
||||
AR = ar
|
||||
RANLIB = ranlib
|
||||
CCSHARED= $(CC) -shared
|
||||
RM = rm -f
|
||||
LN = ln -f
|
||||
MKDIR = mkdir -m 0755 -p
|
||||
INSTALL = install
|
||||
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
_libDatabase_OBJS = libDatabase.o
|
||||
_libDatabase_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
_libDatabase_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
|
||||
_libDatabase.so: $(_libDatabase_OBJS)
|
||||
$(CCSHARED) -o _libDatabase.so $(_libDatabase_OBJS) $(_libDatabase_LDFLAGS)
|
||||
|
||||
libDatabase.o: libDatabase.c
|
||||
$(CC) $(_libDatabase_CFLAGS) -c libDatabase.c
|
||||
|
||||
clean:
|
||||
$(RM) -- $(_libDatabase_OBJS)
|
||||
|
||||
distclean: clean
|
||||
$(RM) -- $(TARGETS)
|
||||
|
||||
install: $(TARGETS)
|
||||
$(MKDIR) $(DESTDIR)$(PREFIX)/lib/python2.7/site-packages
|
||||
$(INSTALL) -m 0644 -- _libDatabase.so $(DESTDIR)$(PREFIX)/lib/python2.7/site-packages/_libDatabase.so
|
||||
$(MKDIR) $(DESTDIR)$(PREFIX)/lib/python2.7/site-packages
|
||||
$(INSTALL) -m 0644 -- libDatabase.py $(DESTDIR)$(PREFIX)/lib/python2.7/site-packages/libDatabase.py
|
||||
|
||||
uninstall:
|
||||
$(RM) -- $(DESTDIR)$(PREFIX)/lib/python2.7/site-packages/_libDatabase.so
|
||||
$(RM) -- $(DESTDIR)$(PREFIX)/lib/python2.7/site-packages/libDatabase.py
|
||||
|
||||
.PHONY: all clean distclean install uninstall
|
85
src/python/libDatabase.c
Normal file
85
src/python/libDatabase.c
Normal file
|
@ -0,0 +1,85 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2013 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Database libDatabase */
|
||||
/* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
|
||||
#include <Python.h>
|
||||
#include "Database.h"
|
||||
|
||||
|
||||
/* libDatabase */
|
||||
/* private */
|
||||
/* constants */
|
||||
static char const _libdatabase_database_name[] = "libDatabase::Database";
|
||||
|
||||
|
||||
/* prototypes */
|
||||
/* Database */
|
||||
static PyObject * _libdatabase_database_new(PyObject * self, PyObject * args);
|
||||
static void _libdatabase_database_delete(PyObject * self);
|
||||
|
||||
|
||||
/* variables */
|
||||
static PyMethodDef _libdatabase_methods[] =
|
||||
{
|
||||
{ "database_new", _libdatabase_database_new, METH_VARARGS,
|
||||
"Instantiates a Database object." },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
|
||||
/* public */
|
||||
/* prototypes */
|
||||
PyMODINIT_FUNC init_libDatabase(void);
|
||||
|
||||
|
||||
/* functions */
|
||||
/* init_libDatabase */
|
||||
PyMODINIT_FUNC init_libDatabase(void)
|
||||
{
|
||||
Py_InitModule("_libDatabase", _libdatabase_methods);
|
||||
}
|
||||
|
||||
|
||||
/* private */
|
||||
/* functions */
|
||||
/* Database */
|
||||
/* libdatabase_database_new */
|
||||
static PyObject * _libdatabase_database_new(PyObject * self, PyObject * args)
|
||||
{
|
||||
Database * database;
|
||||
char const * engine;
|
||||
char const * section;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "ss", &engine, §ion))
|
||||
return NULL;
|
||||
/* FIXME obtain the Config object */
|
||||
if((database = database_new(engine, config_new(), section)) == NULL)
|
||||
return NULL;
|
||||
return PyCapsule_New(database, _libdatabase_database_name,
|
||||
_libdatabase_database_delete);
|
||||
}
|
||||
|
||||
|
||||
/* libdatabase_database_delete */
|
||||
static void _libdatabase_database_delete(PyObject * self)
|
||||
{
|
||||
Database * database;
|
||||
|
||||
if((database = PyCapsule_GetPointer(self, _libdatabase_database_name))
|
||||
== NULL)
|
||||
return;
|
||||
database_delete(database);
|
||||
}
|
25
src/python/libDatabase.py
Normal file
25
src/python/libDatabase.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python2.7
|
||||
#$Id$
|
||||
#Copyright (c) 2013 Pierre Pronchery <khorben@defora.org>
|
||||
#This file is part of DeforaOS Database libDatabase
|
||||
#This program is free software: you can redistribute it and/or modify
|
||||
#it under the terms of the GNU Lesser General Public License as published by
|
||||
#the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
#This program is distributed in the hope that it will be useful,
|
||||
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
#GNU Lesser General Public License for more details.
|
||||
#
|
||||
#You should have received a copy of the GNU Lesser General Public License
|
||||
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
import _libDatabase
|
||||
|
||||
|
||||
#Database
|
||||
class Database:
|
||||
def __init__(self, engine, section):
|
||||
self.database = _libDatabase.database_new(engine, section)
|
15
src/python/project.conf
Normal file
15
src/python/project.conf
Normal file
|
@ -0,0 +1,15 @@
|
|||
targets=_libDatabase
|
||||
cppflags_force=-I ../../include
|
||||
cflags_force=-W `pkg-config --cflags python-2.7 libDatabase` -fPIC
|
||||
cflags=-Wall -g -O2
|
||||
ldflags_force=`pkg-config --libs python-2.7 libDatabase`
|
||||
ldflags=-L.. -L$(LIBDIR) -Wl,-rpath,$(LIBDIR)
|
||||
dist=Makefile,libDatabase.py
|
||||
|
||||
[_libDatabase]
|
||||
type=plugin
|
||||
sources=libDatabase.c
|
||||
install=$(PREFIX)/lib/python2.7/site-packages
|
||||
|
||||
[libDatabase.py]
|
||||
install=$(PREFIX)/lib/python2.7/site-packages
|
Loading…
Reference in New Issue
Block a user