bh: thuban/libraries/pyshapelib setup.py, 1.1, 1.2 dbflib_wrap.c, 1.3, 1.4 dbflib.py, 1.2, 1.3 dbflib.i, 1.3, 1.4
cvs@intevation.de
cvs at intevation.de
Mon May 17 17:48:00 CEST 2004
Author: bh
Update of /thubanrepository/thuban/libraries/pyshapelib
In directory doto:/tmp/cvs-serv23933/libraries/pyshapelib
Modified Files:
setup.py dbflib_wrap.c dbflib.py dbflib.i
Log Message:
Update to newest shapelib and get rid of Thuban specific extensions,
i.e. use the new DBFUpdateHeader instead of our DBFCommit kludge
* libraries/shapelib/shpopen.c: Update to version from current
shapelib CVS.
* libraries/shapelib/shapefil.h: Update to version from current
shapelib CVS.
* libraries/shapelib/dbfopen.c: Update to version from current
shapelib CVS.
(DBFCommit): Effectively removed since shapelib itself has
DBFUpdateHeader now which is better for what DBFCommit wanted to
achieve.
We're now using an unmodified version of dbfopen.
* libraries/pyshapelib/dbflib_wrap.c, libraries/pyshapelib/dbflib.py:
Update from dbflib.i
* libraries/pyshapelib/dbflib.i (DBFInfo_commit): New. Implementation of
the commit method. This new indirection is necessary because we use the
DBFUpdateHeader function now which is not available in shapelib <=
1.2.10
(DBFFile::commit): Use DBFInfo_commit as implementation
(pragma __class__): New. Kludge to remove the commit method when
the DBFUpdateHeader function isn't available
(_have_commit): New. Helper for the pragma kludge.
* libraries/pyshapelib/setup.py (dbf_macros): New. Return the
preprocessor macros needed to compile the dbflib wrapper. Determine
whether DBFUpdateHeader is available and define the right value of
HAVE_UPDATE_HEADER
(extensions): Use dbf_macros for the dbflibc extension
* setup.py (extensions): Add the HAVE_UPDATE_HEADER macro with
value '1' to the Lib.dbflibc extension. This simply reflects the
shapelib and pyshapelib updates
Index: setup.py
===================================================================
RCS file: /thubanrepository/thuban/libraries/pyshapelib/setup.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- setup.py 19 Aug 2003 21:24:20 -0000 1.1
+++ setup.py 17 May 2004 15:47:57 -0000 1.2
@@ -1,23 +1,44 @@
import os
from distutils.core import setup, Extension
+from distutils.util import convert_path
# try to determine the directory where the shapelib source files are.
# There are currently two supported situations.
#
# 1. "Standalone" build: the parent directory is the shapelib source
# directory
-# 2. Built in the Thuban source tree where it's ../shapelib/ relative to
-# the directory containing this setup.py
+# 2. Built in the Thuban source tree where ../shapelib/ relative to the
+# directory containing this setup.py contains (the relevant parts of)
+# shapelib
# os.path expects filenames in OS-specific form so we have to construct
# the files with os.path functions. distutils, OTOH, uses posix-style
-# filenames exclusively, so we posix when making filenames for
-# distutils.
-if os.path.exists(os.path.join(os.pardir, "shpeopen.c")):
- shp_dir = ".."
-elif os.path.exists(os.path.join(os.pardir, "shapelib")):
- shp_dir = "../shapelib"
+# filenames exclusively, so we use posix conventions when making
+# filenames for distutils.
+for shp_dir in ["..", "../shapelib"]:
+ if os.path.exists(os.path.join(convert_path(shp_dir), "shpopen.c")):
+ # shp_dir contains shpopen.c, so assume it's the directory with
+ # the shapefile library to use
+ break
+
+def dbf_macros():
+ """Return the macros to define when compiling the dbflib wrapper.
+
+ The returned list specifies one macro, HAVE_UPDATE_HEADER, which is
+ '1' if the dbflib version we will be compiling with has the
+ DBFUpdateHeader function and '0' otherwise. To check whether
+ DBFUpdateHeader is available, we scan shapefil.h for the string
+ 'DBFUpdateHeader'.
+ """
+ f = open(convert_path(shp_dir + "/shapefil.h"))
+ contents = f.read()
+ f.close()
+ print contents.find("DBFUpdateHeader")
+ if contents.find("DBFUpdateHeader") >= 0:
+ return [("HAVE_UPDATE_HEADER", "1")]
+ else:
+ return [("HAVE_UPDATE_HEADER", "0")]
extensions = [Extension("shapelibc",
["shapelib_wrap.c",
@@ -30,7 +51,8 @@
Extension("dbflibc",
["dbflib_wrap.c",
shp_dir + "/dbfopen.c"],
- include_dirs = [shp_dir])]
+ include_dirs = [shp_dir],
+ define_macros = dbf_macros())]
setup(name = "pyshapelib",
version = "0.3",
Index: dbflib_wrap.c
===================================================================
RCS file: /thubanrepository/thuban/libraries/pyshapelib/dbflib_wrap.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- dbflib_wrap.c 3 Nov 2003 17:31:11 -0000 1.3
+++ dbflib_wrap.c 17 May 2004 15:47:57 -0000 1.4
@@ -820,6 +820,15 @@
return NULL;
}
+static
+void
+DBFInfo_commit(DBFHandle handle)
+{
+#if HAVE_UPDATE_HEADER
+ DBFUpdateHeader(handle);
+#endif
+}
+
static PyObject* l_output_helper(PyObject* target, PyObject* o) {
PyObject* o2;
if (!target) {
@@ -1326,9 +1335,9 @@
}
-int DBFFile_commit(DBFFile *self) {
+void DBFFile_commit(DBFFile *self) {
{
- return DBFCommit(self->handle);
+ DBFInfo_commit(self->handle);
}
}
@@ -1337,7 +1346,6 @@
PyObject *resultobj;
DBFFile *arg0 ;
PyObject * argo0 =0 ;
- int result ;
if(!PyArg_ParseTuple(args,"O:DBFFile_commit",&argo0)) return NULL;
if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
@@ -1347,8 +1355,9 @@
SWIG_exception(SWIG_TypeError, "dbffile already closed");
#endif
}
- result = (int )DBFFile_commit(arg0);
- resultobj = PyInt_FromLong((long)result);
+ DBFFile_commit(arg0);
+ Py_INCREF(Py_None);
+ resultobj = Py_None;
return resultobj;
}
@@ -1391,6 +1400,7 @@
{ SWIG_PY_INT, "FTInteger", (long) FTInteger, 0, 0, 0},
{ SWIG_PY_INT, "FTDouble", (long) FTDouble, 0, 0, 0},
{ SWIG_PY_INT, "FTInvalid", (long) FTInvalid, 0, 0, 0},
+ { SWIG_PY_INT, "_have_commit", (long) HAVE_UPDATE_HEADER, 0, 0, 0},
{0}};
static PyObject *SWIG_globals;
Index: dbflib.py
===================================================================
RCS file: /thubanrepository/thuban/libraries/pyshapelib/dbflib.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dbflib.py 3 Nov 2003 17:31:11 -0000 1.2
+++ dbflib.py 17 May 2004 15:47:57 -0000 1.3
@@ -37,6 +37,7 @@
return val
def __repr__(self):
return "<C DBFFile instance at %s>" % (self.this,)
+ if not dbflibc._have_commit: del commit
class DBFFilePtr(DBFFile):
def __init__(self,this):
self.this = this
@@ -67,3 +68,4 @@
FTInteger = dbflibc.FTInteger
FTDouble = dbflibc.FTDouble
FTInvalid = dbflibc.FTInvalid
+_have_commit = dbflibc._have_commit
Index: dbflib.i
===================================================================
RCS file: /thubanrepository/thuban/libraries/pyshapelib/dbflib.i,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- dbflib.i 3 Nov 2003 17:31:11 -0000 1.3
+++ dbflib.i 17 May 2004 15:47:57 -0000 1.4
@@ -345,6 +345,25 @@
%}
+/* The commit method implementation
+ *
+ * The method relies on the DBFUpdateHeader method which is not
+ * available in shapelib <= 1.2.10. setup.py defines
+ * HAVE_UPDATE_HEADER's value depending on whether the function is
+ * available in the shapelib version the code is compiled with.
+ */
+%{
+static
+void
+DBFInfo_commit(DBFHandle handle)
+{
+#if HAVE_UPDATE_HEADER
+ DBFUpdateHeader(handle);
+#endif
+}
+%}
+
+
/*
* The SWIG Interface definition.
*/
@@ -502,9 +521,13 @@
dict_or_sequence);
}
- int commit() {
- return DBFCommit(self->handle);
+ void commit() {
+ DBFInfo_commit(self->handle);
}
+ /* Delete the commit method from the class if it doesn't have a
+ * real implementation.
+ */
+ %pragma(python) addtomethod="__class__:if not dbflibc._have_commit: del commit"
}
} DBFFile;
@@ -550,3 +573,11 @@
FTDouble,
FTInvalid
} DBFFieldType;
+
+
+/* Put the value of the HAVE_UPDATE_HEADER preprocessor macro into the
+ * wrapper so that the __class__ pragma above knows when to remove the
+ * commit method
+ */
+const int _have_commit = HAVE_UPDATE_HEADER;
+
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)