|
@@ -2,10 +2,13 @@ import os
|
|
import unittest
|
|
import unittest
|
|
from __main__ import vtk, qt, ctk, slicer
|
|
from __main__ import vtk, qt, ctk, slicer
|
|
from slicer.ScriptedLoadableModule import *
|
|
from slicer.ScriptedLoadableModule import *
|
|
-import slicerNetwork
|
|
|
|
-import loadDicom
|
|
|
|
|
|
+#import slicerNetwork
|
|
import json
|
|
import json
|
|
-
|
|
|
|
|
|
+import zipfile
|
|
|
|
+import pathlib
|
|
|
|
+import sys
|
|
|
|
+import urllib3
|
|
|
|
+import string
|
|
#
|
|
#
|
|
# labkeySlicerPythonExtension
|
|
# labkeySlicerPythonExtension
|
|
#
|
|
#
|
|
@@ -41,7 +44,38 @@ class labkeyBrowserWidget(ScriptedLoadableModuleWidget):
|
|
ScriptedLoadableModuleWidget.setup(self)
|
|
ScriptedLoadableModuleWidget.setup(self)
|
|
# Instantiate and connect widgets ...
|
|
# Instantiate and connect widgets ...
|
|
self.logic=labkeyBrowserLogic(self)
|
|
self.logic=labkeyBrowserLogic(self)
|
|
- self.network=slicerNetwork.labkeyURIHandler()
|
|
|
|
|
|
+
|
|
|
|
+ fhome=os.path.expanduser('~')
|
|
|
|
+ fsetup=os.path.join(fhome,'.labkey','setup.json')
|
|
|
|
+ try:
|
|
|
|
+ with open(fsetup) as f:
|
|
|
|
+ self.setup=json.load(f)
|
|
|
|
+ except FileNotFoundError:
|
|
|
|
+ self.setup={}
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ pt=self.setup['paths']
|
|
|
|
+ except KeyError:
|
|
|
|
+ self.setup['paths']={}
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ sys.path.append(self.setup['paths']['labkeyInterface'])
|
|
|
|
+ except KeyError:
|
|
|
|
+ self.setup['paths']['labkeyInterface']=loadLibrary('labkeyInterface')
|
|
|
|
+ with open(fsetup,'w') as f:
|
|
|
|
+ json.dump(self.setup,f,indent='\t')
|
|
|
|
+
|
|
|
|
+ import labkeyInterface
|
|
|
|
+ import labkeyDatabaseBrowser
|
|
|
|
+ import labkeyFileBrowser
|
|
|
|
+
|
|
|
|
+ #self.network=slicerNetwork.labkeyURIHandler()
|
|
|
|
+ self.network=labkeyInterface.labkeyInterface()
|
|
|
|
+ fconfig=os.path.join(fhome,'.labkey','network.json')
|
|
|
|
+ self.network.init(fconfig)
|
|
|
|
+ self.db=labkeyDatabaseBrowser.labkeyDB(self.network)
|
|
|
|
+ self.fb=labkeyFileBrowser.labkeyFileBrowser(self.network)
|
|
|
|
+
|
|
#
|
|
#
|
|
# Parameters Area
|
|
# Parameters Area
|
|
#
|
|
#
|
|
@@ -54,12 +88,12 @@ class labkeyBrowserWidget(ScriptedLoadableModuleWidget):
|
|
self.configDir=os.path.join(os.path.expanduser('~'),".labkey")
|
|
self.configDir=os.path.join(os.path.expanduser('~'),".labkey")
|
|
|
|
|
|
self.serverURL=qt.QLineEdit("https://merlin.fmf.uni-lj.si")
|
|
self.serverURL=qt.QLineEdit("https://merlin.fmf.uni-lj.si")
|
|
- self.serverURL.textChanged.connect(self.updateServerURL)
|
|
|
|
|
|
+ #self.serverURL.textChanged.connect(self.updateServerURL)
|
|
connectionFormLayout.addRow("Server: ", self.serverURL)
|
|
connectionFormLayout.addRow("Server: ", self.serverURL)
|
|
#copy initial setting
|
|
#copy initial setting
|
|
- self.updateServerURL(self.serverURL.text);
|
|
|
|
|
|
+ #self.updateServerURL(self.serverURL.text);
|
|
|
|
|
|
- self.startDir=os.path.join(os.path.expanduser('~'),"temp/crt")
|
|
|
|
|
|
+ self.startDir=os.path.join(os.path.expanduser('~'),"temp","crt")
|
|
|
|
|
|
self.userCertButton=qt.QPushButton("Load")
|
|
self.userCertButton=qt.QPushButton("Load")
|
|
self.userCertButton.toolTip="Load user certificate (crt)"
|
|
self.userCertButton.toolTip="Load user certificate (crt)"
|
|
@@ -69,7 +103,8 @@ class labkeyBrowserWidget(ScriptedLoadableModuleWidget):
|
|
|
|
|
|
self.privateKeyButton=qt.QPushButton("Load")
|
|
self.privateKeyButton=qt.QPushButton("Load")
|
|
self.privateKeyButton.toolTip="Load private key"
|
|
self.privateKeyButton.toolTip="Load private key"
|
|
- self.privateKeyButton.connect('clicked(bool)',self.onPrivateKeyButtonClicked)
|
|
|
|
|
|
+ self.privateKeyButton.connect('clicked(bool)',\
|
|
|
|
+ self.onPrivateKeyButtonClicked)
|
|
|
|
|
|
connectionFormLayout.addRow("Private key:",self.privateKeyButton)
|
|
connectionFormLayout.addRow("Private key:",self.privateKeyButton)
|
|
|
|
|
|
@@ -82,26 +117,39 @@ class labkeyBrowserWidget(ScriptedLoadableModuleWidget):
|
|
|
|
|
|
self.loadConfigButton=qt.QPushButton("Load configuration")
|
|
self.loadConfigButton=qt.QPushButton("Load configuration")
|
|
self.loadConfigButton.toolTip="Load configuration"
|
|
self.loadConfigButton.toolTip="Load configuration"
|
|
- self.loadConfigButton.connect('clicked(bool)',self.onLoadConfigButtonClicked)
|
|
|
|
|
|
+ self.loadConfigButton.connect('clicked(bool)',\
|
|
|
|
+ self.onLoadConfigButtonClicked)
|
|
connectionFormLayout.addRow("Configuration:",self.loadConfigButton)
|
|
connectionFormLayout.addRow("Configuration:",self.loadConfigButton)
|
|
|
|
|
|
|
|
+ self.loadZipButton=qt.QPushButton("Load certificates (.zip)")
|
|
|
|
+ self.loadZipButton.toolTip="Load certificates from zip file"
|
|
|
|
+ self.loadZipButton.connect('clicked(bool)',\
|
|
|
|
+ self.onLoadZipButtonClicked)
|
|
|
|
+ connectionFormLayout.addRow("Load certificates (merlin):",\
|
|
|
|
+ self.loadZipButton)
|
|
|
|
+
|
|
self.saveConfigButton=qt.QPushButton("Save configuration")
|
|
self.saveConfigButton=qt.QPushButton("Save configuration")
|
|
self.saveConfigButton.toolTip="Save configuration"
|
|
self.saveConfigButton.toolTip="Save configuration"
|
|
self.saveConfigButton.clicked.connect(self.onSaveConfigButtonClicked)
|
|
self.saveConfigButton.clicked.connect(self.onSaveConfigButtonClicked)
|
|
connectionFormLayout.addRow("Configuration:",self.saveConfigButton)
|
|
connectionFormLayout.addRow("Configuration:",self.saveConfigButton)
|
|
|
|
|
|
|
|
+ self.resetConfigButton=qt.QPushButton("Reset configuration")
|
|
|
|
+ self.resetConfigButton.toolTip="Reset configuration"
|
|
|
|
+ self.resetConfigButton.clicked.connect(self.onResetConfigButtonClicked)
|
|
|
|
+ connectionFormLayout.addRow("Configuration:",self.resetConfigButton)
|
|
|
|
+
|
|
self.initButton=qt.QPushButton("Init")
|
|
self.initButton=qt.QPushButton("Init")
|
|
self.initButton.toolTip="Initialize connection to the server"
|
|
self.initButton.toolTip="Initialize connection to the server"
|
|
self.initButton.connect('clicked(bool)',self.onInitButtonClicked)
|
|
self.initButton.connect('clicked(bool)',self.onInitButtonClicked)
|
|
connectionFormLayout.addRow("Connection:",self.initButton)
|
|
connectionFormLayout.addRow("Connection:",self.initButton)
|
|
|
|
|
|
self.authName=qt.QLineEdit("email")
|
|
self.authName=qt.QLineEdit("email")
|
|
- self.authName.textChanged.connect(self.updateAuthName)
|
|
|
|
|
|
+ #self.authName.textChanged.connect(self.updateAuthName)
|
|
connectionFormLayout.addRow("Labkey username: ", self.authName)
|
|
connectionFormLayout.addRow("Labkey username: ", self.authName)
|
|
|
|
|
|
self.authPass=qt.QLineEdit("")
|
|
self.authPass=qt.QLineEdit("")
|
|
self.authPass.setEchoMode(qt.QLineEdit.Password)
|
|
self.authPass.setEchoMode(qt.QLineEdit.Password)
|
|
- self.authPass.textChanged.connect(self.updateAuthPass)
|
|
|
|
|
|
+ #self.authPass.textChanged.connect(self.updateAuthPass)
|
|
connectionFormLayout.addRow("Labkey password: ", self.authPass)
|
|
connectionFormLayout.addRow("Labkey password: ", self.authPass)
|
|
|
|
|
|
|
|
|
|
@@ -118,7 +166,8 @@ class labkeyBrowserWidget(ScriptedLoadableModuleWidget):
|
|
self.fileList=qt.QListWidget()
|
|
self.fileList=qt.QListWidget()
|
|
self.fileList.toolTip="Select remote file"
|
|
self.fileList.toolTip="Select remote file"
|
|
self.fileList.itemDoubleClicked.connect(self.onFileListDoubleClicked)
|
|
self.fileList.itemDoubleClicked.connect(self.onFileListDoubleClicked)
|
|
- self.currentRemoteDir=''
|
|
|
|
|
|
+ #remote dir is a list
|
|
|
|
+ self.currentRemoteDir=[]
|
|
|
|
|
|
#add dummy entry
|
|
#add dummy entry
|
|
items=('.','..')
|
|
items=('.','..')
|
|
@@ -136,7 +185,8 @@ class labkeyBrowserWidget(ScriptedLoadableModuleWidget):
|
|
self.fileTypeSelector=qt.QComboBox()
|
|
self.fileTypeSelector=qt.QComboBox()
|
|
self.fileTypeSelector.toolTip="Select file type"
|
|
self.fileTypeSelector.toolTip="Select file type"
|
|
|
|
|
|
- items=self.network.fileTypesAvailable()
|
|
|
|
|
|
+ items=('VolumeFile','SegmentationFile','TransformFile')
|
|
|
|
+
|
|
self.populateFileTypeSelector(items)
|
|
self.populateFileTypeSelector(items)
|
|
|
|
|
|
fileDialogFormLayout.addRow("File type :",self.fileTypeSelector)
|
|
fileDialogFormLayout.addRow("File type :",self.fileTypeSelector)
|
|
@@ -198,11 +248,11 @@ class labkeyBrowserWidget(ScriptedLoadableModuleWidget):
|
|
|
|
|
|
certList=qt.QSslCertificate.fromPath(filename)
|
|
certList=qt.QSslCertificate.fromPath(filename)
|
|
if len(certList) < 1:
|
|
if len(certList) < 1:
|
|
- print ("Troubles parsing {0}").format(filename)
|
|
|
|
|
|
+ print ("Troubles parsing {0}".format(filename))
|
|
return
|
|
return
|
|
|
|
|
|
self.logic.cert=qt.QSslCertificate(f)
|
|
self.logic.cert=qt.QSslCertificate(f)
|
|
- print("cert.isNull()={0}").format(self.logic.cert.isNull())
|
|
|
|
|
|
+ print("cert.isNull()={0}".format(self.logic.cert.isNull()))
|
|
self.userCertButton.setText(filename)
|
|
self.userCertButton.setText(filename)
|
|
self.authName.setText(self.logic.cert.subjectInfo("emailAddress"))
|
|
self.authName.setText(self.logic.cert.subjectInfo("emailAddress"))
|
|
|
|
|
|
@@ -240,7 +290,7 @@ class labkeyBrowserWidget(ScriptedLoadableModuleWidget):
|
|
certList=qt.QSslCertificate.fromPath(filename)
|
|
certList=qt.QSslCertificate.fromPath(filename)
|
|
|
|
|
|
if len(certList) < 1:
|
|
if len(certList) < 1:
|
|
- print("Troubles parsing {0}").format(filename)
|
|
|
|
|
|
+ print("Troubles parsing {0}".format(filename))
|
|
return
|
|
return
|
|
self.logic.caCert=qt.QSslCertificate(f)#certList[0]
|
|
self.logic.caCert=qt.QSslCertificate(f)#certList[0]
|
|
self.caCertButton.setText(filename)
|
|
self.caCertButton.setText(filename)
|
|
@@ -248,14 +298,77 @@ class labkeyBrowserWidget(ScriptedLoadableModuleWidget):
|
|
def onLoadConfigButtonClicked(self):
|
|
def onLoadConfigButtonClicked(self):
|
|
filename=qt.QFileDialog.getOpenFileName(None,'Open configuration file (JSON)',
|
|
filename=qt.QFileDialog.getOpenFileName(None,'Open configuration file (JSON)',
|
|
self.configDir, '*.json')
|
|
self.configDir, '*.json')
|
|
- self.network.parseConfig(filename,self)
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ self.network.init(filename)
|
|
|
|
+
|
|
|
|
+ cfg=self.network.connectionConfig
|
|
|
|
+
|
|
|
|
+ if 'SSL' in cfg:
|
|
|
|
+ sslSetup=cfg['SSL']
|
|
|
|
+ self.privateKeyButton.setText(sslSetup['key'])
|
|
|
|
+ self.userCertButton.setText(sslSetup['user'])
|
|
|
|
+ self.caCertButton.setText(sslSetup['ca'])
|
|
|
|
+
|
|
|
|
+ self.serverURL.setText(cfg['host'])
|
|
|
|
+ if 'labkey' in cfg:
|
|
|
|
+ labkey=cfg['labkey']
|
|
|
|
+ self.authName.setText(labkey['user'])
|
|
|
|
+ self.authPass.setText(labkey['password'])
|
|
|
|
+
|
|
#self.serverURL.setText(self.network.hostname)
|
|
#self.serverURL.setText(self.network.hostname)
|
|
#self.authName.setText(self.network.auth_name)
|
|
#self.authName.setText(self.network.auth_name)
|
|
#self.authPass.setText(self.network.auth_pass)
|
|
#self.authPass.setText(self.network.auth_pass)
|
|
|
|
|
|
self.loadConfigButton.setText(os.path.basename(filename))
|
|
self.loadConfigButton.setText(os.path.basename(filename))
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ def onLoadZipButtonClicked(self):
|
|
|
|
+ filename=qt.QFileDialog.getOpenFileName(\
|
|
|
|
+ None,'Open certificate file (zip)',
|
|
|
|
+ self.configDir, '*.zip')
|
|
|
|
+ zpath=pathlib.Path(filename)
|
|
|
|
+ user=zpath.stem
|
|
|
|
+ userDir=os.path.join(os.path.expanduser('~'),'.labkey',user)
|
|
|
|
+ if not os.path.isdir(userDir):
|
|
|
|
+ os.mkdir(userDir)
|
|
|
|
+
|
|
|
|
+ caName=None
|
|
|
|
+ with zipfile.ZipFile(filename,'r') as zipObj:
|
|
|
|
+ zipObj.extract(user+'.crt',userDir)
|
|
|
|
+ zipObj.extract(user+'.key',userDir)
|
|
|
|
+ zipList=zipObj.namelist()
|
|
|
|
+ for f in zipList:
|
|
|
|
+ if f.find('CA')>-1:
|
|
|
|
+ caName=f
|
|
|
|
+ zipObj.extract(f,userDir)
|
|
|
|
+
|
|
|
|
+ self.serverURL.setText('https://merlin.fmf.uni-lj.si')
|
|
|
|
+ self.privateKeyButton.setText(os.path.join(userDir,user+'.key'))
|
|
|
|
+ self.userCertButton.setText(os.path.join(userDir,user+'.crt'))
|
|
|
|
+ self.pwd='notUsed'
|
|
|
|
+ self.caCertButton.setText(os.path.join(userDir,caName))
|
|
|
|
+ self.authName.setText("guest")
|
|
|
|
+ self.authPass.setText("guest")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
def onSaveConfigButtonClicked(self):
|
|
def onSaveConfigButtonClicked(self):
|
|
|
|
+ connectionConfig=self.generateConfig()
|
|
|
|
+ fhome=os.path.expanduser('~')
|
|
|
|
+ labkeyDir=os.path.join(fhome,".labkey")
|
|
|
|
+ if not os.path.isdir(labkeyDir):
|
|
|
|
+ os.mkdir(labkeyDir)
|
|
|
|
+ fconfig=os.path.join(labkeyDir,'network.json')
|
|
|
|
+
|
|
|
|
+ with open(fconfig,'w') as f:
|
|
|
|
+ json.dump(connectionConfig,f,indent=3)
|
|
|
|
+
|
|
|
|
+ print("Done")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def generateConfig(self):
|
|
connectionConfig={}
|
|
connectionConfig={}
|
|
|
|
|
|
#setup SSL
|
|
#setup SSL
|
|
@@ -269,8 +382,12 @@ class labkeyBrowserWidget(ScriptedLoadableModuleWidget):
|
|
sslSetup['user']=self.userCertButton.text
|
|
sslSetup['user']=self.userCertButton.text
|
|
sslSetup['key']=self.privateKeyButton.text
|
|
sslSetup['key']=self.privateKeyButton.text
|
|
sslSetup['ca']=self.caCertButton.text
|
|
sslSetup['ca']=self.caCertButton.text
|
|
- sslSetup['keyPwd']=self.pwd
|
|
|
|
|
|
+ try:
|
|
|
|
+ sslSetup['keyPwd']=self.pwd
|
|
|
|
+ except AttributeError:
|
|
|
|
+ sslSetup['keyPwd']='notUsed'
|
|
connectionConfig['SSL']=sslSetup
|
|
connectionConfig['SSL']=sslSetup
|
|
|
|
+
|
|
connectionConfig["host"]=self.serverURL.text
|
|
connectionConfig["host"]=self.serverURL.text
|
|
connectionConfig["context"]="labkey"
|
|
connectionConfig["context"]="labkey"
|
|
labkeySetup={}
|
|
labkeySetup={}
|
|
@@ -286,49 +403,43 @@ class labkeyBrowserWidget(ScriptedLoadableModuleWidget):
|
|
orthancSetup['user']='ask'
|
|
orthancSetup['user']='ask'
|
|
orthancSetup['password']='askPassword'
|
|
orthancSetup['password']='askPassword'
|
|
connectionConfig['orthanc']=orthancSetup
|
|
connectionConfig['orthanc']=orthancSetup
|
|
|
|
+ return connectionConfig
|
|
|
|
|
|
-
|
|
|
|
- fhome=os.path.expanduser('~')
|
|
|
|
- labkeyDir=os.path.join(fhome,".labkey")
|
|
|
|
- if not os.path.isdir(labkeyDir):
|
|
|
|
- os.mkdir(labkeyDir)
|
|
|
|
- fconfig=os.path.join(labkeyDir,'network.json')
|
|
|
|
-
|
|
|
|
- with open(fconfig,'w') as f:
|
|
|
|
- json.dump(connectionConfig,f,indent=3)
|
|
|
|
-
|
|
|
|
- print("Done")
|
|
|
|
-
|
|
|
|
|
|
+ def onResetConfigButtonClicked(self):
|
|
|
|
+ self.serverURL.setText('URL')
|
|
|
|
+ self.privateKeyButton.setText("Load")
|
|
|
|
+ self.userCertButton.setText("Load")
|
|
|
|
+ self.caCertButton.setText("Load")
|
|
|
|
+ self.authName.setText("labkey username")
|
|
|
|
+ self.authPass.setText("password")
|
|
|
|
|
|
def onInitButtonClicked(self):
|
|
def onInitButtonClicked(self):
|
|
- if self.serverURL.text.find("https")==0:
|
|
|
|
- try:
|
|
|
|
- self.network.configureSSL(
|
|
|
|
- self.userCertButton.text,
|
|
|
|
- self.privateKeyButton.text,
|
|
|
|
- self.pwd,
|
|
|
|
- self.caCertButton.text)
|
|
|
|
- except AttributeError:
|
|
|
|
- pass
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ self.network.connectionConfig=self.generateConfig()
|
|
|
|
+ print(self.network.connectionConfig['labkey']['user'])
|
|
|
|
|
|
self.network.initRemote()
|
|
self.network.initRemote()
|
|
- if self.network.getCSRF()==None:
|
|
|
|
|
|
+ remoteId=self.network.getUserId()
|
|
|
|
+ if remoteId==None:
|
|
self.initButton.setStyleSheet("background-color: red")
|
|
self.initButton.setStyleSheet("background-color: red")
|
|
else:
|
|
else:
|
|
- self.initButton.setStyleSheet("background-color: green")
|
|
|
|
|
|
+ if remoteId['email']==self.network.connectionConfig['labkey']['user']:
|
|
|
|
+ self.initButton.setStyleSheet("background-color: green")
|
|
|
|
+ else:
|
|
|
|
+ self.initButton.setStyleSheet("background-color: orange")
|
|
|
|
+
|
|
|
|
|
|
- def updateAuthName(self,txt):
|
|
|
|
- self.network.auth_name=txt
|
|
|
|
- print("Setting username to {0}").format(self.network.auth_name);
|
|
|
|
|
|
+ #def updateAuthName(self,txt):
|
|
|
|
+ #self.network.auth_name=txt
|
|
|
|
+ #print("Setting username to {0}".format(self.network.auth_name))
|
|
|
|
|
|
- def updateAuthPass(self,txt):
|
|
|
|
- self.network.auth_pass=txt
|
|
|
|
- print("Setting password.")
|
|
|
|
|
|
+ #def updateAuthPass(self,txt):
|
|
|
|
+ #self.network.auth_pass=txt
|
|
|
|
+ #print("Setting password.")
|
|
|
|
|
|
- def updateServerURL(self,txt):
|
|
|
|
- self.network.hostname=txt
|
|
|
|
- print("Setting hostname to {0}").format(self.network.hostname);
|
|
|
|
|
|
+ #def updateServerURL(self,txt):
|
|
|
|
+ #self.network.hostname=txt
|
|
|
|
+ #print("Setting hostname to {}".format(self.network.hostname))
|
|
|
|
|
|
def onFileListDoubleClicked(self,item):
|
|
def onFileListDoubleClicked(self,item):
|
|
if item == None:
|
|
if item == None:
|
|
@@ -336,26 +447,26 @@ class labkeyBrowserWidget(ScriptedLoadableModuleWidget):
|
|
return
|
|
return
|
|
|
|
|
|
iText=item.text()
|
|
iText=item.text()
|
|
- print("Selected items: {0} ").format(iText)
|
|
|
|
-
|
|
|
|
|
|
+ print("Selected items: {0} ".format(iText))
|
|
|
|
|
|
|
|
+
|
|
#this is hard -> compose path string from currentRemoteDir and selection
|
|
#this is hard -> compose path string from currentRemoteDir and selection
|
|
if item.text().find('..')==0:
|
|
if item.text().find('..')==0:
|
|
#one up
|
|
#one up
|
|
- idx=self.currentRemoteDir.rfind('/')
|
|
|
|
- if idx<0:
|
|
|
|
- self.currentRemoteDir=''
|
|
|
|
- else:
|
|
|
|
- self.currentRemoteDir=self.currentRemoteDir[:idx]
|
|
|
|
|
|
+ try:
|
|
|
|
+ self.currentRemoteDir.pop()
|
|
|
|
+ except IndexError:
|
|
|
|
+ pass
|
|
elif item.text().find('.')==0:
|
|
elif item.text().find('.')==0:
|
|
pass
|
|
pass
|
|
else:
|
|
else:
|
|
- if len(self.currentRemoteDir)>0:
|
|
|
|
- self.currentRemoteDir+='/'
|
|
|
|
- self.currentRemoteDir+=item.text()
|
|
|
|
- print("Listing {0}").format(self.currentRemoteDir)
|
|
|
|
- flist=self.network.toRelativePath(
|
|
|
|
- self.network.listRelativeDir(self.currentRemoteDir))
|
|
|
|
|
|
+ self.currentRemoteDir.append(item.text())
|
|
|
|
+ print("Listing {}".format(self.currentRemoteDir))
|
|
|
|
+ remoteDirString=self.fb.GetRootUrl()
|
|
|
|
+ if len(self.currentRemoteDir):
|
|
|
|
+ remoteDirString+='/'+'/'.join(self.currentRemoteDir)
|
|
|
|
+ ok,lst=self.fb.listRemoteDir(remoteDirString)
|
|
|
|
+ flist=[self.fb.baseDir(f) for f in lst]
|
|
print("Got")
|
|
print("Got")
|
|
print(flist)
|
|
print(flist)
|
|
flist.insert(0,'..')
|
|
flist.insert(0,'..')
|
|
@@ -365,20 +476,32 @@ class labkeyBrowserWidget(ScriptedLoadableModuleWidget):
|
|
|
|
|
|
def onLoadFileButtonClicked(self):
|
|
def onLoadFileButtonClicked(self):
|
|
properties={}
|
|
properties={}
|
|
- localPath=self.network.DownloadFileToCache(self.selectedFile.text)
|
|
|
|
|
|
+
|
|
|
|
+ #local path
|
|
|
|
+ tempDir=os.path.join(os.path.expanduser('~'),'temp')
|
|
|
|
+ if not os.path.isdir(tempDir):
|
|
|
|
+ os.mkdir(tempDir)
|
|
|
|
+ localPath=os.path.join(tempDir,self.currentRemoteDir[-1])
|
|
|
|
+
|
|
|
|
+ print(localPath)
|
|
|
|
+
|
|
|
|
+ #remote path
|
|
|
|
+ remotePath=self.fb.GetRootUrl()+'/'+'/'.join(self.currentRemoteDir)
|
|
|
|
+ print(remotePath)
|
|
|
|
+
|
|
|
|
+ #copy over
|
|
|
|
+ self.fb.readFileToFile(remotePath,localPath)
|
|
|
|
+
|
|
|
|
+ #do slicer magic
|
|
slicer.util.loadNodeFromFile(localPath,self.fileTypeSelector.currentText,
|
|
slicer.util.loadNodeFromFile(localPath,self.fileTypeSelector.currentText,
|
|
properties,returnNode=False)
|
|
properties,returnNode=False)
|
|
- if not self.keepCachedFileCheckBox.isChecked():
|
|
|
|
- os.remove(localPath)
|
|
|
|
|
|
+
|
|
|
|
+ #if not self.keepCachedFileCheckBox.isChecked():
|
|
|
|
+ os.remove(localPath)
|
|
|
|
|
|
def onLoadDirButtonClicked(self):
|
|
def onLoadDirButtonClicked(self):
|
|
- #dir=self.network.loadDir(self.selectedFile.text)
|
|
|
|
- dir=self.selectedFile.text
|
|
|
|
- try:
|
|
|
|
- self.loadDicomLogic.load(self.network,dir)
|
|
|
|
- except:
|
|
|
|
- self.loadDicomLogic=loadDicom.loadDicomLogic(self)
|
|
|
|
- self.loadDicomLogic.load(self.network,dir)
|
|
|
|
|
|
+
|
|
|
|
+ print('Not implemented')
|
|
|
|
|
|
# labkeySlicerPythonExtensionLogic
|
|
# labkeySlicerPythonExtensionLogic
|
|
#
|
|
#
|
|
@@ -524,3 +647,45 @@ def getHomeDir():
|
|
except:
|
|
except:
|
|
fhome=os.environ['HOMEDRIVE']+os.environ['HOMEPATH']
|
|
fhome=os.environ['HOMEDRIVE']+os.environ['HOMEPATH']
|
|
return fhome
|
|
return fhome
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def loadLibrary(name):
|
|
|
|
+ #load library from git, store it at a default location and return path to the stored location
|
|
|
|
+ remoteSources={
|
|
|
|
+ "labkeyInterface":\
|
|
|
|
+ "http://wiscigt.powertheword.com/labkey/labkeyinterface/-/archive/master/labkeyinterface-master.zip"
|
|
|
|
+ }
|
|
|
|
+ #two steps:
|
|
|
|
+ #1 Download
|
|
|
|
+
|
|
|
|
+ tempDir=os.path.join(os.path.expanduser('~'),'temp')
|
|
|
|
+ if not os.path.isdir(tempDir):
|
|
|
|
+ os.mkdir(tempDir)
|
|
|
|
+ tempFile=os.path.join(tempDir,name+'.zip')
|
|
|
|
+
|
|
|
|
+ http = urllib3.PoolManager()
|
|
|
|
+ r = http.request('GET', remoteSources[name], preload_content=False)
|
|
|
|
+ chunk_size=65536
|
|
|
|
+ with open(tempFile, 'wb') as out:
|
|
|
|
+ while True:
|
|
|
|
+ data = r.read(chunk_size)
|
|
|
|
+ if not data:
|
|
|
|
+ break
|
|
|
|
+ out.write(data)
|
|
|
|
+
|
|
|
|
+ r.release_conn()
|
|
|
|
+
|
|
|
|
+ #2 Unzip
|
|
|
|
+ installDir=os.path.join(os.path.expanduser('~'),'.labkey','software','src')
|
|
|
|
+ if not os.path.isdir(installDir):
|
|
|
|
+ os.makedirs(installDir)
|
|
|
|
+
|
|
|
|
+ with zipfile.ZipFile(tempFile,'r') as zip_ref:
|
|
|
|
+ zip_ref.extractall(installDir)
|
|
|
|
+ #cleanup
|
|
|
|
+ os.remove(tempFile)
|
|
|
|
+
|
|
|
|
+ zipName=name.lower()+'-master'
|
|
|
|
+ os.rename(os.path.join(installDir,zipName),os.path.join(installDir,name))
|
|
|
|
+
|
|
|
|
+ return os.path.join(installDir,name)
|