X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=gdcmPython%2F__init__.py;h=4b2b8cc6ee5383b997132f2303161bf3437c5188;hb=a0091d68a2eaa1a0c128f962030bb6c45cc0c366;hp=bf7fe97d768210ebd73c8c4b00a4d7de1d40c428;hpb=1988dee6507ec70166b38c7e0cac6c1e9c18351e;p=gdcm.git diff --git a/gdcmPython/__init__.py b/gdcmPython/__init__.py index bf7fe97d..4b2b8cc6 100644 --- a/gdcmPython/__init__.py +++ b/gdcmPython/__init__.py @@ -1,7 +1,41 @@ import os, sys +try: + from gdcmVersion import * +except: + print "gdcmVersion not imported" + +def BuildInstallOrPreinstallPath(DirName, FileName = None): + # Builds a path to the DirName directory. This should work both when: + # - the package is properly installed in which case DirName is a subdir + # of the package, + # - when in pre-installation mode (basically inside a CVS hierarchy) + # in which case DirName and the package itself lie at the same + # filesystem level. + # In both cases we need to express the full path to DirName relatively + # to the path to this __init__.py. For this we rely on __path__ variable. + # In order to make sure we got the correct Path, we check for the + # existence of FileName if it is setted otherwise for the existence of the + # DirName. + InstallModePath = os.path.join(__path__[0], DirName + "/") + if(FileName): + if os.path.isfile(os.path.join(InstallModePath, FileName)): + return InstallModePath + else: + if os.path.isdir(InstallModePath): + return InstallModePath + + PreInstallModePath = os.path.join(__path__[0], "..", DirName + "/") + if(FileName): + if os.path.isfile(os.path.join(PreInstallModePath, FileName)): + return PreInstallModePath + else: + if os.path.isdir(PreInstallModePath): + return PreInstallModePath + return None + ### Setup the path to the dictionaries. WARNING: this needs to be done -# BEFORE importation of the shadow classse generated by swig as found +# BEFORE importation of the shadow classes generated by swig as found # in gdcm, since the dynamic library loads the standard dictionary # when dynamically loaded. # We consider we succefully found the dictionaries path when we encounter @@ -14,43 +48,24 @@ try: "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) + Path = BuildInstallOrPreinstallPath("Dicts", "dicomV3.dic") + if not Path: + print "Path to dictionaries is mandatory. Exiting" + sys.exit(1) + os.environ["GDCM_DICT_PATH"] = Path +GDCM_DICT_PATH = os.environ["GDCM_DICT_PATH"] -### 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). -InstallModePath = os.path.join(__path__[0], "gdcmData") -if os.path.isfile(os.path.join(InstallModePath, "test.acr")): - GDCM_DATA_PATH = InstallModePath +### Set up the path to the data images for the demos. +if os.environ["GDCM_DATA_PATH"]: + GDCM_DATA_PATH = BuildInstallOrPreinstallPath(os.environ["GDCM_DATA_PATH"], + "test.acr") else: - PreInstallModePath = os.path.join(__path__[0], "..", "gdcmData") - if os.path.isfile(os.path.join(PreInstallModePath, "test.acr")): - GDCM_DATA_PATH = PreInstallModePath - else: - print "Unfound data path" - sys.exit(1) + GDCM_DATA_PATH = BuildInstallOrPreinstallPath("Test", "test.acr") +if not GDCM_DATA_PATH: + print "GDCM_DATA_PATH is not setup properly: unfound Test directory" + +### Set up the path to the data images of the test suite. +GDCM_TEST_DATA_PATH = BuildInstallOrPreinstallPath("gdcmData") ### Import the swig generated shadow classes. try: @@ -60,6 +75,21 @@ except ImportError,e: raise ImportError, "gdcm extension not imported." ### Expose only the necessary stuff -gdcmHeader = gdcm.gdcmHeader -gdcmDictSet = gdcm.gdcmDictSet -gdcmFile = gdcm.gdcmFile +gdcmGlobal = gdcm.gdcmGlobal +gdcmDictSet = gdcm.gdcmDictSet +gdcmDicomDir = gdcm.gdcmDicomDir +gdcmHeader = gdcm.gdcmHeader +gdcmHeaderHelper = gdcm.gdcmHeaderHelper +gdcmFile = gdcm.gdcmFile + +gdcmDicomDirMeta = gdcm.gdcmDicomDirMeta +gdcmDicomDirPatient = gdcm.gdcmDicomDirPatient +gdcmDicomDirStudy = gdcm.gdcmDicomDirStudy +gdcmDicomDirSerie = gdcm.gdcmDicomDirSerie +gdcmDicomDirImage = gdcm.gdcmDicomDirImage + +def GetPubDictEntryNames(): + return gdcmGlobal.GetDicts().GetPubDictEntryNames() + +def GetPubDictEntryNamesByCategory(): + return gdcmGlobal.GetDicts().GetPubDictEntryNamesByCategory()