From 9de7a35ab47a6acf7ef33ad333df73f0a608166f Mon Sep 17 00:00:00 2001 From: regrain Date: Thu, 13 Jan 2005 10:49:25 +0000 Subject: [PATCH] * Add the PrintDicomDir test -- BeNours --- ChangeLog | 1 + gdcmPython/demo/CMakeLists.txt | 8 +++++++ gdcmPython/demo/PrintDicomDir.py | 22 +++++++---------- gdcmPython/demo/PrintDicomDir.py.in | 37 +++++++++++++++++++++++++++++ gdcmPython/demo/PrintHeader.py | 2 +- gdcmPython/demo/PrintHeader.py.in | 10 +------- 6 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 gdcmPython/demo/PrintDicomDir.py.in diff --git a/ChangeLog b/ChangeLog index bd232deb..96b10e12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2005-01-13 Benoit Regrain * Now, python test might work on systems + * Add the PrintDicomDir test 2005-01-13 Jean-Pierre Roux * FIX : First entry following group 0002 was lost for diff --git a/gdcmPython/demo/CMakeLists.txt b/gdcmPython/demo/CMakeLists.txt index f34df9c5..25428d4e 100644 --- a/gdcmPython/demo/CMakeLists.txt +++ b/gdcmPython/demo/CMakeLists.txt @@ -19,6 +19,9 @@ IF(PYTHON_EXECUTABLE) ADD_TEST(Python-PrintHeader ${PYTHON_EXECUTABLE} ${GDCM_BINARY_DIR}/gdcmPython/demo/PrintHeader.py ) + ADD_TEST(Python-PrintDicomDir ${PYTHON_EXECUTABLE} + ${GDCM_BINARY_DIR}/gdcmPython/demo/PrintDicomDir.py + ) ELSE(PYTHON_EXECUTABLE) MESSAGE(FATAL_ERROR "You requested testing for python, but python was not found") @@ -32,3 +35,8 @@ CONFIGURE_FILE( ${GDCM_BINARY_DIR}/gdcmPython/demo/PrintHeader.py ) +CONFIGURE_FILE( + ${GDCM_SOURCE_DIR}/gdcmPython/demo/PrintDicomDir.py.in + ${GDCM_BINARY_DIR}/gdcmPython/demo/PrintDicomDir.py +) + diff --git a/gdcmPython/demo/PrintDicomDir.py b/gdcmPython/demo/PrintDicomDir.py index b9538392..a4c534f3 100644 --- a/gdcmPython/demo/PrintDicomDir.py +++ b/gdcmPython/demo/PrintDicomDir.py @@ -3,9 +3,9 @@ import sys ### Get filename from command line or default it try: - FileName = sys.argv[1] + fileName = sys.argv[1] except IndexError: - FileName = os.path.join(GDCM_DATA_PATH, "DICOMDIR") + fileName = os.path.join(GDCM_DATA_PATH, "DICOMDIR") try: printLevel = int(sys.argv[2]) @@ -13,19 +13,15 @@ except IndexError: printLevel = 1 ### Build the header element list -toRead = gdcmDicomDir(FileName) -if not toRead.IsReadable(): - print "The ", FileName, " DicomDir is not readable with gdcm. Sorry." +dicomdir = gdcmDicomDir(fileName) +if not dicomdir.IsReadable(): + print "The '", fileName, "' DicomDir is not readable with gdcm. Sorry." sys.exit() print "##############################################################" -print "### Display all the elements and their respective values" -print "## found in the ", FileName, " file." +print "## Display all the elements and their respective values" +print "## found in the ", fileName, " file." print "##############################################################" -toRead.SetPrintLevel(-1) -toRead.Print() - -# ValDict = toRead.GetEntry() -# for key in ValDict.keys(): -# print "[%s] = [%s]" %(key, ValDict[key]) +dicomdir.SetPrintLevel(-1) +dicomdir.Print() diff --git a/gdcmPython/demo/PrintDicomDir.py.in b/gdcmPython/demo/PrintDicomDir.py.in new file mode 100644 index 00000000..1f74e543 --- /dev/null +++ b/gdcmPython/demo/PrintDicomDir.py.in @@ -0,0 +1,37 @@ +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 gdcmPython.core import * + +### Get filename from command line or default it +try: + fileName = sys.argv[1] +except IndexError: + fileName = os.path.join(GDCM_DATA_PATH, "DICOMDIR") + +try: + printLevel = int(sys.argv[2]) +except IndexError: + printLevel = 1 + +### Build the header element list +dicomdir = gdcm.DicomDir(fileName) +if not dicomdir.IsReadable(): + print + raise RuntimeError,"The '%s' DicomDir is not readable with gdcm." % fileName + #sys.exit() + +print "##############################################################" +print "## Display all the elements and their respective values" +print "## found in the ", fileName, " file." +print "##############################################################" +dicomdir.SetPrintLevel(-1) +dicomdir.Print() + diff --git a/gdcmPython/demo/PrintHeader.py b/gdcmPython/demo/PrintHeader.py index 0125576c..ae409700 100644 --- a/gdcmPython/demo/PrintHeader.py +++ b/gdcmPython/demo/PrintHeader.py @@ -24,7 +24,7 @@ except IndexError: print fileName, type(fileName) header = gdcm.Header(fileName) if not header.IsReadable(): - print "The ", fileName, " file is not readable with gdcm. Sorry." + print "The '", fileName, "' file is not readable with gdcm. Sorry." sys.exit() print "##############################################################" diff --git a/gdcmPython/demo/PrintHeader.py.in b/gdcmPython/demo/PrintHeader.py.in index affa5f48..cd9acfb8 100644 --- a/gdcmPython/demo/PrintHeader.py.in +++ b/gdcmPython/demo/PrintHeader.py.in @@ -21,19 +21,11 @@ try: except IndexError: printLevel = 1 -#if not os.path.isfile(FileName): -# print "Cannot open file ", FileName -# sys.exit() - -# On debugging purposes uncomment the next line -#s = raw_input("Hit any key in this window to exit") - ### Build the header element list print fileName, type(fileName) header = gdcm.Header(fileName) if not header.IsReadable(): - print "The ", fileName, " file is not readable with gdcm. Sorry." - sys.exit() + raise RuntimeError,"The '%s' file is not readable with gdcm." % fileName print "##############################################################" print "### Display all the elements and their respective values" -- 2.45.1