瀏覽代碼

Proper handling of output files in remote and local regime, adding labkeyBase variable to configuration file

Andrej Studen 5 年之前
父節點
當前提交
3369ea5c0e
共有 1 個文件被更改,包括 19 次插入14 次删除
  1. 19 14
      cardiacSPECT/cardiacSPECT.py

+ 19 - 14
cardiacSPECT/cardiacSPECT.py

@@ -728,14 +728,7 @@ class cardiacSPECTLogic(ScriptedLoadableModuleLogic):
       return segNode.GetSegmentation().GetSegment(segNode.GetSegmentation().GetNthSegmentID(i)).GetName()
 
   def storeNodeRemote(self,relativePath,nodeName):
-    labkeyPath=self.pd.net.GetLabkeyPathFromRelativePath(relativePath)
-    print ("Remote: {}").format(labkeyPath)
-    #checks if exists
-    self.pd.net.mkdir(labkeyPath)
-
-    localPath=self.pd.net.GetLocalPathFromRelativePath(relativePath)
-    localPath.replace('/',os.path.sep)
-
+    
     node=slicer.mrmlScene.GetFirstNodeByName(nodeName)
     if node==None:
         print("Node {} not found").format(nodeName)
@@ -748,20 +741,32 @@ class cardiacSPECTLogic(ScriptedLoadableModuleLogic):
             node.__class__.__name__=="vtkMRMLGridTransformNode"):
         suffix=".h5"
 
-    #fileName=re.sub(r'_RS$',r'',nodeName)+suffix
     fileName=nodeName+suffix
 
+    localPath=self.getLocalPath(relativePath)
     if not os.path.isdir(localPath):
         os.mkdir(localPath)
 
     file=os.path.join(localPath,fileName)
     slicer.util.saveNode(node,file)
     print("Stored to: {}").format(file)
-    f=open(file,"rb")
-    remoteFile=labkeyPath+'/'+fileName
-    self.pd.net.put(remoteFile,f.read())
-
-
+    if self.cfg["remote"]:
+        labkeyPath=self.pd.net.GetLabkeyPathFromRelativePath(relativePath)
+        print ("Remote: {}").format(labkeyPath)
+        #checks if exists
+        self.pd.net.mkdir(labkeyPath)
+        remoteFile=labkeyPath+'/'+fileName
+        f=open(file,"rb")
+        self.pd.net.put(remoteFile,f.read())
+
+  def getLocalPath(self,relativePath):
+    if self.cfg["remote"]:
+        localPath=self.pd.net.GetLocalPathFromRelativePath(relativePath)
+        localPath.replace('/',os.path.sep)
+        return localPath
+    
+    localPath=os.path.join(self.cfg["labkeyBase"],relativePath)
+    return localPath
 
 
   def storeVolumeNodes(self,patientId,n1,n2):