3 def BuildInstallOrPreinstallPath(DirName, FileName = None):
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 if it is setted otherwise for the existence of the
15 InstallModePath = os.path.join(__path__[0], DirName + "/")
17 if os.path.isfile(os.path.join(InstallModePath, FileName)):
18 return InstallModePath
20 if os.path.isdir(InstallModePath):
21 return InstallModePath
23 PreInstallModePath = os.path.join(__path__[0], "..", DirName + "/")
25 if os.path.isfile(os.path.join(PreInstallModePath, FileName)):
26 return PreInstallModePath
28 if os.path.isdir(PreInstallModePath):
29 return PreInstallModePath
32 ### Setup the path to the dictionaries. WARNING: this needs to be done
33 # BEFORE importation of the shadow classes generated by swig as found
34 # in gdcm, since the dynamic library loads the standard dictionary
35 # when dynamically loaded.
36 # We consider we succefully found the dictionaries path when we encounter
37 # the standard dictionary i.e. the file dicomV3.dic.
40 ### First consider the environnement variable.
41 os.environ["GDCM_DICT_PATH"]
42 if not os.path.isfile(os.path.join(os.environ["GDCM_DICT_PATH"],
46 Path = BuildInstallOrPreinstallPath("Dicts", "dicomV3.dic")
48 print "Path to dictionaries is mandatory. Exiting"
50 os.environ["GDCM_DICT_PATH"] = Path
52 ### Set up the path to the data images for the demos.
53 GDCM_DATA_PATH = BuildInstallOrPreinstallPath("Test", "test.acr")
54 if not GDCM_DATA_PATH:
55 print "GDCM_DATA_PATH is not setup properly: unfound Test directory"
57 ### Set up the path to the data images of the test suite.
58 GDCM_TEST_DATA_PATH = BuildInstallOrPreinstallPath("gdcmData")
60 ### Import the swig generated shadow classes.
65 raise ImportError, "gdcm extension not imported."
67 ### Expose only the necessary stuff
68 gdcmHeader = gdcm.gdcmHeader
69 gdcmDictSet = gdcm.gdcmDictSet
70 gdcmFile = gdcm.gdcmFile
72 def GetPubDictTagNames():
73 return gdcm.cvar.gdcmGlob.GetDicts().GetPubDictTagNames()
75 def GetPubDictTagNamesByCategory():
76 return gdcm.cvar.gdcmGlob.GetDicts().GetPubDictTagNamesByCategory()