1 |
# Copyright (c) 2001, 2002 by Intevation GmbH |
2 |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
4 |
# |
5 |
# This program is free software under the GPL (>=v2) |
6 |
# Read the file COPYING coming with Thuban for details. |
7 |
|
8 |
"""Distutils setup script for Thuban.""" |
9 |
|
10 |
__version__ = "$Revision$" |
11 |
|
12 |
# Configuration: |
13 |
# |
14 |
# depending on your platform you may have to configure some variables by |
15 |
# hand below. |
16 |
# |
17 |
|
18 |
import os |
19 |
from types import TupleType |
20 |
from distutils.core import setup, Extension, Command |
21 |
from distutils.command.install import install |
22 |
from distutils.command.build_py import build_py |
23 |
from distutils.command.bdist_rpm import bdist_rpm |
24 |
from distutils.file_util import write_file |
25 |
from distutils.filelist import FileList |
26 |
from distutils.util import convert_path, change_root |
27 |
|
28 |
from distutils import archive_util, dir_util |
29 |
import distutils |
30 |
|
31 |
from string import split |
32 |
import string |
33 |
|
34 |
if os.name == "posix": |
35 |
################################################################### |
36 |
# Posix configuration. Adapt this if you're running some kind of |
37 |
# Unix like system. |
38 |
|
39 |
# Directories where Proj4 is installed |
40 |
proj4_prefix = "/usr/local/" |
41 |
proj4_incdir = os.path.join(proj4_prefix, "include") |
42 |
proj4_libdir = os.path.join(proj4_prefix, "lib") |
43 |
proj4_lib = "proj" |
44 |
|
45 |
|
46 |
# You shpuldn't have to modify anything below here |
47 |
################################################################### |
48 |
|
49 |
# The installation prefix (similar to autoconf's --prefix). This is |
50 |
# only the default value, you can override it on the command line |
51 |
# with the install command's --prefix option |
52 |
prefix = "/usr/local/" |
53 |
|
54 |
# On POSIX-systems we run wxgtk-config to determine the C++-compiler |
55 |
# flags |
56 |
wx_config_script = "wx-config" |
57 |
# These lists will be filled automatically below |
58 |
wx_defs = [] |
59 |
wx_incdirs = [] |
60 |
wx_libdirs = [] |
61 |
wx_libs = [] |
62 |
|
63 |
elif os.name == "nt": |
64 |
################################################################# |
65 |
# Windows configuration. |
66 |
# |
67 |
|
68 |
# Directories where Proj4 is installed |
69 |
proj4_prefix = r"D:\cygwin\home\user\proj-4.4.3\src" |
70 |
proj4_incdir = proj4_prefix |
71 |
proj4_libdir = proj4_prefix |
72 |
proj4_lib = "proj_i" |
73 |
|
74 |
# Define include and lib directories for wxWindows and |
75 |
wx_prefix = r"D:\wx230" |
76 |
wx_inc = os.path.join(wx_prefix, "include") |
77 |
wx_lib = os.path.join(wx_prefix, "lib") |
78 |
|
79 |
# |
80 |
# Unless you use a wxPython version other than 2.3.1, you probably |
81 |
# shouldn't have to modify anything below here |
82 |
################################################################## |
83 |
|
84 |
# Installation prefix. Just install relative to current directory by |
85 |
# default. This is only the default value, you can override it on |
86 |
# the command line with the install command's --prefix option |
87 |
prefix = r"install" |
88 |
|
89 |
# There doesn't seem to be an easy way to get at the wx compiler |
90 |
# flags, so we define them here. These flags work for us with |
91 |
# wxPython 2.3.1. They may have to be modified for other versions. |
92 |
|
93 |
# there's no config script. |
94 |
wx_config_script = "" |
95 |
|
96 |
# the values of wx_defs and wx_libs. copied from the wxPython |
97 |
# setup.py |
98 |
wx_defs = [ ('WIN32', None), # Some of these are no longer |
99 |
('__WIN32__', None), # necessary. Anybody know which? |
100 |
('_WINDOWS', None), |
101 |
('__WINDOWS__', None), |
102 |
('WINVER', '0x0400'), |
103 |
('__WIN95__', None), |
104 |
('STRICT', None), |
105 |
|
106 |
('__WXMSW__', None), |
107 |
('WXUSINGDLL', '1'), |
108 |
|
109 |
('SWIG_GLOBAL', None), |
110 |
('HAVE_CONFIG_H', None), |
111 |
('WXP_USE_THREAD', '1'), |
112 |
] |
113 |
|
114 |
wx_incdirs = [wx_inc] |
115 |
wx_libdirs = [wx_lib] |
116 |
wx_libs = ["wx23_1h"] |
117 |
wx_libs = wx_libs + ['kernel32', 'user32', 'gdi32', 'comdlg32', |
118 |
'winspool', 'winmm', 'shell32', 'oldnames', |
119 |
'comctl32', 'ctl3d32', 'odbc32', 'ole32', 'oleaut32', |
120 |
'uuid', 'rpcrt4', 'advapi32', 'wsock32'] |
121 |
else: |
122 |
raise RuntimeError("Unsupported platform " + os.name) |
123 |
|
124 |
|
125 |
###################################################################### |
126 |
# |
127 |
# There's nothing beyond this point that has to be modified for a |
128 |
# normal installation |
129 |
# |
130 |
###################################################################### |
131 |
|
132 |
|
133 |
# |
134 |
# Functions to determine wxWindows config on POSIX systems |
135 |
# |
136 |
|
137 |
def run_script(cmdline): |
138 |
"""Run command and return its stdout or none in case of errors""" |
139 |
pipe = os.popen(cmdline) |
140 |
result = pipe.read() |
141 |
if pipe.close() is not None: |
142 |
print '"' + cmdline + '"', 'failed' |
143 |
return None |
144 |
return result |
145 |
|
146 |
|
147 |
def run_wx_script(command): |
148 |
# first, determine the C++ preprocessor flags Use --cflags here |
149 |
# because it seems that older version don't have --cxxflags and |
150 |
# newer ones return the same result for both |
151 |
flags = run_script(command + ' --cflags ') |
152 |
if flags is None: |
153 |
return 0 |
154 |
for flag in split(flags): |
155 |
start = flag[:2] |
156 |
value = flag[2:] |
157 |
if start == "-I": |
158 |
wx_incdirs.append(value) |
159 |
elif start == "-D": |
160 |
wx_defs.append((value, None)) |
161 |
|
162 |
# determine the library flags |
163 |
flags = run_script(command + ' --libs') |
164 |
if flags is None: |
165 |
return 0 |
166 |
for flag in split(flags): |
167 |
start = flag[:2] |
168 |
value = flag[2:] |
169 |
if start == "-L": |
170 |
wx_libdirs.append(value) |
171 |
elif start == "-l": |
172 |
wx_libs.append(value) |
173 |
|
174 |
if wx_config_script: |
175 |
# if there's a wx config script, run it to determine the configuration |
176 |
run_wx_script(wx_config_script) |
177 |
|
178 |
|
179 |
|
180 |
# |
181 |
# Define some extension and python modules |
182 |
# |
183 |
# The C-extension names are prefixed woth "Lib." so they get put into |
184 |
# the Lib/ subdirectory. Lib/ is not really a package but distutils |
185 |
# doesn't care |
186 |
|
187 |
# subdirectory containing the extensions |
188 |
ext_dir = "extensions" |
189 |
|
190 |
# subdirectory with some shapelib files |
191 |
shp_dir = ext_dir + "/shapelib" |
192 |
|
193 |
# lists to fill with the module descriptions |
194 |
extensions = [] |
195 |
py_modules = [] |
196 |
|
197 |
|
198 |
# |
199 |
# Thuban specific modules |
200 |
# |
201 |
|
202 |
extensions.append(Extension("Lib.wxproj", |
203 |
[ext_dir + "/thuban/wxproj.cpp"], |
204 |
include_dirs = ([shp_dir, proj4_incdir, |
205 |
ext_dir + "/pyshapelib/"] |
206 |
+ wx_incdirs), |
207 |
define_macros = wx_defs, |
208 |
library_dirs = [proj4_libdir] + wx_libdirs, |
209 |
libraries = [proj4_lib] + wx_libs)) |
210 |
|
211 |
# |
212 |
# shapelib wrappers are also distributed with thuban |
213 |
# |
214 |
|
215 |
extensions.append(Extension("Lib.shapelibc", |
216 |
[ext_dir + "/pyshapelib/shapelib_wrap.c", |
217 |
shp_dir + "/shpopen.c"], |
218 |
include_dirs = [shp_dir])) |
219 |
extensions.append(Extension("Lib.dbflibc", |
220 |
[ext_dir + "/pyshapelib/dbflib_wrap.c", |
221 |
shp_dir + "/dbfopen.c"], |
222 |
include_dirs = [shp_dir])) |
223 |
for name in ("shapelib", "dbflib"): |
224 |
py_modules.append(ext_dir + "/pyshapelib/" + name) |
225 |
|
226 |
# |
227 |
# PROJ4 bindings are also distributed with thuban |
228 |
# |
229 |
extensions.append(Extension("Lib.Projectionc", |
230 |
[ext_dir + "/pyprojection/Projection_wrap.c"], |
231 |
include_dirs = [proj4_incdir], |
232 |
library_dirs = [proj4_libdir], |
233 |
libraries = [proj4_lib])) |
234 |
py_modules.append(ext_dir + "/pyprojection/Projection") |
235 |
|
236 |
|
237 |
# |
238 |
# Data files |
239 |
# |
240 |
|
241 |
data_files = [] |
242 |
|
243 |
# bitmaps |
244 |
dir = "Resources/Bitmaps" |
245 |
bitmaps = [] |
246 |
for file in os.listdir(os.path.join("Resources", "Bitmaps")): |
247 |
if string.lower(file[-4:]) == ".xpm": |
248 |
bitmaps.append(dir + '/' + file) |
249 |
data_files.append((dir, bitmaps)) |
250 |
|
251 |
# |
252 |
# Command definitions |
253 |
# |
254 |
# So far distutils are only meant to distribute python extensions, not |
255 |
# complete applications, so we have to redefine a few commands |
256 |
# |
257 |
|
258 |
|
259 |
# Much of the data_dist command is directly copied from the distutils' |
260 |
# sdist command |
261 |
class data_dist(Command): |
262 |
|
263 |
description = "create a data distribution (tarball, zip file, etc.)" |
264 |
|
265 |
user_options = [ |
266 |
('formats=', None, |
267 |
"formats for source distribution (comma-separated list)"), |
268 |
('keep-temp', 'k', |
269 |
"keep the distribution tree around after creating " + |
270 |
"archive file(s)"), |
271 |
('dist-dir=', 'd', |
272 |
"directory to put the source distribution archive(s) in " |
273 |
"[default: dist]"), |
274 |
] |
275 |
|
276 |
boolean_options = ['keep-temp'] |
277 |
|
278 |
def initialize_options (self): |
279 |
self.formats = None |
280 |
self.keep_temp = 0 |
281 |
self.dist_dir = None |
282 |
|
283 |
def finalize_options (self): |
284 |
self.ensure_string_list('formats') |
285 |
if self.formats is None: |
286 |
self.formats = ["zip"] |
287 |
bad_format = archive_util.check_archive_formats(self.formats) |
288 |
if bad_format: |
289 |
raise DistutilsOptionError, \ |
290 |
"unknown archive format '%s'" % bad_format |
291 |
|
292 |
if self.dist_dir is None: |
293 |
self.dist_dir = "dist" |
294 |
|
295 |
|
296 |
def run(self): |
297 |
# 'filelist' contains the list of files that will make up the |
298 |
# manifest |
299 |
self.filelist = FileList() |
300 |
|
301 |
# Do whatever it takes to get the list of files to process. |
302 |
# File list is accumulated in 'self.filelist'. |
303 |
self.get_file_list() |
304 |
|
305 |
# Otherwise, go ahead and create the source distribution tarball, |
306 |
# or zipfile, or whatever. |
307 |
self.make_distribution() |
308 |
|
309 |
def get_file_list(self): |
310 |
"""Figure out the list of files to include in the data |
311 |
distribution, and put it in 'self.filelist'. |
312 |
""" |
313 |
self.filelist.findall("Data") |
314 |
self.filelist.include_pattern("*", anchor = 0) |
315 |
self.filelist.exclude_pattern(r'/(RCS|CVS)/.*', is_regex=1) |
316 |
self.filelist.sort() |
317 |
self.filelist.remove_duplicates() |
318 |
|
319 |
def make_release_tree(self, base_dir, files): |
320 |
"""Create the directory tree that will become the source |
321 |
distribution archive. All directories implied by the filenames in |
322 |
'files' are created under 'base_dir', and then we hard link or copy |
323 |
(if hard linking is unavailable) those files into place. |
324 |
Essentially, this duplicates the developer's source tree, but in a |
325 |
directory named after the distribution, containing only the files |
326 |
to be distributed. |
327 |
""" |
328 |
# Create all the directories under 'base_dir' necessary to |
329 |
# put 'files' there; the 'mkpath()' is just so we don't die |
330 |
# if the manifest happens to be empty. |
331 |
self.mkpath(base_dir) |
332 |
dir_util.create_tree(base_dir, files, |
333 |
verbose=self.verbose, dry_run=self.dry_run) |
334 |
|
335 |
# And walk over the list of files, either making a hard link (if |
336 |
# os.link exists) to each one that doesn't already exist in its |
337 |
# corresponding location under 'base_dir', or copying each file |
338 |
# that's out-of-date in 'base_dir'. (Usually, all files will be |
339 |
# out-of-date, because by default we blow away 'base_dir' when |
340 |
# we're done making the distribution archives.) |
341 |
|
342 |
if hasattr(os, 'link'): # can make hard links on this system |
343 |
link = 'hard' |
344 |
msg = "making hard links in %s..." % base_dir |
345 |
else: # nope, have to copy |
346 |
link = None |
347 |
msg = "copying files to %s..." % base_dir |
348 |
|
349 |
if not files: |
350 |
self.warn("no files to distribute -- empty manifest?") |
351 |
else: |
352 |
self.announce(msg) |
353 |
for file in files: |
354 |
if not os.path.isfile(file): |
355 |
self.warn("'%s' not a regular file -- skipping" % file) |
356 |
else: |
357 |
dest = os.path.join(base_dir, file) |
358 |
self.copy_file(file, dest, link=link) |
359 |
|
360 |
|
361 |
def make_distribution (self): |
362 |
"""Create the source distribution(s). First, we create the release |
363 |
tree with 'make_release_tree()'; then, we create all required |
364 |
archive files (according to 'self.formats') from the release tree. |
365 |
Finally, we clean up by blowing away the release tree (unless |
366 |
'self.keep_temp' is true). The list of archive files created is |
367 |
stored so it can be retrieved later by 'get_archive_files()'. |
368 |
""" |
369 |
# Don't warn about missing meta-data here -- should be (and is!) |
370 |
# done elsewhere. |
371 |
base_dir = "Thuban-data-" + self.distribution.get_version() |
372 |
base_name = os.path.join(self.dist_dir, base_dir) |
373 |
|
374 |
self.make_release_tree(base_dir, self.filelist.files) |
375 |
archive_files = [] # remember names of files we create |
376 |
for fmt in self.formats: |
377 |
file = self.make_archive(base_name, fmt, base_dir=base_dir) |
378 |
archive_files.append(file) |
379 |
|
380 |
self.archive_files = archive_files |
381 |
|
382 |
if not self.keep_temp: |
383 |
dir_util.remove_tree(base_dir, self.verbose, self.dry_run) |
384 |
|
385 |
|
386 |
|
387 |
class InstallLocal(Command): |
388 |
|
389 |
""" |
390 |
A new install command to just link (or copy, on non-POSIX systems) |
391 |
the extension modules to the top directory so that Thuban can be run |
392 |
directly from the source dir. |
393 |
""" |
394 |
|
395 |
description =\ |
396 |
"Create some symlinks so you can run thuban from the source directory" |
397 |
|
398 |
user_options = [ |
399 |
('skip-build', None, "skip the build steps"), |
400 |
] |
401 |
|
402 |
def initialize_options (self): |
403 |
self.extensions = None |
404 |
self.build_dir = None |
405 |
self.skip_build = None |
406 |
|
407 |
def finalize_options (self): |
408 |
self.set_undefined_options("install", |
409 |
("build_lib", "build_dir"), |
410 |
('skip_build', 'skip_build')) |
411 |
self.extensions = self.distribution.ext_modules |
412 |
|
413 |
def run(self): |
414 |
# Make sure we have built everything we need first |
415 |
self.build() |
416 |
|
417 |
# now do the work. Simply link or copy the Lib dir |
418 |
libdir = os.path.join(self.build_dir, "Lib") |
419 |
if os.name == "posix": |
420 |
# on posix, just link the Lib dir |
421 |
self.link_dir(libdir, "Lib") |
422 |
else: |
423 |
self.copy_tree(libdir, "Lib") |
424 |
|
425 |
def link_dir(self, src, dest): |
426 |
"""Create a symbolic link dest pointing to src""" |
427 |
if self.verbose: |
428 |
self.announce("symlinking %s -> %s" % (src, dest)) |
429 |
if self.dry_run: |
430 |
return |
431 |
|
432 |
if not (os.path.exists(dest) and os.path.samefile(src, dest)): |
433 |
os.symlink(src, dest) |
434 |
|
435 |
def build (self): |
436 |
if not self.skip_build: |
437 |
if self.distribution.has_pure_modules(): |
438 |
self.run_command('build_py') |
439 |
if self.distribution.has_ext_modules(): |
440 |
self.run_command('build_ext') |
441 |
|
442 |
|
443 |
|
444 |
class thuban_build_py(build_py): |
445 |
|
446 |
""" |
447 |
A new build_py that can deal with both packages and modules in one |
448 |
distribution. |
449 |
""" |
450 |
|
451 |
def run(self): |
452 |
"""The same the as the original in build_py revision 1.33 except |
453 |
that this allows both packages and modules to be in one |
454 |
distribution |
455 |
""" |
456 |
if not self.py_modules and not self.packages: |
457 |
return |
458 |
|
459 |
# Now we're down to two cases: 'py_modules' only and 'packages' only. |
460 |
if self.py_modules: |
461 |
self.build_modules() |
462 |
if self.packages: |
463 |
self.build_packages() |
464 |
|
465 |
self.byte_compile(self.get_outputs(include_bytecode=0)) |
466 |
|
467 |
def find_modules (self): |
468 |
"""Thuban specific version of build_py.find_modules. Unlike the |
469 |
original version, we assume that the modules in self.py_modules |
470 |
can contain directories and are all to be placed into the same |
471 |
subdirectory, Lib, in the build directory. This is achieved by |
472 |
returning the modules as a list (package, module, filename) |
473 |
where package is 'Lib', module is the basename of the module name |
474 |
and filename is the filename relative to the package root. |
475 |
""" |
476 |
modules = [] |
477 |
for module in self.py_modules: |
478 |
module_base = os.path.basename(module) |
479 |
module_file = module + ".py" |
480 |
if not self.check_module(module, module_file): |
481 |
continue |
482 |
|
483 |
modules.append(("Lib", module_base, module_file)) |
484 |
return modules |
485 |
|
486 |
def find_all_modules (self): |
487 |
# same as find_all_modules of the original build_py command |
488 |
# (rev. 1.33) but handle installations with both modules and |
489 |
# packages. Needed here so tha the get_outputs works correctly |
490 |
modules = [] |
491 |
if self.py_modules: |
492 |
modules.extend(self.find_modules()) |
493 |
if self.packages: |
494 |
for package in self.packages: |
495 |
package_dir = self.get_package_dir(package) |
496 |
m = self.find_package_modules(package, package_dir) |
497 |
modules.extend(m) |
498 |
|
499 |
return modules |
500 |
|
501 |
|
502 |
|
503 |
class ThubanInstall(install): |
504 |
|
505 |
""" |
506 |
Thuban specific install command. |
507 |
|
508 |
Extend the standard install command to symlink the installed script |
509 |
to $prefix/bin/ |
510 |
""" |
511 |
|
512 |
user_options = install.user_options[:] |
513 |
user_options.extend([("do-symlink", None, |
514 |
"Create a symlink to the script in <prefix>/bin." |
515 |
"(default on posix systems and only relevant there)"), |
516 |
|
517 |
("extra-files", None, |
518 |
"List of filenames or (src, dest) pairs describing " |
519 |
" extra files to install " |
520 |
"(can only be set from witin setup.py"), |
521 |
]) |
522 |
|
523 |
boolean_options = install.boolean_options[:] |
524 |
boolean_options.append("do-symlink") |
525 |
|
526 |
def initialize_options(self): |
527 |
self.do_symlink = None |
528 |
self.extra_files = [] |
529 |
install.initialize_options(self) |
530 |
|
531 |
def finalize_options(self): |
532 |
if self.do_symlink is None: |
533 |
if os.name == "posix": |
534 |
self.do_symlink = 1 |
535 |
else: |
536 |
self.do_symlink = 0 |
537 |
install.finalize_options(self) |
538 |
|
539 |
def run(self): |
540 |
install.run(self) |
541 |
for item in self.extra_files: |
542 |
if type(item) == TupleType: |
543 |
src, dest = item |
544 |
else: |
545 |
src = dest = item |
546 |
self.copy_file(convert_path(src), |
547 |
os.path.join(self.root, convert_path(dest))) |
548 |
|
549 |
if os.name == "posix" and self.do_symlink: |
550 |
install_scripts = self.install_scripts |
551 |
if self.root: |
552 |
install_scripts = install_scripts[len(self.root):] |
553 |
scriptfile = os.path.join(install_scripts, "thuban.py") |
554 |
bindir = os.path.join(self.prefix, "bin") |
555 |
if self.root: |
556 |
bindir = change_root(self.root, bindir) |
557 |
binfile = os.path.join(bindir, "thuban") |
558 |
self.mkpath(bindir) |
559 |
self.link_file(scriptfile, binfile) |
560 |
|
561 |
def link_file(self, src, dest): |
562 |
"""Create a symbolic link dest pointing to src. |
563 |
|
564 |
Unlike the symlink variant of the command object's copy_file |
565 |
method, this method even performs the link if src doesn't exist. |
566 |
This is useful when installing with an alternat root directory""" |
567 |
if self.verbose: |
568 |
self.announce("symlinking %s -> %s" % (src, dest)) |
569 |
if self.dry_run: |
570 |
return |
571 |
|
572 |
if not os.path.exists(dest): |
573 |
os.symlink(src, dest) |
574 |
|
575 |
|
576 |
def get_outputs (self): |
577 |
outputs = install.get_outputs(self) |
578 |
for item in self.extra_files: |
579 |
if type(item) == TupleType: |
580 |
src, dest = item |
581 |
else: |
582 |
src = dest = item |
583 |
outputs.append(os.path.join(self.root, convert_path(dest))) |
584 |
if os.name == "posix" and self.do_symlink: |
585 |
bindir = os.path.join(self.prefix, "bin") |
586 |
if self.root: |
587 |
bindir = change_root(self.root, bindir) |
588 |
binfile = os.path.join(bindir, "thuban") |
589 |
outputs.append(binfile) |
590 |
return outputs |
591 |
|
592 |
|
593 |
bdist_rpm_prep_script = ''' |
594 |
%setup |
595 |
cp extensions/pyshapelib/{README,README.pyshapelib} |
596 |
cp extensions/pyshapelib/{COPYING,COPYING.pyshapelib} |
597 |
cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection} |
598 |
''' |
599 |
|
600 |
|
601 |
|
602 |
class thuban_bdist_rpm(bdist_rpm): |
603 |
|
604 |
"""Thuban specific RPM distribution command""" |
605 |
|
606 |
def initialize_options(self): |
607 |
# create the prep script for the spec-file |
608 |
open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script) |
609 |
|
610 |
bdist_rpm.initialize_options(self) |
611 |
|
612 |
|
613 |
class bdist_inno(Command): |
614 |
|
615 |
"""Command to create a windows installer with Inno Setup""" |
616 |
|
617 |
description = "Create a windows installer with Inno Setup" |
618 |
|
619 |
user_options = [ |
620 |
('skip-build', None, "skip the build steps"), |
621 |
('bdist-dir=', None, |
622 |
"temporary directory for creating the distribution"), |
623 |
('run-inno', None, |
624 |
"Run inno-setup to create the installer. On by default on nt"), |
625 |
('iss-name', None, |
626 |
"The name of the iss file to generate. " |
627 |
"Shouldn't contain directories"), |
628 |
|
629 |
# Parameters for the Inno Setup script |
630 |
('copyright', None, "Copyright notice for the Inno Setup file"), |
631 |
('default-dir-name', None, |
632 |
"Default installation directory. Defaults to '{pf}\\<name>'"), |
633 |
('default-group-name', None, |
634 |
"Default program group name. Defaults to <name>'"), |
635 |
("license-file", None, "File containing the license."), |
636 |
("output-basename", None, |
637 |
"Base filename for the Inno Setup output " |
638 |
"(defaults to <name>-<version>-<issrevision>)."), |
639 |
("iss-revision", None, |
640 |
"revision of the generated installer of the package version"), |
641 |
|
642 |
("icons-entries", None, |
643 |
"List if InnoIconItems " |
644 |
"(this can only be set from inside the setup.py script)"), |
645 |
] |
646 |
|
647 |
boolean_options = ["do-symlink"] |
648 |
|
649 |
def initialize_options(self): |
650 |
self.skip_build = 0 |
651 |
self.bdist_dir = None |
652 |
self.run_inno = None |
653 |
self.iss_name = None |
654 |
self.copyright = "" |
655 |
self.default_dir_name = None |
656 |
self.default_group_name = None |
657 |
self.license_file = None |
658 |
self.output_basename = None |
659 |
self.iss_revision = None |
660 |
self.icons_entries = [] |
661 |
|
662 |
def finalize_options(self): |
663 |
self.set_undefined_options("install", |
664 |
('skip_build', 'skip_build')) |
665 |
if self.bdist_dir is None: |
666 |
bdist_base = self.get_finalized_command('bdist').bdist_base |
667 |
self.bdist_dir = os.path.join(bdist_base, 'inno') |
668 |
|
669 |
if self.run_inno is None: |
670 |
self.run_inno = os.name == "nt" |
671 |
|
672 |
name = self.distribution.get_name() |
673 |
if self.iss_name is None: |
674 |
self.iss_name = name + '.iss' |
675 |
|
676 |
if self.default_dir_name is None: |
677 |
self.default_dir_name = "{pf}\\" + name |
678 |
if self.default_group_name is None: |
679 |
self.default_group_name = name |
680 |
|
681 |
if self.iss_revision is None: |
682 |
self.iss_revision = 0 |
683 |
if self.output_basename is None: |
684 |
self.output_basename = "%s-%s-%d" \ |
685 |
% (name, self.distribution.get_version(), |
686 |
self.iss_revision) |
687 |
|
688 |
def run(self, install_options = None): |
689 |
"""Execute the command. install_options if given, should be a |
690 |
directory of additional options to set in the install step""" |
691 |
# Obviously have to build before we can install |
692 |
if not self.skip_build: |
693 |
self.run_command('build') |
694 |
|
695 |
# Install in a temporary directory |
696 |
install = self.reinitialize_command('install') |
697 |
install.root = self.bdist_dir |
698 |
if install_options is not None: |
699 |
for key, value in install_options.items(): |
700 |
setattr(install, key, value) |
701 |
if os.name != 'nt': |
702 |
# Must force install to use the 'nt' scheme; |
703 |
install.select_scheme('nt') |
704 |
|
705 |
self.announce("installing to %s" % self.bdist_dir) |
706 |
install.ensure_finalized() |
707 |
install.run() |
708 |
|
709 |
# Create the iss file |
710 |
iss_file = os.path.join(self.bdist_dir, self.iss_name) |
711 |
self.execute(write_file, (iss_file, self.generate_iss()), |
712 |
"Create Inno Setup script file %s" % iss_file) |
713 |
|
714 |
# and invoke |
715 |
if self.run_inno: |
716 |
self.spawn(["iscc", iss_file]) |
717 |
|
718 |
def generate_iss(self): |
719 |
"""Return the contents of the iss file as list of strings, one |
720 |
string per line""" |
721 |
|
722 |
# first, turn the icons entries into a more usable form |
723 |
icons = {} |
724 |
for item in self.icons_entries: |
725 |
icons[item.filename] = item |
726 |
|
727 |
iss = [] |
728 |
|
729 |
name = self.distribution.get_name() |
730 |
iss.extend(["[Setup]", |
731 |
"AppName=" + name, |
732 |
"AppVerName=" + name + " "+self.distribution.get_version(), |
733 |
"DefaultDirName=" + self.default_dir_name, |
734 |
"DefaultGroupName=" + self.default_group_name, |
735 |
]) |
736 |
if self.copyright: |
737 |
iss.append("AppCopyright=" + self.copyright) |
738 |
if self.license_file: |
739 |
iss.append("LicenseFile=" + self.license_file) |
740 |
|
741 |
iss.append("OutputBasefilename=" + self.output_basename) |
742 |
|
743 |
iss.append("") |
744 |
iss.append("[Files]") |
745 |
|
746 |
install = self.get_finalized_command("install") |
747 |
install_scripts = self.get_finalized_command("install_scripts") |
748 |
script_files = install_scripts.get_outputs() |
749 |
prefixlen = len(self.bdist_dir) + len(os.sep) |
750 |
for filename in install.get_outputs(): |
751 |
filename = filename[prefixlen:] |
752 |
icon = icons.get(filename) |
753 |
dirname = os.path.dirname(filename) |
754 |
if os.name != "nt": |
755 |
# change the separators to \ on non-windos systems |
756 |
filename = string.join(string.split(filename, os.sep), "\\") |
757 |
dirname = string.join(string.split(dirname, os.sep), "\\") |
758 |
line = 'Source: "%s"' % filename |
759 |
if icon is not None: |
760 |
# install it as defined in the icon object |
761 |
backslash = string.rfind(icon.install_name, "\\") |
762 |
if backslash >= 0: |
763 |
dirname = icon.install_name[:backslash] |
764 |
basename = icon.install_name[backslash + 1:] |
765 |
else: |
766 |
dirname = "" |
767 |
basename = icon.install_name |
768 |
line = '%s; DestDir: "%s"; DestName: "%s"' % (line, dirname, |
769 |
basename) |
770 |
else: |
771 |
line = line + '; DestDir: "{app}\\%s"' % (dirname) |
772 |
iss.append(line) |
773 |
|
774 |
iss.append("") |
775 |
iss.append("[Icons]") |
776 |
for icon in self.icons_entries: |
777 |
line = 'Name: "{group}\\%s"; Filename: "%s";' \ |
778 |
% (icon.title, icon.install_name) |
779 |
iss.append(line) |
780 |
|
781 |
return iss |
782 |
|
783 |
|
784 |
class InnoIconItem: |
785 |
|
786 |
"""Describe one item for the start menu for the Inno Setup installer""" |
787 |
|
788 |
def __init__(self, filename, title, install_name = None): |
789 |
self.filename = filename |
790 |
self.title = title |
791 |
if install_name is not None: |
792 |
self.install_name = install_name |
793 |
else: |
794 |
self.install_name = filename |
795 |
|
796 |
|
797 |
class thuban_bdist_inno(bdist_inno): |
798 |
|
799 |
"""Thuban specific Inno Setup stuff""" |
800 |
|
801 |
def run(self): |
802 |
install_options = { |
803 |
"prefix": ".", |
804 |
"install_scripts": "$base", |
805 |
"warn_dir": 0, |
806 |
"extra_files": ["COPYING", "Lib/proj.dll"], |
807 |
} |
808 |
# don't make a symlink because we're simulating windows, so |
809 |
# that we can generate the iss-file even on Linux |
810 |
install_options["do_symlink"] = 0 |
811 |
bdist_inno.run(self, install_options) |
812 |
|
813 |
|
814 |
# |
815 |
# Run the script |
816 |
# |
817 |
|
818 |
|
819 |
long_description = """\ |
820 |
Thuban is a viewer for geographic data written in Python |
821 |
""" |
822 |
|
823 |
setup(name = "Thuban", |
824 |
version = "0.1.1", |
825 |
description = "Geographic data viewer", |
826 |
long_description = long_description, |
827 |
licence = "GPL", |
828 |
author = "Intevation GmbH", |
829 |
author_email = "[email protected]", |
830 |
url = "ftp:intevation.de/", |
831 |
|
832 |
scripts = ["thuban.py"], |
833 |
packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"], |
834 |
ext_modules = extensions, |
835 |
py_modules = py_modules, |
836 |
data_files = data_files, |
837 |
|
838 |
# defaults for the install command |
839 |
options = {"install": |
840 |
# prefix defaults to python's prefix normally |
841 |
{"prefix": prefix, |
842 |
# make sure both libs and scripts are installed in the |
843 |
# same directory. |
844 |
"install_lib": "$base/thuban", |
845 |
"install_scripts": "$base/thuban", |
846 |
"install_data": "$base/thuban", |
847 |
|
848 |
# Don't print warning messages about the lib dir not |
849 |
# being on Python's path. The libraries are Thuban |
850 |
# specific and are installed just for Thuban. They'll |
851 |
# be automatically on Python's path when Thuban is run |
852 |
"warn_dir": 0, |
853 |
}, |
854 |
"bdist_inno": |
855 |
{"icons_entries": [InnoIconItem(".\\thuban.py", |
856 |
"Start Thuban", |
857 |
"{app}\\thuban.pyw")], |
858 |
"license_file": "COPYING", |
859 |
} |
860 |
}, |
861 |
cmdclass = {"build_py": thuban_build_py, |
862 |
"install_local": InstallLocal, |
863 |
"install": ThubanInstall, |
864 |
"bdist_rpm": thuban_bdist_rpm, |
865 |
"bdist_inno": thuban_bdist_inno, |
866 |
"data_dist": data_dist |
867 |
}) |
868 |
|
869 |
|