1 |
# Copyright (c) 2001, 2002, 2003 by Intevation GmbH |
# Copyright (c) 2001, 2002, 2003, 2004 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
15 |
# hand below. |
# hand below. |
16 |
# |
# |
17 |
|
|
18 |
|
import sys |
19 |
import os |
import os |
20 |
from types import TupleType |
from types import TupleType |
21 |
import glob |
import glob |
23 |
from distutils.command.install import install, INSTALL_SCHEMES, subst_vars |
from distutils.command.install import install, INSTALL_SCHEMES, subst_vars |
24 |
from distutils.command.build_py import build_py |
from distutils.command.build_py import build_py |
25 |
from distutils.command.bdist_rpm import bdist_rpm |
from distutils.command.bdist_rpm import bdist_rpm |
26 |
|
from distutils.command.build_ext import build_ext |
27 |
from distutils.file_util import write_file |
from distutils.file_util import write_file |
28 |
from distutils.filelist import FileList |
from distutils.filelist import FileList |
29 |
from distutils.util import convert_path, change_root |
from distutils.util import convert_path, change_root |
34 |
from string import split |
from string import split |
35 |
import string |
import string |
36 |
|
|
37 |
|
# config script parameter list indices |
38 |
|
CS_DEFS, CS_INCDIRS, CS_LIBDIRS, CS_LIBS, CS_NUM_PARAMS = range(5) |
39 |
|
|
40 |
|
# support for gdal is on by default, but under posix we try to |
41 |
|
# detect it anyway. Set this to False to disable GDAL. |
42 |
|
include_gdal = True |
43 |
|
|
44 |
if os.name == "posix": |
if os.name == "posix": |
45 |
################################################################### |
################################################################### |
46 |
# Posix configuration. Adapt this if you're running some kind of |
# Posix configuration. Adapt this if you're running some kind of |
61 |
# with the install command's --prefix option. |
# with the install command's --prefix option. |
62 |
# |
# |
63 |
# Note that there's a separate prefix option for the bdist_rpm |
# Note that there's a separate prefix option for the bdist_rpm |
64 |
# command completely independend of this one. |
# command completely independent of this one. |
65 |
prefix = "/usr/local/" |
prefix = "/usr/local/" |
66 |
|
|
67 |
# Whether to create the thubaninit module. You can override this |
# Whether to create the thubaninit module. You can override this |
73 |
# flags |
# flags |
74 |
wx_config_script = "wx-config" |
wx_config_script = "wx-config" |
75 |
# These lists will be filled automatically below |
# These lists will be filled automatically below |
76 |
wx_defs = [] |
wx_cs_params = [[] for i in range(CS_NUM_PARAMS)] |
77 |
wx_incdirs = [] |
|
78 |
wx_libdirs = [] |
gdal_config_script = "gdal-config" |
79 |
wx_libs = [] |
gdal_cs_params = [[] for i in range(CS_NUM_PARAMS)] |
80 |
|
|
81 |
elif os.name == "nt": |
elif os.name == "nt": |
82 |
################################################################# |
################################################################# |
83 |
# Windows configuration. |
# Windows configuration. |
84 |
# |
# |
85 |
|
|
86 |
|
basedir = os.path.dirname(sys.argv[0]) |
87 |
|
|
88 |
# Directories where Proj4 is installed |
# Directories where Proj4 is installed |
89 |
proj4_prefix = r"D:\cygwin\home\user\proj-4.4.3\src" |
proj4_prefix = os.path.join(basedir, "..", "proj-4.4.7", "src") |
90 |
proj4_incdir = proj4_prefix |
proj4_incdir = proj4_prefix |
91 |
proj4_libdir = proj4_prefix |
proj4_libdir = proj4_prefix |
92 |
proj4_lib = "proj_i" |
proj4_lib = "proj_i" |
93 |
|
|
94 |
# Define include and lib directories for wxWindows and |
# Define include and lib directories for wxWindows and |
95 |
wx_prefix = r"D:\wx240" |
wx_prefix = os.path.join(basedir, "..", "wxPython-2.4.2.4") |
96 |
wx_inc = [os.path.join(wx_prefix, 'lib', 'mswdllh'), |
wx_inc = [os.path.join(wx_prefix, 'lib', 'mswdllh'), |
97 |
os.path.join(wx_prefix, "include")] |
os.path.join(wx_prefix, "include")] |
98 |
wx_lib = [os.path.join(wx_prefix, "lib")] |
wx_lib = [os.path.join(wx_prefix, "lib")] |
99 |
|
|
100 |
|
# Define include and lib directories for GDAL |
101 |
|
gdal_prefix = os.path.join(basedir, "..", "gdal-1.1.8") |
102 |
|
gdal_inc = [os.path.join(gdal_prefix, 'alg'), |
103 |
|
os.path.join(gdal_prefix, 'ogr'), |
104 |
|
os.path.join(gdal_prefix, 'port'), |
105 |
|
os.path.join(gdal_prefix, 'core')] |
106 |
|
gdal_lib = [gdal_prefix] |
107 |
|
|
108 |
# |
# |
109 |
# Unless you use a wxPython version other than 2.4.0, you probably |
# Unless you use a wxPython version other than 2.4.0, you probably |
130 |
# there's no config script. |
# there's no config script. |
131 |
wx_config_script = "" |
wx_config_script = "" |
132 |
|
|
133 |
|
wx_cs_params = [[] for i in range(CS_NUM_PARAMS)] |
134 |
|
|
135 |
# the values of wx_defs and wx_libs. copied from the wxPython |
# the values of wx_defs and wx_libs. copied from the wxPython |
136 |
# setup.py |
# setup.py |
137 |
wx_defs = [ ('WIN32', None), # Some of these are no longer |
wx_cs_params[CS_DEFS] = \ |
138 |
|
[ ('WIN32', None), # Some of these are no longer |
139 |
('__WIN32__', None), # necessary. Anybody know which? |
('__WIN32__', None), # necessary. Anybody know which? |
140 |
('_WINDOWS', None), |
('_WINDOWS', None), |
141 |
('__WINDOWS__', None), |
('__WINDOWS__', None), |
151 |
('WXP_USE_THREAD', '1'), |
('WXP_USE_THREAD', '1'), |
152 |
] |
] |
153 |
|
|
154 |
wx_incdirs = wx_inc |
wx_cs_params[CS_INCDIRS] = wx_inc |
155 |
wx_libdirs = wx_lib |
wx_cs_params[CS_LIBDIRS] = wx_lib |
156 |
wx_libs = ["wxmsw24h"] |
wx_cs_params[CS_LIBS] = ["wxmsw24h"] \ |
157 |
|
+ ['kernel32', 'user32', 'gdi32', 'comdlg32', |
|
wx_libs = wx_libs + ['kernel32', 'user32', 'gdi32', 'comdlg32', |
|
158 |
'winspool', 'winmm', 'shell32', 'oldnames', |
'winspool', 'winmm', 'shell32', 'oldnames', |
159 |
'comctl32', 'ctl3d32', 'odbc32', 'ole32', 'oleaut32', |
'comctl32', 'ctl3d32', 'odbc32', 'ole32', 'oleaut32', |
160 |
'uuid', 'rpcrt4', 'advapi32', 'wsock32'] |
'uuid', 'rpcrt4', 'advapi32', 'wsock32'] |
161 |
|
|
162 |
|
gdal_config_script = "" |
163 |
|
gdal_cs_params = [[] for i in range(CS_NUM_PARAMS)] |
164 |
|
|
165 |
|
gdal_cs_params[CS_INCDIRS] = gdal_inc |
166 |
|
gdal_cs_params[CS_LIBDIRS] = gdal_lib |
167 |
|
gdal_cs_params[CS_LIBS] = ["gdal_i"] |
168 |
|
|
169 |
else: |
else: |
170 |
raise RuntimeError("Unsupported platform " + os.name) |
raise RuntimeError("Unsupported platform " + os.name) |
171 |
|
|
192 |
return result |
return result |
193 |
|
|
194 |
|
|
195 |
def run_wx_script(command): |
def run_cs_script(command, store): |
196 |
# first, determine the C++ preprocessor flags Use --cflags here |
# first, determine the C++ preprocessor flags Use --cflags here |
197 |
# because it seems that older version don't have --cxxflags and |
# because it seems that older version don't have --cxxflags and |
198 |
# newer ones return the same result for both |
# newer ones return the same result for both |
199 |
flags = run_script(command + ' --cflags ') |
flags = run_script(command + ' --cflags ') |
200 |
if flags is None: |
if flags is None: |
201 |
return 0 |
return False |
202 |
for flag in split(flags): |
for flag in split(flags): |
203 |
start = flag[:2] |
start = flag[:2] |
204 |
value = flag[2:] |
value = flag[2:] |
205 |
if start == "-I": |
if start == "-I": |
206 |
wx_incdirs.append(value) |
store[CS_INCDIRS].append(value) |
207 |
elif start == "-D": |
elif start == "-D": |
208 |
wx_defs.append((value, None)) |
store[CS_DEFS].append((value, None)) |
209 |
|
|
210 |
# determine the library flags |
# determine the library flags |
211 |
flags = run_script(command + ' --libs') |
flags = run_script(command + ' --libs') |
212 |
if flags is None: |
if flags is None: |
213 |
return 0 |
return False |
214 |
for flag in split(flags): |
for flag in split(flags): |
215 |
start = flag[:2] |
start = flag[:2] |
216 |
value = flag[2:] |
value = flag[2:] |
217 |
if start == "-L": |
if start == "-L": |
218 |
wx_libdirs.append(value) |
store[CS_LIBDIRS].append(value) |
219 |
elif start == "-l": |
elif start == "-l": |
220 |
wx_libs.append(value) |
store[CS_LIBS].append(value) |
221 |
|
|
222 |
|
return True |
223 |
|
|
224 |
if wx_config_script: |
if wx_config_script: |
225 |
# if there's a wx config script, run it to determine the configuration |
# if there's a wx config script, run it to determine the configuration |
226 |
run_wx_script(wx_config_script) |
run_cs_script(wx_config_script, wx_cs_params) |
|
|
|
227 |
|
|
228 |
|
if gdal_config_script: |
229 |
|
# if there's a gdal config script, run it to determine the configuration |
230 |
|
include_gdal = include_gdal \ |
231 |
|
and run_cs_script(gdal_config_script, gdal_cs_params) |
232 |
|
|
233 |
# |
# |
234 |
# Define some extension and python modules |
# Define some extension and python modules |
235 |
# |
# |
236 |
# The C-extension names are prefixed woth "Lib." so they get put into |
# The C-extension names are prefixed with "Lib." so they get put into |
237 |
# the Lib/ subdirectory. Lib/ is not really a package but distutils |
# the Lib/ subdirectory. Lib/ is not really a package but distutils |
238 |
# doesn't care |
# doesn't care |
239 |
|
|
240 |
# subdirectory containing the extensions |
# subdirectory containing the distutil extensions |
241 |
ext_dir = "extensions" |
ext_dir = "libraries" |
242 |
|
|
243 |
# subdirectory with some shapelib files |
# subdirectory with some shapelib files |
244 |
shp_dir = ext_dir + "/shapelib" |
shp_dir = ext_dir + "/shapelib" |
256 |
[ext_dir + "/thuban/wxproj.cpp"], |
[ext_dir + "/thuban/wxproj.cpp"], |
257 |
include_dirs = ([shp_dir, proj4_incdir, |
include_dirs = ([shp_dir, proj4_incdir, |
258 |
ext_dir + "/pyshapelib/"] |
ext_dir + "/pyshapelib/"] |
259 |
+ wx_incdirs), |
+ wx_cs_params[CS_INCDIRS]), |
260 |
define_macros = wx_defs, |
define_macros = wx_cs_params[CS_DEFS], |
261 |
library_dirs = [proj4_libdir] + wx_libdirs, |
library_dirs = [proj4_libdir] + |
262 |
libraries = [proj4_lib] + wx_libs)) |
wx_cs_params[CS_LIBDIRS], |
263 |
|
libraries = [proj4_lib] + wx_cs_params[CS_LIBS])) |
264 |
|
|
265 |
|
|
266 |
# |
# |
267 |
# shapelib wrappers are also distributed with thuban |
# shapelib wrappers are also distributed with thuban |
278 |
extensions.append(Extension("Lib.dbflibc", |
extensions.append(Extension("Lib.dbflibc", |
279 |
[ext_dir + "/pyshapelib/dbflib_wrap.c", |
[ext_dir + "/pyshapelib/dbflib_wrap.c", |
280 |
shp_dir + "/dbfopen.c"], |
shp_dir + "/dbfopen.c"], |
281 |
include_dirs = [shp_dir])) |
include_dirs = [shp_dir], |
282 |
|
define_macros = [("HAVE_UPDATE_HEADER", "1")])) |
283 |
for name in ("shapelib", "dbflib"): |
for name in ("shapelib", "dbflib"): |
284 |
py_modules.append(ext_dir + "/pyshapelib/" + name) |
py_modules.append(ext_dir + "/pyshapelib/" + name) |
285 |
|
|
300 |
|
|
301 |
data_files = [] |
data_files = [] |
302 |
|
|
303 |
# bitmaps |
# Resources |
304 |
for d, pattern in [("Resources/Bitmaps", "Resources/Bitmaps/*.xpm"), |
for d, patterns in [("Resources/Bitmaps", |
305 |
("Resources/Locale", "Resources/Locale/*/LC_MESSAGES/*.mo") |
("Resources/Bitmaps/*.xpm",)), |
306 |
|
("Resources/Projections", |
307 |
|
("Resources/Projections/*.proj",)), |
308 |
|
("Resources/XML", |
309 |
|
("Resources/XML/*.dtd",)), |
310 |
|
("Extensions/importAPR/samples", |
311 |
|
("Extensions/importAPR/samples/README", |
312 |
|
"Extensions/importAPR/samples/*.apr")), |
313 |
]: |
]: |
314 |
data_files.append((d, glob.glob(pattern))) |
for pattern in patterns: |
315 |
|
data_files.append((d, glob.glob(pattern))) |
316 |
|
if os.path.isdir("Resources/Locale"): |
317 |
|
for d in os.listdir("Resources/Locale"): |
318 |
|
data_files.append(("Resources/Locale/" + d +"/LC_MESSAGES", |
319 |
|
["Resources/Locale/"+ d +"/LC_MESSAGES/thuban.mo"])) |
320 |
|
|
321 |
# |
# |
322 |
# Command definitions |
# Command definitions |
653 |
("extra-files", None, |
("extra-files", None, |
654 |
"List of filenames or (src, dest) pairs describing" |
"List of filenames or (src, dest) pairs describing" |
655 |
" extra files to install " |
" extra files to install " |
656 |
"(can only be set from witin setup.py"), |
"(can only be set from within setup.py"), |
657 |
|
|
658 |
("create-init-module=", None, |
("create-init-module=", None, |
659 |
"If true, create a module in the site-packages" |
"If true, create a module in the site-packages" |
798 |
|
|
799 |
bdist_rpm_prep_script = ''' |
bdist_rpm_prep_script = ''' |
800 |
%setup |
%setup |
801 |
cp extensions/pyshapelib/{README,README.pyshapelib} |
cp libraries/pyshapelib/{README,README.pyshapelib} |
802 |
cp extensions/pyshapelib/{COPYING,COPYING.pyshapelib} |
cp libraries/pyshapelib/{COPYING,COPYING.pyshapelib} |
803 |
cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection} |
cp libraries/pyprojection/{LICENSE,LICENSE.pyprojection} |
804 |
''' |
''' |
805 |
|
|
806 |
bdist_rpm_build_script = ''' |
bdist_rpm_build_script = ''' |
1070 |
def run(self, install_options = None): |
def run(self, install_options = None): |
1071 |
self.spawn(["happydoc", "-d./Doc", "./Thuban"]) |
self.spawn(["happydoc", "-d./Doc", "./Thuban"]) |
1072 |
|
|
1073 |
|
class thuban_build_ext(build_ext): |
1074 |
|
|
1075 |
|
"""Extend the build_ext command to optionally include the |
1076 |
|
GDAL extension. |
1077 |
|
""" |
1078 |
|
|
1079 |
|
user_options = build_ext.user_options[:] |
1080 |
|
user_options.extend([("with-gdal", None, "Include GDAL support."), |
1081 |
|
("without-gdal", None, "Don't include GDAL support.")]) |
1082 |
|
|
1083 |
|
boolean_options = ["with-gdal"] |
1084 |
|
negative_opt = {'without-gdal' : 'with-gdal'} |
1085 |
|
|
1086 |
|
def initialize_options(self): |
1087 |
|
self.with_gdal = True |
1088 |
|
build_ext.initialize_options(self) |
1089 |
|
|
1090 |
|
def finalize_options(self): |
1091 |
|
build_ext.finalize_options(self) |
1092 |
|
if self.with_gdal and include_gdal: |
1093 |
|
self.extensions.append(Extension("Lib.gdalwarp", |
1094 |
|
[ext_dir + "/thuban/gdalwarp.cpp", |
1095 |
|
ext_dir + "/thuban/cpl_mfile.cpp", |
1096 |
|
ext_dir + "/thuban/bmpdataset.cpp"], |
1097 |
|
include_dirs = gdal_cs_params[CS_INCDIRS] + |
1098 |
|
[ext_dir + "/thuban/"], |
1099 |
|
define_macros = gdal_cs_params[CS_DEFS], |
1100 |
|
library_dirs = gdal_cs_params[CS_LIBDIRS], |
1101 |
|
libraries = gdal_cs_params[CS_LIBS])) |
1102 |
|
|
1103 |
|
def run(self, install_options = None): |
1104 |
|
build_ext.run(self) |
1105 |
|
|
1106 |
# |
# |
1107 |
# Run the script |
# Run the script |
1108 |
# |
# |
1109 |
|
|
|
|
|
1110 |
long_description = """\ |
long_description = """\ |
1111 |
Thuban is a viewer for geographic data written in Python |
Thuban is a viewer for geographic data written in Python |
1112 |
""" |
""" |
1113 |
|
|
1114 |
setup(name = "Thuban", |
setup(name = "Thuban", |
1115 |
version = "0.2.0", |
version = "1.0.0", |
1116 |
description = "Geographic data viewer", |
description = "Geographic data viewer", |
1117 |
long_description = long_description, |
long_description = long_description, |
1118 |
licence = "GPL", |
license = "GPL", |
1119 |
author = "Intevation GmbH", |
author = "Intevation GmbH", |
1120 |
author_email = "[email protected]", |
author_email = "[email protected]", |
1121 |
url = "http://thuban.intevation.de/", |
url = "http://thuban.intevation.de/", |
1122 |
|
|
1123 |
scripts = ["thuban.py"], |
scripts = ["thuban.py"], |
1124 |
packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"], |
packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI", |
1125 |
|
"Extensions", "Extensions.gns2shp", "Extensions.wms", |
1126 |
|
"Extensions.importAPR", "Extensions.profiling"], |
1127 |
ext_modules = extensions, |
ext_modules = extensions, |
1128 |
py_modules = py_modules, |
py_modules = py_modules, |
1129 |
data_files = data_files, |
data_files = data_files, |
1157 |
"bdist_rpm": thuban_bdist_rpm, |
"bdist_rpm": thuban_bdist_rpm, |
1158 |
"bdist_inno": thuban_bdist_inno, |
"bdist_inno": thuban_bdist_inno, |
1159 |
"data_dist": data_dist, |
"data_dist": data_dist, |
1160 |
"build_docs": thuban_build_docs |
"build_docs": thuban_build_docs, |
1161 |
|
"build_ext": thuban_build_ext |
1162 |
}) |
}) |
1163 |
|
|
1164 |
|
|