]> Creatis software - gdcm.git/commitdiff
* setup.py fixed for un*x (needed macro for stdint.h)
authorfrog <frog>
Thu, 27 Mar 2003 14:57:07 +0000 (14:57 +0000)
committerfrog <frog>
Thu, 27 Mar 2003 14:57:07 +0000 (14:57 +0000)
      * Test/test.cxx renamed to PrintHeader.cxx to avoid collision on
        un*ces with sh-utils test utility.
      * gdcmPython/demo/test.py renamed to PrintHeader.py
      * gdcmPython/demo/ReorganiseFiles.py new demo script added.

ChangeLog
Testing/.cvsignore
gdcmPython/demo/PrintHeader.py [moved from gdcmPython/demo/test.py with 100% similarity]
gdcmPython/demo/ReorganiseFiles.py [new file with mode: 0644]
setup.py

index a7d1e2ad4198b1798731c60ab2deec34c7f82f0d..7d3615616a8ce7325420cef014eae85bdf80e3bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2003-03-27 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
+      * setup.py fixed for un*x (needed macro for stdint.h)
+      * Test/test.cxx renamed to PrintHeader.cxx to avoid collision on
+        un*ces with sh-utils test utility.
+      * gdcmPython/demo/test.py renamed to PrintHeader.py
+      * gdcmPython/demo/ReorganiseFiles.py new demo script added.
+
 2003-03-26 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
       * src/gdcmHeader[h, cxx] gdcmHeader now has an IsReadable predicate.
       * gdcmPython/demo/test.py changed accordingly.
index d5d57cdfeb80e7081bf80f13c463d5c186bfe33d..0622317ef88dbd583bc531dca04921e646e74f36 100644 (file)
@@ -3,7 +3,7 @@
 .libs
 Makefile.in
 Makefile
-test
+PrintHeader
 testWrite
 hashtest
 dcm2acr
diff --git a/gdcmPython/demo/ReorganiseFiles.py b/gdcmPython/demo/ReorganiseFiles.py
new file mode 100644 (file)
index 0000000..1ba6178
--- /dev/null
@@ -0,0 +1,57 @@
+# Rename the dcm extension files of a given drectory according
+# to series and image number information extracted in each respective header.
+
+from gdcmPython import *
+import glob
+import os
+import sys
+
+def PrintUsage():
+   print "Usage: python ReorganiseFiles.py <SourceDirectory>"
+   print "       <SourceDirectory> is the directory containing the source"
+   print "                         images (defaulted to invocation directory."
+
+def Warning(DirName):
+   print "Warning: this script will rename files in the"
+   print "        ", DirName, " directory."
+   a = raw_input("Proceed ?[y/n]")
+   if a != "y":
+      sys.exit()
+
+try:
+   SourceDirectory = sys.argv[1]
+except IndexError:
+   SourceDirectory = os.getcwd()
+
+if not os.path.isdir(SourceDirectory):
+   PrintUsage
+Warning(SourceDirectory)
+SourceFiles=glob.glob(os.path.join(SourceDirectory, "*.dcm"))
+
+for file in SourceFiles:
+   header = gdcmHeader(file)
+   info = header.GetPubElVal()
+   try:
+      ImNum = info["Image Number"]
+      if len(ImNum) == 0 or ImNum == "gdcm::Unfound":
+         raise KeyError
+   except KeyError:
+      print "Skipped file ", file, " (unfound Image Number tag)."
+      continue
+   try:
+      SeNum = info["Series Number"]
+      if len(SeNum) == 0 or SeNum == "gdcm::Unfound":
+         raise KeyError
+   except KeyError:
+      print "Skipped file ", file, " (unfound Series Number tag)."
+      continue
+   DestFile = "image_%02d_%04d.dcm"
+   DestFile %= (int(info["Image Number"]), int(info["Series Number"]))
+   DestFile = os.path.join(SourceDirectory, DestFile)
+   # necessary to close the file descriptor to enable further rename.
+   del header
+   if os.path.isfile(DestFile):
+      print "Skipped file ", file, " (allready existing destination"
+      print "     file ", DestFile
+      continue
+   os.rename(file, DestFile)
index acb4caef72377f7a38371af1d5fe7730f4fbcb05..4a75e2d0af31082b7fb9e2fe66dc0021c3e14499 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -11,11 +11,13 @@ gdcmDataDir     ="Data"
 # Due to a disutil oddity on Unices : see
 # http://aspn.activestate.com/ASPN/Mail/Message/distutils-sig/588325
 if(os.name=='posix'):
-       targetDir=os.path.join('lib','python'+sys.version[:3],'site-packages')
-       libraries=["stdc++"]
+   targetDir=os.path.join('lib','python'+sys.version[:3],'site-packages')
+   libraries=["stdc++"]
+   macros   =[('__STDC_LIMIT_MACROS', '1')]
 else:
-       targetDir=os.path.join('lib','site-packages')
-       libraries=["WSOCK32"]
+   targetDir=os.path.join('lib','site-packages')
+   libraries=["WSOCK32"]
+   macros   =[]
 
 targetDir=os.path.join(targetDir, ThisModule)
 
@@ -38,6 +40,7 @@ setup(name=ThisModule,
                    sources=Sources,
                    include_dirs=[gdcmSrcDir],
                    libraries=libraries,
+                   define_macros=macros,
                    swig_cpp=1,
                    swig_include=[ gdcmSrcDir] ) ],
       data_files=[(os.path.join(targetDir,"Data"),