4 from gdcmVersion import *
6 print "gdcmVersion not imported"
8 def BuildInstallOrPreinstallPath(DirName, FileName = None):
9 # Builds a path to the DirName directory. This should work both when:
10 # - the package is properly installed in which case DirName is a subdir
12 # - when in pre-installation mode (basically inside a CVS hierarchy)
13 # in which case DirName and the package itself lie at the same
15 # In both cases we need to express the full path to DirName relatively
16 # to the path to this __init__.py. For this we rely on __path__ variable.
17 # In order to make sure we got the correct Path, we check for the
18 # existence of FileName if it is setted otherwise for the existence of the
20 InstallModePath = os.path.join(__path__[0], DirName + "/")
22 if os.path.isfile(os.path.join(InstallModePath, FileName)):
23 return InstallModePath
25 if os.path.isdir(InstallModePath):
26 return InstallModePath
28 PreInstallModePath = os.path.join(__path__[0], "..", DirName + "/")
30 if os.path.isfile(os.path.join(PreInstallModePath, FileName)):
31 return PreInstallModePath
33 if os.path.isdir(PreInstallModePath):
34 return PreInstallModePath
37 ### Setup the path to the dictionaries. WARNING: this needs to be done
38 # BEFORE importation of the shadow classes generated by swig as found
39 # in gdcm, since the dynamic library loads the standard dictionary
40 # when dynamically loaded.
41 # We consider we succefully found the dictionaries path when we encounter
42 # the standard dictionary i.e. the file dicomV3.dic.
45 ### First consider the environnement variable.
46 os.environ["GDCM_DICT_PATH"]
47 if not os.path.isfile(os.path.join(os.environ["GDCM_DICT_PATH"],
51 Path = BuildInstallOrPreinstallPath("Dicts", "dicomV3.dic")
53 print "Path to dictionaries is mandatory. Exiting"
55 os.environ["GDCM_DICT_PATH"] = Path
56 GDCM_DICT_PATH = os.environ["GDCM_DICT_PATH"]
58 ### Set up the path to the data images for the demos.
59 if os.environ["GDCM_DATA_PATH"]:
60 GDCM_DATA_PATH = BuildInstallOrPreinstallPath(os.environ["GDCM_DATA_PATH"],
63 GDCM_DATA_PATH = BuildInstallOrPreinstallPath("Test", "test.acr")
64 if not GDCM_DATA_PATH:
65 print "GDCM_DATA_PATH is not setup properly: unfound Test directory"
67 ### Set up the path to the data images of the test suite.
68 GDCM_TEST_DATA_PATH = BuildInstallOrPreinstallPath("gdcmData")
70 ### Import the swig generated shadow classes.
75 raise ImportError, "gdcm extension not imported."
77 ### Expose only the necessary stuff
78 gdcmGlobal = gdcm.gdcmGlobal
79 gdcmDictSet = gdcm.gdcmDictSet
80 gdcmDicomDir = gdcm.gdcmDicomDir
81 gdcmHeader = gdcm.gdcmHeader
82 gdcmHeaderHelper = gdcm.gdcmHeaderHelper
83 gdcmFile = gdcm.gdcmFile
85 gdcmDicomDirMeta = gdcm.gdcmDicomDirMeta
86 gdcmDicomDirPatient = gdcm.gdcmDicomDirPatient
87 gdcmDicomDirStudy = gdcm.gdcmDicomDirStudy
88 gdcmDicomDirSerie = gdcm.gdcmDicomDirSerie
89 gdcmDicomDirImage = gdcm.gdcmDicomDirImage
91 def GetPubDictEntryNames():
92 return gdcmGlobal.GetDicts().GetPubDictEntryNames()
94 def GetPubDictEntryNamesByCategory():
95 return gdcmGlobal.GetDicts().GetPubDictEntryNamesByCategory()