changeset 733:29982cfc5009

improvements to ImportDicomFiles tx Karsten Hilbert
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Feb 2014 09:45:15 +0100
parents b79eda29896d
children 8c29c1056d45
files Resources/Samples/ImportDicomFiles/ImportDicomFiles.py
diffstat 1 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/Samples/ImportDicomFiles/ImportDicomFiles.py	Tue Feb 25 15:39:13 2014 +0100
+++ b/Resources/Samples/ImportDicomFiles/ImportDicomFiles.py	Thu Feb 27 09:45:15 2014 +0100
@@ -21,16 +21,19 @@
 
 URL = 'http://%s:%d/instances' % (sys.argv[1], int(sys.argv[2]))
 
-success = 0
+success_count = 0
+total_file_count = 0
 
 
 # This function will upload a single file to Orthanc through the REST API
 def UploadFile(path):
-    global success
+    global success_count
+    global total_file_count
 
     f = open(path, "rb")
     content = f.read()
     f.close()
+    total_file_count += 1
 
     try:
         sys.stdout.write("Importing %s" % path)
@@ -51,14 +54,14 @@
             # not always work)
             # http://en.wikipedia.org/wiki/Basic_access_authentication
             headers['authorization'] = 'Basic ' + base64.b64encode(username + ':' + password)       
-            
+
         resp, content = h.request(URL, 'POST', 
                                   body = content,
                                   headers = headers)
 
         if resp.status == 200:
             sys.stdout.write(" => success\n")
-            success += 1
+            success_count += 1
         else:
             sys.stdout.write(" => failure (Is it a DICOM file?)\n")
 
@@ -74,6 +77,8 @@
     for root, dirs, files in os.walk(sys.argv[3]):
         for f in files:
             UploadFile(os.path.join(root, f))
-        
 
-print("\nSummary: %d DICOM file(s) have been imported" % success)
+if success_count == total_file_count:
+    print("\nSummary: all %d DICOM file(s) have been imported successfully" % success_count)
+else:
+    print("\nSummary: %d out of %d files have been imported successfully as DICOM instances" % (success_count, total_file_count))