]> Creatis software - gdcm.git/blobdiff - gdcmPython/__init__.py
* gdcmPython/__init__.py doesn't crash anymore when running in
[gdcm.git] / gdcmPython / __init__.py
index f454cdb11588aea64801f45d87923e65654962ad..34ce06f7522ea717c194369e76944213e7dc525a 100644 (file)
@@ -8,54 +8,56 @@ import os, sys
 #   the standard dictionary i.e. the file dicomV3.dic.
 
 try:
-       ### First consider the environnement variable.
-       os.environ["GDCM_DICT_PATH"]
-       if not os.path.isfile(os.path.join(os.environ["GDCM_DICT_PATH"],
-                                          "dicomV3.dic")):
-               raise KeyError
+   ### First consider the environnement variable.
+   os.environ["GDCM_DICT_PATH"]
+   if not os.path.isfile(os.path.join(os.environ["GDCM_DICT_PATH"],
+                                      "dicomV3.dic")):
+      raise KeyError
 except KeyError:
-       # When environnement variable is unavailable assume the package was
-       # properly installed i.e. the layout is such that the directory containing
-       # the dictionaries is BELOW (the root is at the top) the current file.
-       # Note: when importing this __init__ file the pathes are relative to the
-       #       invocation directory. In order to get them relative to the package
-       #       (or more simply to this file) we rely on the __path__ variable.
-       InstallModePath = os.path.join(__path__[0], "Dicts/")
-       if os.path.isfile(os.path.join(InstallModePath, "dicomV3.dic")):
-               os.environ["GDCM_DICT_PATH"] = InstallModePath
-               PreInstallModePath = None
-       else:
-               # When both environnement variable and proper package installation 
-               # strategy fail we eventually consider the pre-installation mode
-               # i.e. when developpers are toying in a CVS tree. In this case
-               # the layout is such that the directory containing the dictionaries is
-               # ABOVE (the root is at the top) the current directory.
-               PreInstallModePath = os.path.join(__path__[0], "..", "Dicts/")
-               if os.path.isfile(os.path.join(PreInstallModePath, "dicomV3.dic")):
-                       os.environ["GDCM_DICT_PATH"] = PreInstallModePath
-                       InstallModePath = None
-               else:
-                       print "Unfound gdcm dictionaries path"
-                       sys.exit(1)
+   # When environnement variable is unavailable assume the package was
+   # properly installed i.e. the layout is such that the directory containing
+   # the dictionaries is BELOW (the root is at the top) the current file.
+   # Note: when importing this __init__ file the pathes are relative to the
+   #       invocation directory. In order to get them relative to the package
+   #       (or more simply to this file) we rely on the __path__ variable.
+   InstallModePath = os.path.join(__path__[0], "Dicts/")
+   if os.path.isfile(os.path.join(InstallModePath, "dicomV3.dic")):
+      os.environ["GDCM_DICT_PATH"] = InstallModePath
+      PreInstallModePath = None
+   else:
+      # When both environnement variable and proper package installation 
+      # strategy fail we eventually consider the pre-installation mode
+      # i.e. when developpers are toying in a CVS tree. In this case
+      # the layout is such that the directory containing the dictionaries is
+      # ABOVE (the root is at the top) the current directory.
+      PreInstallModePath = os.path.join(__path__[0], "..", "Dicts/")
+      if os.path.isfile(os.path.join(PreInstallModePath, "dicomV3.dic")):
+         os.environ["GDCM_DICT_PATH"] = PreInstallModePath
+         InstallModePath = None
+      else:
+         print "Unfound gdcm dictionaries path"
+         sys.exit(1)
 
 ### Set up the path to the data images (for the test suite and the demo
 #   examples). As for GDCM_DICT_PATH we offer both proper python package
 #   installation scheme and the pre-install mode (see above).
-if InstallModePath:
-       GDCM_DATA_PATH = os.path.join(__path__[0], "Data")
+InstallModePath = os.path.join(__path__[0], "Data")
+if os.path.isfile(os.path.join(InstallModePath, "test.acr")):
+   os.environ["GDCM_DATA_PATH"] = InstallModePath
 else:
-       if PreInstallModePath:
-               GDCM_DATA_PATH = os.path.join(__path__[0], "..","Data")
-       else:
-               print "Unfound data path"
-               sys.exit(1)
+   PreInstallModePath = os.path.join(__path__[0], "..", "Data")
+   if os.path.isfile(os.path.join(PreInstallModePath, "test.acr")):
+      os.environ["GDCM_DATA_PATH"] = PreInstallModePath
+   else:
+      print "Unfound data path"
+      sys.exit(1)
 
 ### Import the swig generated shadow classes.
 try:
-       import gdcm
+   import gdcm
 except ImportError,e:
-       print e
-       raise ImportError, "gdcm extension not imported."
+   print e
+   raise ImportError, "gdcm extension not imported."
 
 ### Expose only the necessary stuff
 gdcmHeader = gdcm.gdcmHeader