changeset 372:cc0fe7890e89

merge
author jodogne
date Tue, 12 Mar 2013 11:21:03 +0100
parents 22bb88181e06 (diff) 0ef82ea18da0 (current diff)
children 7000726bade7
files
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/Samples/ImportDicomFiles/ImportDicomFiles.py	Thu Mar 07 10:10:02 2013 +0100
+++ b/Resources/Samples/ImportDicomFiles/ImportDicomFiles.py	Tue Mar 12 11:21:03 2013 +0100
@@ -5,7 +5,7 @@
 import os.path
 import httplib2
 
-if len(sys.argv) != 4:
+if len(sys.argv) != 4 and len(sys.argv) != 6:
     print("""
 Sample script to recursively import in Orthanc all the DICOM files
 that are stored in some path. Please make sure that Orthanc is running
@@ -13,8 +13,9 @@
 API.
 
 Usage: %s [hostname] [HTTP port] [path]
+Usage: %s [hostname] [HTTP port] [path] [username] [password]
 For instance: %s localhost 8042 .
-""" % (sys.argv[0], sys.argv[0]))
+""" % (sys.argv[0], sys.argv[0], sys.argv[0]))
     exit(-1)
 
 URL = 'http://%s:%d/instances' % (sys.argv[1], int(sys.argv[2]))
@@ -26,7 +27,7 @@
 def UploadFile(path):
     global success
 
-    f = open(path, "r")
+    f = open(path, "rb")
     content = f.read()
     f.close()
 
@@ -34,6 +35,10 @@
         sys.stdout.write("Importing %s" % path)
 
         h = httplib2.Http()
+
+        if len(sys.argv) == 6:
+            h.add_credentials(sys.argv[4], sys.argv[5])
+    
         resp, content = h.request(URL, 'POST', 
                                   body = content,
                                   headers = { 'content-type' : 'application/dicom' })
@@ -45,7 +50,7 @@
             sys.stdout.write(" => failure (is it a DICOM file?)\n")
 
     except:
-        sys.stdout.write(" => unable to connect\n")
+        sys.stdout.write(" => unable to connect (is there a password?)\n")
 
 
 if os.path.isfile(sys.argv[3]):