|
@@ -4,7 +4,7 @@ import qt
|
|
|
import ctk
|
|
|
import json
|
|
|
import os
|
|
|
-
|
|
|
+import shutil
|
|
|
|
|
|
class fileIO(slicer.ScriptedLoadableModule.ScriptedLoadableModule):
|
|
|
def __init__(self,parent):
|
|
@@ -157,6 +157,11 @@ class fileIOWidget(slicer.ScriptedLoadableModule.ScriptedLoadableModuleWidget):
|
|
|
copyToRemoteButton.connect('clicked(bool)',self.onCopyToRemoteButtonClicked)
|
|
|
fileDialogFormLayout.addRow(copyToRemoteButton)
|
|
|
|
|
|
+ copyToLocalButton=qt.QPushButton("Remote -> Local")
|
|
|
+ copyToLocalButton.toolTip="Remote -> Local"
|
|
|
+ copyToLocalButton.connect('clicked(bool)',self.onCopyToLocalButtonClicked)
|
|
|
+ fileDialogFormLayout.addRow(copyToLocalButton)
|
|
|
+
|
|
|
removeRemoteButton=qt.QPushButton("Remove remote")
|
|
|
removeRemoteButton.toolTip="Remove Remote"
|
|
|
removeRemoteButton.connect('clicked(bool)',self.onRemoveRemoteButtonClicked)
|
|
@@ -213,9 +218,40 @@ class fileIOWidget(slicer.ScriptedLoadableModule.ScriptedLoadableModuleWidget):
|
|
|
localfile=os.path.join(localPath,f)
|
|
|
self.copyLocalFileToRemote(localfile,remotePath)
|
|
|
|
|
|
+ def copyRemoteToLocal(self,localPath,remotePath):
|
|
|
+ ok,files=self.network.listRemoteDir(remotePath)
|
|
|
+ if not ok:
|
|
|
+ print 'Troubles getting remote dir content for {}'.format(remotePath)
|
|
|
+ return
|
|
|
+ #remove trailing slash
|
|
|
+ for f in files:
|
|
|
+ if f[-1]=='/':
|
|
|
+ f=f[:-1]
|
|
|
+
|
|
|
+ bf=f[f.rfind('/')+1:]
|
|
|
+ dirUrl=self.network.GetLabkeyWebdavUrl()+"/"+f
|
|
|
+ if self.network.isDir(dirUrl):
|
|
|
+ lp=os.path.join(localPath,bf)
|
|
|
+ if not os.path.isdir(lp):
|
|
|
+ os.mkdir(lp)
|
|
|
+ print 'Creating {}'.format(lp)
|
|
|
+ print 'Copying directory {} to {}'.format(f,lp)
|
|
|
+ self.copyRemoteToLocal(lp,f)
|
|
|
+ else:
|
|
|
+ rf=self.network.readFile(f)
|
|
|
+ fout=os.path.join(localPath,bf)
|
|
|
+ print 'Copying file {} to {}'.format(f,fout)
|
|
|
+ with open (fout, 'w') as fd:
|
|
|
+ rf.seek (0)
|
|
|
+ shutil.copyfileobj (rf, fd)
|
|
|
+ fd.close()
|
|
|
+
|
|
|
def onCopyToRemoteButtonClicked(self):
|
|
|
self.copyLocalFileToRemote(self.localPath.text,self.remotePath.text)
|
|
|
|
|
|
+ def onCopyToLocalButtonClicked(self):
|
|
|
+ self.copyRemoteToLocal(self.localPath.text,self.remotePath.text)
|
|
|
+
|
|
|
def onRemoveRemoteButtonClicked(self):
|
|
|
remotePath=self.remotePath.text
|
|
|
if self.network.isRemoteDir(remotePath):
|