21 |
# filenames exclusively, so we use posix conventions when making |
# filenames exclusively, so we use posix conventions when making |
22 |
# filenames for distutils. |
# filenames for distutils. |
23 |
for shp_dir in ["..", "../shapelib", "../../../../../../shapelib"]: |
for shp_dir in ["..", "../shapelib", "../../../../../../shapelib"]: |
24 |
if (os.path.isdir(convert_path(shp_dir)) |
if (os.path.isdir(convert_path(shp_dir)) |
25 |
and os.path.exists(os.path.join(convert_path(shp_dir), "shpopen.c"))): |
and os.path.exists(os.path.join(convert_path(shp_dir), "shpopen.c"))): |
26 |
# shp_dir contains shpopen.c, so assume it's the directory with |
# shp_dir contains shpopen.c, so assume it's the directory with |
27 |
# the shapefile library to use |
# the shapefile library to use |
28 |
break |
break |
29 |
else: |
else: |
30 |
print >>sys.stderr, "no shapelib directory found" |
print >>sys.stderr, "no shapelib directory found" |
31 |
sys.exit(1) |
sys.exit(1) |
32 |
|
|
33 |
def dbf_macros(): |
def dbf_macros(): |
34 |
"""Return the macros to define when compiling the dbflib wrapper. |
"""Return the macros to define when compiling the dbflib wrapper. |
35 |
|
|
36 |
The returned list specifies one macro, HAVE_UPDATE_HEADER, which is |
The returned list specifies following macros: |
37 |
'1' if the dbflib version we will be compiling with has the |
- HAVE_UPDATE_HEADER, which is |
38 |
DBFUpdateHeader function and '0' otherwise. To check whether |
'1' if the dbflib version we will be compiling with has the |
39 |
DBFUpdateHeader is available, we scan shapefil.h for the string |
DBFUpdateHeader function and '0' otherwise. To check whether |
40 |
'DBFUpdateHeader'. |
DBFUpdateHeader is available, we scan shapefil.h for the string |
41 |
""" |
'DBFUpdateHeader'. |
42 |
f = open(convert_path(shp_dir + "/shapefil.h")) |
- HAVE_LANGUAGE_DRIVER, whics is '1' if the dbflib version we will |
43 |
contents = f.read() |
compiling with has the nLanguageDriver field in DBFInfo and '0' otherwise. |
44 |
f.close() |
Again, shapefil.h is scanned to check this. |
45 |
if contents.find("DBFUpdateHeader") >= 0: |
""" |
46 |
return [("HAVE_UPDATE_HEADER", "1")] |
f = open(convert_path(shp_dir + "/shapefil.h")) |
47 |
else: |
contents = f.read() |
48 |
return [("HAVE_UPDATE_HEADER", "0")] |
f.close() |
49 |
|
|
50 |
|
def have(keyword): |
51 |
|
if keyword in contents: |
52 |
|
return "1" |
53 |
|
return 0 |
54 |
|
|
55 |
|
return [ |
56 |
|
("HAVE_UPDATE_HEADER", have("DBFUpdateHeader")), |
57 |
|
("HAVE_LANGUAGE_DRIVER", have("nLanguageDriver"))] |
58 |
|
|
59 |
extensions = [Extension("shapelib", |
extensions = [Extension("shapelib", |
60 |
["shapelibmodule.c", |
["shapelibmodule.c", |
61 |
shp_dir + "/shpopen.c", |
shp_dir + "/shpopen.c", |
62 |
shp_dir + "/shptree.c"], |
shp_dir + "/shptree.c"], |
63 |
include_dirs = [shp_dir]), |
include_dirs = [shp_dir]), |
64 |
Extension("shptree", |
Extension("shptree", |
65 |
["shptreemodule.c"], |
["shptreemodule.c"], |
66 |
include_dirs = [shp_dir]), |
include_dirs = [shp_dir]), |
67 |
Extension("dbflib", |
Extension("dbflib", |
68 |
["dbflibmodule.c", |
["dbflibmodule.c", |
69 |
shp_dir + "/dbfopen.c"], |
shp_dir + "/dbfopen.c"], |
70 |
include_dirs = [shp_dir], |
include_dirs = [shp_dir], |
71 |
define_macros = dbf_macros())] |
define_macros = dbf_macros())] |
72 |
|
|
73 |
setup(name = "pyshapelib", |
setup(name = "pyshapelib", |
74 |
version = "0.3", |
version = "0.3", |
75 |
description = "Python bindings for shapelib", |
description = "Python bindings for shapelib", |
76 |
author = "Bernhard Herzog", |
author = "Bernhard Herzog", |
77 |
author_email = "[email protected]", |
author_email = "[email protected]", |
78 |
url = "ftp:intevation.de/users/bh", |
url = "ftp:intevation.de/users/bh", |
79 |
ext_modules = extensions) |
ext_modules = extensions) |
80 |
|
|