18 |
import os |
import os |
19 |
from types import TupleType |
from types import TupleType |
20 |
from distutils.core import setup, Extension, Command |
from distutils.core import setup, Extension, Command |
21 |
from distutils.command.install import install |
from distutils.command.install import install, INSTALL_SCHEMES, subst_vars |
22 |
from distutils.command.build_py import build_py |
from distutils.command.build_py import build_py |
23 |
from distutils.command.bdist_rpm import bdist_rpm |
from distutils.command.bdist_rpm import bdist_rpm |
24 |
from distutils.file_util import write_file |
from distutils.file_util import write_file |
43 |
proj4_lib = "proj" |
proj4_lib = "proj" |
44 |
|
|
45 |
|
|
46 |
# You shpuldn't have to modify anything below here |
# You shouldn't have to modify anything below here |
47 |
################################################################### |
################################################################### |
48 |
|
|
49 |
# The installation prefix (similar to autoconf's --prefix). This is |
# The installation prefix (similar to autoconf's --prefix). This is |
50 |
# only the default value, you can override it on the command line |
# only the default value, you can override it on the command line |
51 |
# with the install command's --prefix option |
# with the install command's --prefix option. |
52 |
|
# |
53 |
|
# Note that there's a separate prefix option for the bdist_rpm |
54 |
|
# command completely independend of this one. |
55 |
prefix = "/usr/local/" |
prefix = "/usr/local/" |
56 |
|
|
57 |
|
# Whether to create the thubaninit module. You can override this |
58 |
|
# value on the commandline with the --create-init-module to the |
59 |
|
# install command. |
60 |
|
create_init_module = 1 |
61 |
|
|
62 |
# On POSIX-systems we run wxgtk-config to determine the C++-compiler |
# On POSIX-systems we run wxgtk-config to determine the C++-compiler |
63 |
# flags |
# flags |
64 |
wx_config_script = "wx-config" |
wx_config_script = "wx-config" |
94 |
# the command line with the install command's --prefix option |
# the command line with the install command's --prefix option |
95 |
prefix = r"install" |
prefix = r"install" |
96 |
|
|
97 |
|
# Whether to create the thubaninit module. You can override this |
98 |
|
# value on the commandline with the --create-init-module to the |
99 |
|
# install command. By default we don't create it under NT because we |
100 |
|
# most often run install only as part of bdist_inno where we can't |
101 |
|
# really create because it needs information only known at install |
102 |
|
# time. |
103 |
|
create_init_module = 0 |
104 |
|
|
105 |
# There doesn't seem to be an easy way to get at the wx compiler |
# There doesn't seem to be an easy way to get at the wx compiler |
106 |
# flags, so we define them here. These flags work for us with |
# flags, so we define them here. These flags work for us with |
107 |
# wxPython 2.3.1. They may have to be modified for other versions. |
# wxPython 2.3.1. They may have to be modified for other versions. |
216 |
# |
# |
217 |
|
|
218 |
extensions.append(Extension("Lib.wxproj", |
extensions.append(Extension("Lib.wxproj", |
219 |
[ext_dir + "/thuban/wxproj.cpp", |
[ext_dir + "/thuban/wxproj.cpp"], |
220 |
shp_dir + "/shpopen.c"], |
include_dirs = ([shp_dir, proj4_incdir, |
221 |
include_dirs = [shp_dir, proj4_incdir] +wx_incdirs, |
ext_dir + "/pyshapelib/"] |
222 |
|
+ wx_incdirs), |
223 |
define_macros = wx_defs, |
define_macros = wx_defs, |
224 |
library_dirs = [proj4_libdir] + wx_libdirs, |
library_dirs = [proj4_libdir] + wx_libdirs, |
225 |
libraries = [proj4_lib] + wx_libs)) |
libraries = [proj4_lib] + wx_libs)) |
230 |
|
|
231 |
extensions.append(Extension("Lib.shapelibc", |
extensions.append(Extension("Lib.shapelibc", |
232 |
[ext_dir + "/pyshapelib/shapelib_wrap.c", |
[ext_dir + "/pyshapelib/shapelib_wrap.c", |
233 |
shp_dir + "/shpopen.c"], |
shp_dir + "/shpopen.c", |
234 |
|
shp_dir + "/shptree.c"], |
235 |
|
include_dirs = [shp_dir])) |
236 |
|
extensions.append(Extension("Lib.shptree", |
237 |
|
[ext_dir + "/pyshapelib/shptreemodule.c"], |
238 |
include_dirs = [shp_dir])) |
include_dirs = [shp_dir])) |
239 |
extensions.append(Extension("Lib.dbflibc", |
extensions.append(Extension("Lib.dbflibc", |
240 |
[ext_dir + "/pyshapelib/dbflib_wrap.c", |
[ext_dir + "/pyshapelib/dbflib_wrap.c", |
519 |
return modules |
return modules |
520 |
|
|
521 |
|
|
522 |
|
thubaninit_contents = """ |
523 |
|
# This module was automatically generated by Thuban's install script |
524 |
|
'''Import this module once per program (best place is probably the file |
525 |
|
that ends up as your __main__ module) to be able to import Thuban |
526 |
|
afterwards. |
527 |
|
|
528 |
|
Usage: |
529 |
|
|
530 |
|
import thubaninit |
531 |
|
import Thuban |
532 |
|
''' |
533 |
|
import sys, os |
534 |
|
sys.path.insert(0, %(thubandir)s) |
535 |
|
|
536 |
|
# Put the Lib dir into the path. The Lib dir contains some extra Python |
537 |
|
# modules |
538 |
|
import Thuban |
539 |
|
thubandir = os.path.join(Thuban.__path__[0], '..') |
540 |
|
dir = os.path.join(thubandir, "Lib") |
541 |
|
if os.path.isdir(dir): |
542 |
|
sys.path.insert(0, dir) |
543 |
|
""" |
544 |
|
|
545 |
|
|
546 |
class ThubanInstall(install): |
class ThubanInstall(install): |
547 |
|
|
558 |
"(default on posix systems and only relevant there)"), |
"(default on posix systems and only relevant there)"), |
559 |
|
|
560 |
("extra-files", None, |
("extra-files", None, |
561 |
"List of filenames or (src, dest) pairs describing " |
"List of filenames or (src, dest) pairs describing" |
562 |
" extra files to install " |
" extra files to install " |
563 |
"(can only be set from witin setup.py"), |
"(can only be set from witin setup.py"), |
564 |
|
|
565 |
|
("create-init-module=", None, |
566 |
|
"If true, create a module in the site-packages" |
567 |
|
" directory that tweaks sys.path to let you easily" |
568 |
|
" import thuban modules from outside of thuban."), |
569 |
|
("init-module-dir=", None, |
570 |
|
"Directory in which to create the init module." |
571 |
|
" Defaults to Python's site-packages directory."), |
572 |
|
|
573 |
]) |
]) |
574 |
|
|
575 |
boolean_options = install.boolean_options[:] |
boolean_options = install.boolean_options[:] |
576 |
boolean_options.append("do-symlink") |
boolean_options.append("do-symlink") |
577 |
|
boolean_options.append("create-init-module") |
578 |
|
|
579 |
def initialize_options(self): |
def initialize_options(self): |
580 |
self.do_symlink = None |
self.do_symlink = None |
581 |
self.extra_files = [] |
self.extra_files = [] |
582 |
|
|
583 |
|
# initialize the create_init_module flag from the global |
584 |
|
# determined at runtime |
585 |
|
self.create_init_module = create_init_module |
586 |
|
self.init_module_dir = None |
587 |
install.initialize_options(self) |
install.initialize_options(self) |
588 |
|
|
589 |
def finalize_options(self): |
def finalize_options(self): |
593 |
else: |
else: |
594 |
self.do_symlink = 0 |
self.do_symlink = 0 |
595 |
install.finalize_options(self) |
install.finalize_options(self) |
596 |
|
self.expand_with_pure_python_dirs(["init_module_dir"]) |
597 |
|
|
598 |
|
def expand_with_pure_python_dirs(self, attrs): |
599 |
|
"""Expand the attributes with default values of base and platbase""" |
600 |
|
# it seems that the values for "prefix" and "exec_prefix" in |
601 |
|
# self.config_vars are the corresponding values used by the |
602 |
|
# python interpreter, so we just assign these to "base" and |
603 |
|
# "platbase". |
604 |
|
config_vars = self.config_vars.copy() |
605 |
|
config_vars["base"] = self.config_vars["prefix"] |
606 |
|
config_vars["platbase"] = self.config_vars["exec_prefix"] |
607 |
|
for attr in attrs: |
608 |
|
val = getattr(self, attr) |
609 |
|
if val is not None: |
610 |
|
if os.name == 'posix': |
611 |
|
val = os.path.expanduser(val) |
612 |
|
val = subst_vars(val, config_vars) |
613 |
|
setattr(self, attr, val) |
614 |
|
|
615 |
|
def select_scheme(self, scheme): |
616 |
|
"""Extend the inherited method to set init_module_dir""" |
617 |
|
install.select_scheme(self, scheme) |
618 |
|
# only set init_module_dir if it wasn't set by the user |
619 |
|
if self.init_module_dir is None: |
620 |
|
self.init_module_dir = INSTALL_SCHEMES[scheme]['purelib'] |
621 |
|
|
622 |
|
def convert_paths(self, *args): |
623 |
|
"""Extend the inherited method so that we can remember some filename |
624 |
|
""" |
625 |
|
# remember the installation directory before its root gets |
626 |
|
# changed |
627 |
|
self.install_lib_orig = self.install_lib |
628 |
|
apply(install.convert_paths, (self,) + args) |
629 |
|
|
630 |
def run(self): |
def run(self): |
631 |
install.run(self) |
install.run(self) |
649 |
self.mkpath(bindir) |
self.mkpath(bindir) |
650 |
self.link_file(scriptfile, binfile) |
self.link_file(scriptfile, binfile) |
651 |
|
|
652 |
|
if self.create_init_module: |
653 |
|
# create the init module |
654 |
|
initfilename = self.thuban_init_filename() |
655 |
|
if self.root: |
656 |
|
initfilename = change_root(self.root, initfilename) |
657 |
|
contents = thubaninit_contents % { |
658 |
|
"thubandir": repr(self.install_lib_orig) |
659 |
|
} |
660 |
|
self.mkpath(os.path.dirname(initfilename)) |
661 |
|
self.execute(write_file, (initfilename, split(contents, "\n")), |
662 |
|
"Create %s" % initfilename) |
663 |
|
|
664 |
def link_file(self, src, dest): |
def link_file(self, src, dest): |
665 |
"""Create a symbolic link dest pointing to src. |
"""Create a symbolic link dest pointing to src. |
666 |
|
|
675 |
if not os.path.exists(dest): |
if not os.path.exists(dest): |
676 |
os.symlink(src, dest) |
os.symlink(src, dest) |
677 |
|
|
678 |
|
def thuban_init_filename(self): |
679 |
|
"""Return the filename for the init-module""" |
680 |
|
# Since we override the normal install dirs to point to our own |
681 |
|
# prefix we have to reach into installed |
682 |
|
return self.init_module_dir + "/thubaninit.py" |
683 |
|
|
684 |
def get_outputs (self): |
def get_outputs (self): |
685 |
outputs = install.get_outputs(self) |
outputs = install.get_outputs(self) |
695 |
bindir = change_root(self.root, bindir) |
bindir = change_root(self.root, bindir) |
696 |
binfile = os.path.join(bindir, "thuban") |
binfile = os.path.join(bindir, "thuban") |
697 |
outputs.append(binfile) |
outputs.append(binfile) |
698 |
|
if self.create_init_module: |
699 |
|
initfilename = self.thuban_init_filename() |
700 |
|
if self.root: |
701 |
|
initfilename = change_root(self.root, initfilename) |
702 |
|
outputs.append(initfilename) |
703 |
return outputs |
return outputs |
704 |
|
|
705 |
|
|
706 |
|
# scripts to override some of the commands put into the spec-file by the |
707 |
|
# bdist_rpm command. |
708 |
|
|
709 |
bdist_rpm_prep_script = ''' |
bdist_rpm_prep_script = ''' |
710 |
%setup |
%setup |
711 |
cp extensions/pyshapelib/{README,README.pyshapelib} |
cp extensions/pyshapelib/{README,README.pyshapelib} |
713 |
cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection} |
cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection} |
714 |
''' |
''' |
715 |
|
|
716 |
|
bdist_rpm_install_script = ''' |
717 |
|
%(python)s setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES \ |
718 |
|
--prefix=%(prefix)s |
719 |
|
''' |
720 |
|
|
721 |
|
|
722 |
class thuban_bdist_rpm(bdist_rpm): |
class thuban_bdist_rpm(bdist_rpm): |
723 |
|
|
724 |
"""Thuban specific RPM distribution command""" |
"""Thuban specific RPM distribution command""" |
725 |
|
|
726 |
|
user_options = bdist_rpm.user_options[:] |
727 |
|
user_options.extend([("prefix=", None, "Install prefix for the RPM"), |
728 |
|
]) |
729 |
|
|
730 |
def initialize_options(self): |
def initialize_options(self): |
731 |
# create the prep script for the spec-file |
# per default, RPMs are installed in /usr |
732 |
open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script) |
self.prefix = "/usr/" |
733 |
|
|
734 |
|
# create the scripts we want to override. We actually fill them |
735 |
|
# with contents later because some values we put into those |
736 |
|
# scripts such as the python interpreter to use are only known |
737 |
|
# then. |
738 |
|
open("bdist_rpm_prep", "w").close() |
739 |
|
open("bdist_rpm_install", "w").close() |
740 |
bdist_rpm.initialize_options(self) |
bdist_rpm.initialize_options(self) |
741 |
|
|
742 |
|
def _make_spec_file(self): |
743 |
|
# create the scripts for the spec-file. Now we know the python |
744 |
|
# interpreter to use. |
745 |
|
open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script) |
746 |
|
install = bdist_rpm_install_script % {"python": self.python, |
747 |
|
"prefix": self.prefix} |
748 |
|
open("bdist_rpm_install", "w").write(install) |
749 |
|
|
750 |
|
# |
751 |
|
return bdist_rpm._make_spec_file(self) |
752 |
|
|
753 |
|
|
754 |
class bdist_inno(Command): |
class bdist_inno(Command): |
755 |
|
|
962 |
""" |
""" |
963 |
|
|
964 |
setup(name = "Thuban", |
setup(name = "Thuban", |
965 |
version = "0.1.1", |
version = "0.1.3cvs", |
966 |
description = "Geographic data viewer", |
description = "Geographic data viewer", |
967 |
long_description = long_description, |
long_description = long_description, |
968 |
licence = "GPL", |
licence = "GPL", |
969 |
author = "Intevation GmbH", |
author = "Intevation GmbH", |
970 |
author_email = "[email protected]", |
author_email = "[email protected]", |
971 |
url = "ftp:intevation.de/", |
url = "http://thuban.intevation.de/", |
972 |
|
|
973 |
scripts = ["thuban.py"], |
scripts = ["thuban.py"], |
974 |
packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"], |
packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"], |
982 |
{"prefix": prefix, |
{"prefix": prefix, |
983 |
# make sure both libs and scripts are installed in the |
# make sure both libs and scripts are installed in the |
984 |
# same directory. |
# same directory. |
985 |
"install_lib": "$base/thuban", |
"install_lib": "$base/lib/thuban", |
986 |
"install_scripts": "$base/thuban", |
"install_scripts": "$base/lib/thuban", |
987 |
"install_data": "$base/thuban", |
"install_data": "$base/lib/thuban", |
988 |
|
|
989 |
# Don't print warning messages about the lib dir not |
# Don't print warning messages about the lib dir not |
990 |
# being on Python's path. The libraries are Thuban |
# being on Python's path. The libraries are Thuban |