2005-01-13 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
* Now, python test might work on systems
+ * Add the PrintDicomDir test
2005-01-13 Jean-Pierre Roux <jpr@creatis.univ-lyon1.fr>
* FIX : First entry following group 0002 was lost for
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")
${GDCM_BINARY_DIR}/gdcmPython/demo/PrintHeader.py
)
+CONFIGURE_FILE(
+ ${GDCM_SOURCE_DIR}/gdcmPython/demo/PrintDicomDir.py.in
+ ${GDCM_BINARY_DIR}/gdcmPython/demo/PrintDicomDir.py
+)
+
### 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])
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()
--- /dev/null
+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()
+
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 "##############################################################"
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"