3 def BuildInstallOrPreinstallPath(DirName, FileName):
4 # Builds a path to the DirName directory. This should work both when:
5 # - the package is properly installed in which case DirName is a subdir
7 # - when in pre-installation mode (basically inside a CVS hierarchy)
8 # in which case DirName and the package itself lie at the same
10 # In both cases we need to express the full path to DirName relatively
11 # to the path to this __init__.py. For this we rely on __path__ variable.
12 # In order to make sure we got the correct Path, we check for the
13 # existence of FileName.
14 InstallModePath = os.path.join(__path__[0], DirName + "/")
15 if os.path.isfile(os.path.join(InstallModePath, FileName)):
16 return InstallModePath
17 PreInstallModePath = os.path.join(__path__[0], "..", DirName + "/")
18 if os.path.isfile(os.path.join(PreInstallModePath, FileName)):
19 return PreInstallModePath
22 ### Setup the path to the dictionaries. WARNING: this needs to be done
23 # BEFORE importation of the shadow classes generated by swig as found
24 # in gdcm, since the dynamic library loads the standard dictionary
25 # when dynamically loaded.
26 # We consider we succefully found the dictionaries path when we encounter
27 # the standard dictionary i.e. the file dicomV3.dic.
30 ### First consider the environnement variable.
31 os.environ["GDCM_DICT_PATH"]
32 if not os.path.isfile(os.path.join(os.environ["GDCM_DICT_PATH"],
36 Path = BuildInstallOrPreinstallPath("Dicts", "dicomV3.dic")
38 print "Path to dictionaries is mandatory. Exiting"
40 os.environ["GDCM_DICT_PATH"] = Path
42 ### Set up the path to the data images for the demos.
43 GDCM_DATA_PATH = BuildInstallOrPreinstallPath("Test", "test.acr")
44 if not GDCM_DATA_PATH:
45 print "GDCM_DATA_PATH is not setup properly: unfound Test directory"
47 ### Set up the path to the data images of the test suite.
48 GDCM_TEST_DATA_PATH = BuildInstallOrPreinstallPath("gdcmData", "test.acr")
50 ### Import the swig generated shadow classes.
55 raise ImportError, "gdcm extension not imported."
57 ### Expose only the necessary stuff
58 gdcmHeader = gdcm.gdcmHeader
59 gdcmDictSet = gdcm.gdcmDictSet
60 gdcmFile = gdcm.gdcmFile
62 def GetPubDictTagNames():
63 return gdcm.cvar.gdcmGlob.GetDicts().GetPubDictTagNames()
65 def GetPubDictTagNamesByCategory():
66 return gdcm.cvar.gdcmGlob.GetDicts().GetPubDictTagNamesByCategory()