File: itkbase.py.in

package info (click to toggle)
insighttoolkit 3.20.1%2Bgit20120521-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 80,672 kB
  • ctags: 85,253
  • sloc: cpp: 458,133; ansic: 196,222; fortran: 28,000; python: 3,839; tcl: 1,811; sh: 1,184; java: 583; makefile: 428; csh: 220; perl: 193; xml: 20
file content (76 lines) | stat: -rw-r--r-- 2,534 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""InsightToolkit support module to help load its packages."""
import sys,os

# Get the path to the directory containing this script.  It may be
# used to set pkgdir below, depending on how this script is
# configured.
if __name__ == '__main__':
    selfpath = os.path.abspath(sys.path[0] or os.curdir)
else:
    selfpath = os.path.abspath(os.path.dirname(__file__))

# The directory containing the binary ITK python wrapper libraries.
pkgdir = @ITK_CSWIG_PACKAGE_DIR@

# Python "help(sys.setdlopenflags)" states:
#
# setdlopenflags(...)
#     setdlopenflags(n) -> None
#
#     Set the flags that will be used for dlopen() calls. Among other
#     things, this will enable a lazy resolving of symbols when
#     importing a module, if called as sys.setdlopenflags(0) To share
#     symbols across extension modules, call as
#
#     sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)
#
# GCC 3.x depends on proper merging of symbols for RTTI:
#   http://gcc.gnu.org/faq.html#dso
#
# The Python setup.py states that the "dl" module
# requires "sizeof(int) == sizeof(long) == sizeof(char*)".
# Therefore the dl module is missing on 64-bit platforms.
# Since RTLD_NOW==0x002 and RTLD_GLOBAL==0x100 very commonly
# we will just guess that the proper flags are 0x102 when there
# is no dl module.

def preimport():
  """Called by InsightToolkit packages before loading a C module."""
  # Save the current dlopen flags and set the ones we need.
  try:
    import dl
    newflags = dl.RTLD_NOW|dl.RTLD_GLOBAL
  except:
    newflags = 0x102  # No dl module, so guess (see above).
  try:
    oldflags = sys.getdlopenflags()
    sys.setdlopenflags(newflags)
  except:
    oldflags = None
  # Save the current working directory and change to that containing
  # the python wrapper libraries.  They have '.' in their rpaths, so
  # they will find the libraries on which they depend.
  cwd = os.getcwd()
  os.chdir(pkgdir)
  # Add the binary package directory to the python module search path.
  sys.path.insert(1, pkgdir)
  return [cwd, oldflags]

def postimport(data):
  """Called by InsightToolkit packages after loading a C module."""
  # Remove the binary package directory to the python module search path.
  sys.path.remove(pkgdir)
  # Restore the original working directory.
  os.chdir(data[0])
  # Restore the original dlopen flags.
  try:
    sys.setdlopenflags(data[1])
  except:
    pass

# Default location for test output
defaultTestRoot = @ITK_CSWIG_TEST_ROOT@

# Default location for test input
defaultDataRoot = @ITK_CSWIG_DATA_ROOT@