|
@@ -213,6 +213,25 @@ class labkeyURIHandler(slicer.vtkURIHandler):
|
|
|
print e.code
|
|
|
print e.read()
|
|
|
return e
|
|
|
+
|
|
|
+ #a HEAD request
|
|
|
+ def head(self,url):
|
|
|
+
|
|
|
+ debug=False
|
|
|
+ if debug:
|
|
|
+ print("HEAD: {0}").format(url)
|
|
|
+ print("as {0}").format(self.auth_name)
|
|
|
+ r=MethodRequest(url.encode('utf-8'),method="HEAD")
|
|
|
+ base64string = base64.b64encode('%s:%s' % (self.auth_name, self.auth_pass))
|
|
|
+ r.add_header("Authorization", "Basic %s" % base64string)
|
|
|
+ try:
|
|
|
+ return self.opener.open(r)
|
|
|
+ #f contains json as a return value
|
|
|
+ except urllib2.HTTPError as e:
|
|
|
+ print e.code
|
|
|
+ print e.read()
|
|
|
+ return e
|
|
|
+
|
|
|
|
|
|
def post(self,url,data):
|
|
|
|
|
@@ -310,17 +329,26 @@ class labkeyURIHandler(slicer.vtkURIHandler):
|
|
|
return ('VolumeFile','SegmentationFile','TransformFile')
|
|
|
|
|
|
#mimic slicer.util.loadNodeFromFile
|
|
|
- def loadNode(self, relativeName, filetype, properties={},returnNode=False):
|
|
|
+ def loadNode(self, relativeName, filetype, properties={},returnNode=False, keepCached=True):
|
|
|
#this is the only relevant part - file must be downloaded to cache
|
|
|
#labkeyName is just the relative part (from labkey onwards)
|
|
|
+
|
|
|
localPath=self.DownloadFileToCache(relativeName)
|
|
|
- print localPath
|
|
|
+
|
|
|
if not returnNode:
|
|
|
slicer.util.loadNodeFromFile(localPath,filetype,properties,returnNode=False)
|
|
|
+ if not keepCached:
|
|
|
+ os.remove(localPath)
|
|
|
return
|
|
|
+
|
|
|
ok,node=slicer.util.loadNodeFromFile(localPath,filetype,properties,returnNode=True)
|
|
|
if ok:
|
|
|
- return node
|
|
|
+ if not keepCached:
|
|
|
+ os.remove(localPath)
|
|
|
+ return node
|
|
|
+
|
|
|
+
|
|
|
+ os.remove(localPath)
|
|
|
return None
|
|
|
# #remove retrieved file
|
|
|
|