From: frog Date: Thu, 27 Mar 2003 14:57:07 +0000 (+0000) Subject: * setup.py fixed for un*x (needed macro for stdint.h) X-Git-Tag: April2003~4 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=f978dcd25d35bb7dcd2e21f5ca192cc9aea4e8ec;p=gdcm.git * 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. --- diff --git a/ChangeLog b/ChangeLog index a7d1e2ad..7d361561 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2003-03-27 Eric Boix + * 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 * src/gdcmHeader[h, cxx] gdcmHeader now has an IsReadable predicate. * gdcmPython/demo/test.py changed accordingly. diff --git a/Testing/.cvsignore b/Testing/.cvsignore index d5d57cdf..0622317e 100644 --- a/Testing/.cvsignore +++ b/Testing/.cvsignore @@ -3,7 +3,7 @@ .libs Makefile.in Makefile -test +PrintHeader testWrite hashtest dcm2acr diff --git a/gdcmPython/demo/test.py b/gdcmPython/demo/PrintHeader.py similarity index 100% rename from gdcmPython/demo/test.py rename to gdcmPython/demo/PrintHeader.py diff --git a/gdcmPython/demo/ReorganiseFiles.py b/gdcmPython/demo/ReorganiseFiles.py new file mode 100644 index 00000000..1ba6178e --- /dev/null +++ b/gdcmPython/demo/ReorganiseFiles.py @@ -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 " + print " 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) diff --git a/setup.py b/setup.py index acb4caef..4a75e2d0 100644 --- 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"),