From: regrain Date: Thu, 17 Mar 2005 11:21:47 +0000 (+0000) Subject: * Amelioration of the Python part concerning demos X-Git-Tag: Version1.2.bp~822 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=f51f3cf0f4013935c1d93a828779e5ca285a31fc;p=gdcm.git * Amelioration of the Python part concerning demos -- BeNours --- diff --git a/gdcmPython/CMakeLists.txt b/gdcmPython/CMakeLists.txt index 21315edd..c5488ece 100644 --- a/gdcmPython/CMakeLists.txt +++ b/gdcmPython/CMakeLists.txt @@ -208,7 +208,7 @@ FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/core.py "import gdcm\n" - "GDCM_DATA_ROOT =\"${GDCM_DATA_ROOT}\"\n" + "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n" ) IF(GDCM_VTK) @@ -218,7 +218,7 @@ IF(GDCM_VTK) " from libvtkgdcmPython import *\n" "else:\n" " from vtkgdcmPython import *\n" - "GDCM_DATA_ROOT =\"${GDCM_DATA_ROOT}\"\n" + "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n" ) ENDIF(GDCM_VTK) diff --git a/gdcmPython/demo/CMakeLists.txt b/gdcmPython/demo/CMakeLists.txt index b3bde10c..f50976ab 100644 --- a/gdcmPython/demo/CMakeLists.txt +++ b/gdcmPython/demo/CMakeLists.txt @@ -33,6 +33,11 @@ ENDIF(PYTHON_EXECUTABLE) #----------------------------------------------------------------------------- # Copy all the demo directory content to the cmake bin # Without it, tests can't be launched +CONFIGURE_FILE( + ${GDCM_SOURCE_DIR}/gdcmPython/demo/gdcmConfigDemo.py.in + ${GDCM_BINARY_DIR}/gdcmPython/demo/gdcmConfigDemo.py +) + CONFIGURE_FILE( ${GDCM_SOURCE_DIR}/gdcmPython/demo/PrintFile.py.in ${GDCM_BINARY_DIR}/gdcmPython/demo/PrintFile.py diff --git a/gdcmPython/demo/PrintDicomDir.py.in b/gdcmPython/demo/PrintDicomDir.py.in index 703ee20e..4b016d43 100644 --- a/gdcmPython/demo/PrintDicomDir.py.in +++ b/gdcmPython/demo/PrintDicomDir.py.in @@ -1,15 +1,15 @@ -import sys -import os - -sys.path.append('${GDCM_BINARY_DIR}') -if os.name == 'posix': - sys.path.append('${GDCM_BINARY_DIR}/bin') -else: - sys.path.append('${GDCM_BINARY_DIR}/bin/Release') - sys.path.append('${GDCM_BINARY_DIR}/bin/Debug') - +from gdcmConfigDemo import * from gdcmPython.core import * +def PrintUse(): + print "" + print "Use :" + print "-----" + print "%s " % sys.argv[0] + print " dicomDir : path to the DICOMDIR to parse" + print "" + print "" + ### Get filename from command line or default it try: fileName = sys.argv[1] @@ -24,10 +24,10 @@ except IndexError: ### Build the DicomDir element list dicomdir = gdcm.DicomDir(fileName) if not dicomdir.IsReadable(): - print + PrintUse() raise RuntimeError,"The '%s' DicomDir is not readable with gdcm." % fileName - #sys.exit() +print "DICOMDIR -->",fileName print "##############################################################" print "## Display all the elements and their respective values" print "## found in the ", fileName, " file." diff --git a/gdcmPython/demo/PrintDict.py.in b/gdcmPython/demo/PrintDict.py.in index 82537d05..aca8f437 100644 --- a/gdcmPython/demo/PrintDict.py.in +++ b/gdcmPython/demo/PrintDict.py.in @@ -1,13 +1,4 @@ -import sys -import os - -sys.path.append('${GDCM_BINARY_DIR}') -if os.name == 'posix': - sys.path.append('${GDCM_BINARY_DIR}/bin') -else: - sys.path.append('${GDCM_BINARY_DIR}/bin/Release') - sys.path.append('${GDCM_BINARY_DIR}/bin/Debug') - +from gdcmConfigDemo import * from gdcmPython.core import * print "#####################################################################" diff --git a/gdcmPython/demo/PrintFile.py.in b/gdcmPython/demo/PrintFile.py.in index 77b1058c..007a3fa1 100644 --- a/gdcmPython/demo/PrintFile.py.in +++ b/gdcmPython/demo/PrintFile.py.in @@ -1,15 +1,16 @@ import sys -import os - -sys.path.append('${GDCM_BINARY_DIR}') -if os.name == 'posix': - sys.path.append('${GDCM_BINARY_DIR}/bin') -else: - sys.path.append('${GDCM_BINARY_DIR}/bin/Release') - sys.path.append('${GDCM_BINARY_DIR}/bin/Debug') - +from gdcmConfigDemo import * from gdcmPython.core import * +def PrintUse(): + print "" + print "Use :" + print "-----" + print "%s " % sys.argv[0] + print " fileName : path to the DICOM file to parse" + print "" + print "" + ### Get filename from command line or default it try: fileName = sys.argv[1] @@ -22,11 +23,12 @@ except IndexError: printLevel = 1 ### Build the file element list -print fileName, type(fileName) file = gdcm.File(fileName) if not file.IsReadable(): + PrintUse() raise RuntimeError,"The '%s' file is not readable with gdcm." % fileName +print "File -->",fileName print "##############################################################" print "### Display all the elements and their respective values" print "## found in the ", fileName, " file." diff --git a/gdcmPython/demo/gdcmConfigDemo.py.in b/gdcmPython/demo/gdcmConfigDemo.py.in new file mode 100644 index 00000000..245b9c06 --- /dev/null +++ b/gdcmPython/demo/gdcmConfigDemo.py.in @@ -0,0 +1,45 @@ +# gdcmPython Demo configurer + +if __name__!="main": + import sys + import os + import inspect + import os.path + + def FindPath(): + try: + path=inspect.getsourcefile(FindPath) + except: + pass + else: + if( path ): + path=os.path.split(path)[0] + file=os.path.join(path,"..","__init__.py") + if( os.path.isfile(file) ): + gdcmPath=os.path.join(path,"..","..") + sys.path.append(gdcmPath) + sys.path.append(os.path.join(gdcmPath,"bin")) + if( os.name != 'posix' ): + sys.path.append(os.path.join(gdcmPath,"bin","Release")) + sys.path.append(os.path.join(gdcmPath,"bin","Debug")) + + def UseCMakePath(): + sys.path.append('${GDCM_BINARY_DIR}') + sys.path.append('${GDCM_BINARY_DIR}/bin') + if( os.name != 'posix' ): + sys.path.append('${GDCM_BINARY_DIR}/bin/Release') + sys.path.append('${GDCM_BINARY_DIR}/bin/Debug') + + try: + mod=__import__("gdcmPython") + except: + FindPath() + try: + mod=__import__("gdcmPython") + except: + UseCMakePath() + +else: + print "Only a system configurer for gdcm Demos." + print "Can't be executed" + diff --git a/gdcmPython/demo/vtkGdcmReader.py.in b/gdcmPython/demo/vtkGdcmReader.py.in index 587165c0..aea5e5c8 100644 --- a/gdcmPython/demo/vtkGdcmReader.py.in +++ b/gdcmPython/demo/vtkGdcmReader.py.in @@ -1,22 +1,25 @@ -import sys -import os - -# All paths must be added without system tests, because of ctest... -sys.path.append('${GDCM_BINARY_DIR}') -if os.name == 'posix': - sys.path.append('${GDCM_BINARY_DIR}/bin') -else: - sys.path.append('${GDCM_BINARY_DIR}/bin/Release') - sys.path.append('${GDCM_BINARY_DIR}/bin/Debug') - +from gdcmConfigDemo import * from gdcmPython.vtk import * from vtkpython import * +def PrintUse(): + print "" + print "Use :" + print "-----" + print "%s " % sys.argv[0] + print " fileName : path to the DICOM file to see" + print "" + print "" + # Get the file names try: fileName = sys.argv[1] except IndexError: fileName = os.path.join(GDCM_DATA_ROOT, "test.acr") + +if( not os.path.isfile(fileName) ): + PrintUse() + sys.exit(1) # read the image reader = vtkGdcmReader() diff --git a/gdcmPython/demo/vtkGdcmWriter.py.in b/gdcmPython/demo/vtkGdcmWriter.py.in index cdb94fd7..c3f5809e 100644 --- a/gdcmPython/demo/vtkGdcmWriter.py.in +++ b/gdcmPython/demo/vtkGdcmWriter.py.in @@ -1,21 +1,25 @@ -import sys -import os - -sys.path.append('${GDCM_BINARY_DIR}') -if os.name == 'posix': - sys.path.append('${GDCM_BINARY_DIR}/bin') -else: - sys.path.append('${GDCM_BINARY_DIR}/bin/Release') - sys.path.append('${GDCM_BINARY_DIR}/bin/Debug') - +from gdcmConfigDemo import * from gdcmPython.vtk import * from vtkpython import * +def PrintUse(): + print "" + print "Use :" + print "-----" + print "%s " % sys.argv[0] + print " fileName : path to the DICOM file to see" + print "" + print "" + # Get the file names try: fileName = sys.argv[1] except IndexError: fileName = os.path.join(GDCM_DATA_ROOT, "test.acr") + +if( not os.path.isfile(fileName) ): + PrintUse() + sys.exit(1) # read the image reader = vtkGdcmReader()