Explorar o código

Removing superflous files

Andrej %!s(int64=4) %!d(string=hai) anos
pai
achega
7400d9fb8d
Modificáronse 2 ficheiros con 0 adicións e 1038 borrados
  1. 0 298
      labkeyBrowser/fileIO.py
  2. 0 740
      labkeyBrowser/slicerNetwork.py

+ 0 - 298
labkeyBrowser/fileIO.py

@@ -1,298 +0,0 @@
-import slicerNetwork
-import slicer
-import qt
-import ctk
-import json
-import os
-import shutil
-
-class fileIO(slicer.ScriptedLoadableModule.ScriptedLoadableModule):
-    def __init__(self,parent):
-        slicer.ScriptedLoadableModule.ScriptedLoadableModule.__init__(self, parent)
-        self.className="fileIO"
-        self.parent.title="fileIO"
-
-        self.parent.categories = ["LabKey"]
-        self.parent.dependencies = []
-        self.parent.contributors = ["Andrej Studen (UL/FMF)"] # replace with "Firstname Lastname (Organization)"
-        self.parent.helpText = """
-                    File IO for Labkey interface to slicer
-                                """
-        self.parent.acknowledgementText = """
-            Developed within the medical physics research programme of the Slovenian research agency.
-                """ # replace with organization, grant and thanks.
-
-class remoteFileSelector(qt.QMainWindow):
-    def __init__(self, parent=None):
-        super(remoteFileSelector, self).__init__(parent)
-        self.setup()
-
-
-    def setMaster(self,master):
-        self.master=master
-
-    def setup(self):
-        centralWidget=qt.QWidget(self)
-        fileDialogFormLayout = qt.QFormLayout(centralWidget)
-        #self.layout.addWidget(fileDialogFormLayout)
-
-        #add item list for each found file/directory
-        self.fileList=qt.QListWidget()
-        self.fileList.toolTip="Select remote file"
-        self.fileList.itemDoubleClicked.connect(self.onFileListDoubleClicked)
-        self.currentRelativeDir=''
-
-        #add dummy entry
-        items=('.','..')
-        self.populateFileList(items)
-
-        fileDialogFormLayout.addWidget(self.fileList)
-
-        self.selectedPath=qt.QLineEdit("")
-        self.selectedPath.toolTip="Selected path"
-
-        fileDialogFormLayout.addRow("Selected path :",self.selectedPath)
-
-        self.closeButton=qt.QPushButton("Close")
-        self.closeButton.toolTip="Close"
-        self.closeButton.connect('clicked(bool)',self.onCloseButtonClicked)
-        fileDialogFormLayout.addRow(self.closeButton)
-        self.setCentralWidget(centralWidget);
-
-    def onFileListDoubleClicked(self,item):
-        if item == None:
-            print("Selected items: None")
-            return
-
-        iText=item.text()
-        print ("Selected items: {0} ").format(iText)
-
-
-        #this is hard -> compose path string from currentRelativeDir and selection
-        if item.text().find('..')==0:
-            #one up
-            idx=self.currentRelativeDir.rfind('/')
-            if idx<0:
-                self.currentRelativeDir=''
-            else:
-                self.currentRelativeDir=self.currentRelativeDir[:idx]
-        elif item.text().find('.')==0:
-            pass
-        else:
-            if len(self.currentRelativeDir)>0:
-                self.currentRelativeDir+='/'
-            self.currentRelativeDir+=item.text()
-
-        print ("Listing {0}").format(self.currentRelativeDir)
-        flist=self.master.network.toRelativePath(
-            self.master.network.listRelativeDir(self.currentRelativeDir))
-        print ("Got")
-        print (flist)
-        flist.insert(0,'..')
-        flist.insert(0,'.')
-        self.populateFileList(flist)
-        self.selectedPath.setText(self.currentRelativeDir)
-        self.master.remotePath.setText(self.master.network.GetLabkeyPathFromRelativePath(self.currentRelativeDir))
-
-    def populateFileList(self,items):
-        self.fileList.clear()
-        for it_text in items:
-          item=qt.QListWidgetItem(self.fileList)
-          item.setText(it_text)
-          item.setIcon(qt.QIcon(it_text))
-
-    def onCloseButtonClicked(self):
-        self.hide()
-
-
-class fileIOWidget(slicer.ScriptedLoadableModule.ScriptedLoadableModuleWidget):
-    def __init__(self,parent):
-       slicer.ScriptedLoadableModule.ScriptedLoadableModuleWidget.__init__(self, parent)
-       self.selectRemote=remoteFileSelector()
-       #self.selectLocal=qt.QFileDialog()
-       #self.selectLocal.connect('fileSelected(QString)',self.onLocalFileSelected)
-       self.selectRemote.setMaster(self)
-       self.network=slicerNetwork.labkeyURIHandler()
-
-    def setup(self):
-        connectionCollapsibleButton = ctk.ctkCollapsibleButton()
-        connectionCollapsibleButton.text = "Connection"
-        self.layout.addWidget(connectionCollapsibleButton)
-
-        connectionFormLayout = qt.QFormLayout(connectionCollapsibleButton)
-        self.loadConfigButton=qt.QPushButton("Load configuration")
-        self.loadConfigButton.toolTip="Load configuration"
-        self.loadConfigButton.connect('clicked(bool)',self.onLoadConfigButtonClicked)
-        connectionFormLayout.addRow("Connection:",self.loadConfigButton)
-
-        fileDialogCollapsibleButton = ctk.ctkCollapsibleButton()
-        fileDialogCollapsibleButton.text = "Paths"
-        self.layout.addWidget(fileDialogCollapsibleButton)
-
-        fileDialogFormLayout = qt.QFormLayout(fileDialogCollapsibleButton)
-
-        self.listRemoteButton=qt.QPushButton("List Remote")
-        self.listRemoteButton.toolTip="List Remote"
-        self.listRemoteButton.connect('clicked(bool)',self.onListRemoteButtonClicked)
-        fileDialogFormLayout.addRow(self.listRemoteButton)
-
-        self.listLocalButton=qt.QPushButton("List Local")
-        self.listLocalButton.toolTip="List Local"
-        self.listLocalButton.connect('clicked(bool)',self.onListLocalButtonClicked)
-        fileDialogFormLayout.addRow(self.listLocalButton)
-
-        #add selected file display
-        self.remotePath=qt.QLineEdit("")
-        self.remotePath.toolTip="Remote path"
-
-        fileDialogFormLayout.addRow("RemotePath :",self.remotePath)
-
-        self.localPath=qt.QLineEdit("")
-        self.localPath.toolTip="Local path"
-
-        fileDialogFormLayout.addRow("LocalPath :",self.localPath)
-
-        copyToRemoteButton=qt.QPushButton("Local->Remote")
-        copyToRemoteButton.toolTip="Local -> Remote"
-        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)
-        fileDialogFormLayout.addRow(removeRemoteButton)
-
-        mkdirRemoteButton=qt.QPushButton("Mkdir remote")
-        mkdirRemoteButton.toolTip="Mkdir Remote"
-        mkdirRemoteButton.connect('clicked(bool)',self.onMkdirRemoteButtonClicked)
-        fileDialogFormLayout.addRow(mkdirRemoteButton)
-
-    def onListLocalButtonClicked(self):
-        self.localPath.setText(qt.QFileDialog.getOpenFileName(None,"Select local"))
-
-    def onListRemoteButtonClicked(self):
-        self.selectRemote.show()
-
-    def onLoadConfigButtonClicked(self):
-
-        filename=qt.QFileDialog.getOpenFileName(None,'Open configuration file (JSON)',
-            '.', '*.json')
-
-        with open(filename,'r') as f:
-           dt=json.load(f)
-
-        if dt.has_key('host'):
-           self.network.hostname=dt['host']
-
-        if dt.has_key('SSL'):
-           self.network.configureSSL(dt['SSL']['user'],dt['SSL']['key'],
-                dt['SSL']['keyPwd'],dt['SSL']['ca'])
-
-        if dt.has_key('labkey'):
-           if dt['labkey'].has_key('user'):
-               self.network.auth_name=dt['labkey']['user']
-           if dt['labkey'].has_key('password'):
-               self.network.auth_pass=dt['labkey']['password']
-
-        self.loadConfigButton.setText(os.path.basename(filename))
-        self.network.initRemote()
-
-    def copyLocalToRemote(self,localPath,remotePath):
-        if os.path.isfile(localPath):
-            #end recursion
-            print ("Copy {} to {}").format(localPath,remotePath)
-            self.network.copyLocalFileToRemote(localPath,remotePath)
-            return
-
-        dirName=os.path.basename(os.path.normpath(localPath))
-        remotePath+='/'+dirName
-        if not self.network.isRemoteDir(remotePath):
-            self.network.mkdir(remotePath+'/')
-        for f in os.listdir(localPath):
-            #enter recursion
-            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):
-            resp=qt.QMessageBox.question(None,'Delete directory',
-                'Do you want to delete directory {}'.format(remotePath))
-            if resp == qt.QMessageBox.No:
-                return
-        self.network.rmdir(remotePath)
-
-    def onMkdirRemoteButtonClicked(self):
-        remotePath=self.remotePath.text
-        self.network.mkdir(remotePath)
-
-
-class fileIOLogic(slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic):
-    def __init__(self,parent):
-       slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic.__init__(self, parent)
-
-
-class fileIOTest(slicer.ScriptedLoadableModule.ScriptedLoadableModuleTest):
-  """
-  This is the test case for your scripted module.
-  Uses ScriptedLoadableModuleTest base class, available at:
-  https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
-  """
-
-  def setUp(self):
-    """ Do whatever is needed to reset the state - typically a scene clear will be enough.
-    """
-    slicer.mrmlScene.Clear(0)
-
-  def runTest(self):
-    """Run as few or as many tests as needed here.
-    """
-    self.setUp()
-    self.test_fileIO()
-
-  def test_fileIO(self):
-    """ Ideally you should have several levels of tests.  At the lowest level
-    tests should exercise the functionality of the logic with different inputs
-    (both valid andclass dataExplorerTest(ScriptedLoadableModuleTest):
-  """
-    pass

+ 0 - 740
labkeyBrowser/slicerNetwork.py

@@ -1,740 +0,0 @@
-import qt
-import urllib3
-import xml.etree.ElementTree as ET
-import re
-import slicer
-import shutil
-import distutils
-import os
-import json
-import chardet
-import io
-
-#mimics labkeyInterface
-class slicerNetwork(slicer.ScriptedLoadableModule.ScriptedLoadableModule):
-    def __init__(self, parent):
-        slicer.ScriptedLoadableModule.ScriptedLoadableModule.__init__(self,parent)
-        self.parent.title="slicerNetwork"
-        pass
-
-
-class DummyResponse:
-    pass
-
-class labkeyURIHandler(slicer.vtkURIHandler):
-    def __init__(self):
-        slicer.vtkURIHandler.__init__(self)
-        self.className="labkeyURIHandler"
-        slicer.mrmlScene.AddURIHandler(self)
-
-        fhome=os.path.expanduser('~')
-        self.localCacheDirectory=os.path.join(fhome,"labkeyCache")
-        self.configDir=os.path.join(fhome,".labkey")
-        #try initializing network from default config file, if found
-        self.initFromConfig()
-
-
-    def CanHandleURI(self,uri):
-        print("labkeyURIHandler::CanHandleURI({0})".format(uri))
-        if uri.find('labkey://')==0:
-            return 1
-        return 0
-
-    def GetClassName(self):
-        return self.className
-
-
-    def GetHostName(self):
-        self.hostname=self.connectionConfig['host']
-        print("Host name:{}".format(self.hostname))
-        return self.hostname
-
-    def SetHostName(self,host):
-        try:
-            self.connectionConfig['host']=host
-        except AttributeError:
-            self.connectionConfig={}
-            self.connectionConfig['host']=host
-
-        self.hostname=host
-
-    def SetLocalCahceDirectory(self,dir):
-        self.localCacheDirectory=dir
-
-    def GetLocalCacheDirectory(self):
-        return self.localCacheDirectory
-
-    def GetLabkeyUrl(self):
-        return self.GetHostName()+"/labkey"
-
-    def GetLabkeyWebdavUrl(self):
-        return self.GetLabkeyUrl()+"/_webdav"
-
-    #configuration part
-
-    def configureSSL(self,cert=None,key=None,pwd=None,cacert=None):
-        print("configure SSL: {}".format(cert))
-
-        if not cert==None:
-            self.http = urllib3.PoolManager(\
-                    cert_file=cert,\
-                    cert_reqs='CERT_REQUIRED',\
-                    key_file=key,\
-                    ca_certs=cacert)
-        else:
-            self.http = urllib3.PoolManager(\
-                    cert_reqs='CERT_REQUIRED',\
-                    ca_certs=cacert)
-
-    def initRemote(self):
-        #assume self.connectionConfig is set
-        self.http=urllib3.PoolManager()
-        try:
-            config=self.connectionConfig
-        except AttributeError:
-            print("ConnectionConfig not initialized")
-            return
-        
-        if 'SSL' in self.connectionConfig:
-            print("Setting up SSL")
-            try:
-                cert=self.connectionConfig['SSL']['user']
-            except KeyError:
-                print("No user cert supplied")
-                return
-            try:
-                key=self.connectionConfig['SSL']['key']
-            except KeyError:
-                print("No user key supplied")
-                return
-            try:
-                ca=self.connectionConfig['SSL']['ca']
-            except KeyError:
-                print("No CA cert supplied")
-                return
-                
-            self.configureSSL(cert,key,None,ca)
-
-
-    def initFromConfig(self):
-        print("slicerNetwork: initFromConfig")
-        path=os.path.join(self.configDir,"Remote.json")
-        try:
-            self.parseConfig(path)
-        except OSError:
-            return
-        self.initRemote()
-
-    def parseConfig(self,fname,parent=None):
-        print("slicerNetwork: parseConfig") 
-        try:
-            with open(fname) as f:
-                self.connectionConfig=json.load(f)
-        except OSError as e:
-            print("Confgiuration error: OS error({0}): {1}".format(e.errno, e.strerror))
-            raise
-        except AttributeError:
-            print("Troubles parsing json at {}".format(fname))
-
-        if not parent==None:
-            parent.userCertButton.setText(self.connectionConfig['SSL']['user'])
-            parent.caCertButton.setText(self.connectionConfig['SSL']['ca'])
-            parent.privateKeyButton.setText(self.connectionConfig['SSL']['key'])
-            parent.pwd=self.connectionConfig['SSL']['keyPwd']
-
-
-        self.hostname=self.connectionConfig['host']
-        self.auth_name=self.connectionConfig['labkey']['user']
-        self.auth_pass=self.connectionConfig['labkey']['password']
-        if not parent==None:
-            parent.serverURL.setText(self.connectionConfig['host'])
-            parent.authName.setText(self.connectionConfig['labkey']['user'])
-            parent.authPass.setText(self.connectionConfig['labkey']['password'])
-
-
-    #path convention
-
-    #localPath is a path on local filesystem. It means it has to adhere to OS
-    #policy, especially in separators
-
-    #relativePath is just the portion of the path that is equal both locally
-    #and remotely. In relativePath, separator is according to http convention,
-    #which equals separator in osx and *nix
-
-    #labkeyPath or remotePath is the full URL to the resource,
-    #including http-like header and all intermediate portions
-
-    #the following functions convert between different notations
-
-    #was GetLocalPath
-    def GetLocalPathFromRelativePath(self,relativePath):
-        debug=False
-        relativePath=re.sub('labkey://','',relativePath)
-        sp=os.sep.encode('unicode_escape').decode('utf-8')
-        if debug:
-            print("Substituting / with {0} in {1}".format(sp,relativePath))
-        relativePath=re.sub('/',sp,relativePath)
-        return os.path.join(self.GetLocalCacheDirectory(),relativePath)
-
-    #was GetRemotePath
-    def GetLabkeyPathFromRelativePath(self,source):
-        return self.GetLabkeyWebdavUrl()+"/"+source
-
-    #was GetLabkeyPathFromLocalPath
-    def GetRelativePathFromLocalPath(self,f):
-        debug=False
-        #report it with URL separator, forward-slash
-        if f.find(self.localCacheDirectory)<-1:
-            print("Localpath misformation. Exiting")
-            return "NULL"
-        f0=re.sub('\\\\','\\\\\\\\',self.localCacheDirectory)
-        relativePath=re.sub(re.compile(f0),'',f)
-        if debug:
-            print("[SEP] Relative path {}".format(relativePath))
-        #leaves /ContextPath/%40files/subdirectory_list/files
-        #remove first separator
-        sp=os.path.sep
-        f1=re.sub('\\\\','\\\\\\\\',sp)
-        if relativePath[0]==sp:
-            relativePath=relativePath[1:len(relativePath)]
-
-        if debug:
-            print("[SLASH] Relative path {}".format(relativePath))
-
-        return re.sub(f1,'/',relativePath)
-
-    #was GetLabkeyPathFromRemotePath
-    def GetRelativePathFromLabkeyPath(self,f):
-        #used to query labkey stuff, so URL separator is used
-
-        #in old conventions, labkey://was used to tag a labkeyPath
-        f=re.sub('labkey://','',f)
-        f=re.sub(self.GetLabkeyWebdavUrl(),'',f)
-
-        if f[0]=='/':
-            f=f[1:len(f)]
-        return f;
-    
-    def getBasicAuth(self):
-
-        user=self.connectionConfig['labkey']['user']
-        pwd=self.connectionConfig['labkey']['password']
-        #debug
-        return user+":"+pwd
-     
-
-    #standard HTTP
-    def get(self,url,binary=False):
-
-        debug=True
-        if debug:
-            print("GET: {0}".format(url))
-            print("as {0}".format(self.connectionConfig['labkey']['user']))
-        headers=urllib3.util.make_headers(basic_auth=self.getBasicAuth())
-        try:
-            if not binary:
-                return self.http.request('GET',url,headers=headers)
-            else:
-                return self.http.request('GET',url,headers=headers,preload_content=False)
-        #f contains json as a return value
-        #f contains json as a return value
-        except urllib3.exceptions.HTTPError as e:
-            print("HTTP error {}".format(e))
-            response=DummyResponse()
-            response.status=1000
-            response.data=str(e)
-            return response
-
-    #a HEAD request
-    def head(self,url):
-    
-        debug=False
-        if debug:
-            print("HEAD: {0}".format(url))
-            print("as {0}".format(self.auth_name))
-        headers=urllib3.util.make_headers(basic_auth=self.getBasicAuth())
-        
-        try:
-            return self.http.request('HEAD',url,headers=headers)
-        except urllib3.exceptions.HTTPError as e:
-            print(e)
-            response=DummyResponse()
-            response.status=1000
-            response.data=str(e)
-            return response
-
-
-
-    def post(self,url,data):
-
-        debug=False
-        headers=urllib3.util.make_headers(basic_auth=self.getBasicAuth())
-        headers["Content-Type"]="application/json"
-        #add csrf;also sets self.cookie
-        headers["X-LABKEY-CSRF"]=self.getCSRF()
-        headers["Cookie"]=self.cookie
-
-        try:
-            return self.http.request('POST',url,headers=headers,body=data)
-        #f contains json as a return value
-        except urllib3.exceptions.HTTPError as e:
-            print(e)
-            response=DummyResponse()
-            response.status=1000
-            response.data=str(e)
-            return response
-
-
-    def put(self,url,data):
-   
-        debug=False
- 
-        if debug:
-            print("PUT: {}".format(url))
-
-        headers=urllib3.util.make_headers(basic_auth=self.getBasicAuth())
-        headers["Content-Type"]="application/octet-stream"
-        #add csrf
-        headers["X-LABKEY-CSRF"]=self.getCSRF()
-        headers["Cookie"]=self.cookie
-
-        try:
-            return self.http.request('PUT',url,headers=headers,body=data)
-        #f contains json as a return value
-        except urllib3.exceptions.HTTPError as e:
-            print(e)
-            response=DummyResponse()
-            response.status=1000
-            response.data=str(e)
-            return response
-    
-    def sendRequest(self,url,requestCode):
-
-        debug=False
-        headers=urllib3.util.make_headers(basic_auth=self.getBasicAuth())
-        #add csrf;also sets self.cookie
-        headers["X-LABKEY-CSRF"]=self.getCSRF()
-        headers["Cookie"]=self.cookie
-
-        try:
-            return self.http.request(requestCode,url,headers=headers)
-        #f contains json as a return value
-        except urllib3.exceptions.HTTPError as e:
-            print(e)
-            response=DummyResponse()
-            response.status=1000
-            response.data=str(e)
-            return response
-    
-    def mkcol(self,url):
-        return self.sendRequest(url,'MKCOL')
-
-    def delete(self,url):
-        return self.sendRequest(url,'DELETE')
-
-    def propfind(self,url,PROPFIND):
-        headers=urllib3.util.make_headers(basic_auth=self.getBasicAuth())
-        headers["Content-Type"]='text/xml; charset="utf-8"'
-        headers['content-length']=str(len(PROPFIND))
-        headers['Depth']='1'
-        #add csrf
-        headers["X-LABKEY-CSRF"]=self.getCSRF()
-        headers["Cookie"]=self.cookie
-
-        try:
-            return self.http.request('PROPFIND',url,headers=headers,body=PROPFIND)
-        #f contains json as a return value
-        except urllib3.exceptions.HTTPError as e:
-            print(e)
-            response=DummyResponse()
-            response.status=1000
-            response.data=str(e)
-            return response
-
-    @staticmethod 
-    def HTTPStatus(response,method=None):
-        if response.status==200:
-            return True
-        if method=='propfind':
-            if response.status==207:
-                return True
-        
-        print("Status: {}".format(response.status))
-        print("Data: {}".format(response.data))
-        return False
-
-    #a good testing routine; CSRF is required for content modifying requests
-    def getCSRF(self):
-        url=self.GetLabkeyUrl()+'/login/whoAmI.view'
-        try:
-            response=self.get(url)
-            if not labkeyURIHandler.HTTPStatus(response):
-                return None
-            encoding=chardet.detect(response.data)['encoding']
-            jsonData=json.loads(response.data.decode(encoding))
-        except AttributeError:
-            print("Response: {}".response.data)
-            print("Failed")
-            return None
-        #local cookie jar
-        self.cookie=response.getheader('Set-Cookie')
-        print("CSRF: {}".format(jsonData["CSRF"]))
-        user=jsonData['email']
-        if not user==self.connectionConfig['labkey']['user']:
-            print("User mismatch: {}/{}".format(user,self.connectionConfig['labkey']['user']))
-            return None
-        return jsonData["CSRF"]
-
-
-    #file manipulation routiens
-
-    #was GetFile
-    def DownloadFileToCache(self,relativePath):
-        debug=True
-        # check for file in cache. If available, use, if not, download
-        localPath=self.GetLocalPathFromRelativePath(relativePath)
-        if os.path.isfile(localPath):
-            if debug:
-                print("Returning localFile {}".format(localPath))
-            return localPath
-
-        if debug:
-            print("labkeyURIHandler::DownloadFileToCache({0}->{1})".format(relativePath,localPath))
-
-        #make all necessary directories LOCALLY
-        path=os.path.dirname(localPath)
-        if debug:
-            print("Target directory: '{}''".format(path))
-        if not os.path.isdir(path):
-            os.makedirs(path)
-
-        #make sure we are at the begining of the file
-
-
-        #labkeyPath=self.GetLabkeyPathFromRelativePath(relativePath)
-        remoteBuffer=self.readFileToBuffer(relativePath)
-
-	    #check file size
-        if debug:
-            print("Remote size: {}".format(remoteBuffer.seek(0,2)))
-            remoteBuffer.seek(0)
-
-        with open(localPath,'wb') as localBuffer:
-            shutil.copyfileobj(remoteBuffer,localBuffer)
-
-
-        print("Local size: {}".format(os.path.getsize(localPath)))
-
-        return localPath
-
-    def fileTypesAvailable(self):
-        return ('VolumeFile','SegmentationFile','TransformFile')
-
-    #mimic slicer.util.loadNodeFromFile
-    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)
-         
-         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:
-             if not keepCached:
-                 os.remove(localPath)
-             return node
-         
-
-         os.remove(localPath)
-         return None
-    #     #remove retrieved file
-
-    def storeNode(self,node,project,dir=None):
-
-        removeFile=True
-        relativePath=project+'/%40files'
-        if not dir==None:
-            relativePath+='/'+dir
-        labkeyPath=self.GetLabkeyPathFromRelativePath(relativePath)
-        print ("Remote: {}".format(labkeyPath))
-      
-        #checks if exists
-        self.mkdir(labkeyPath)
-
-        localPath=self.GetLocalPathFromRelativePath(relativePath)
-        localPath.replace('/',os.path.sep)
-
-        nodeName=node.GetName()
-
-        suffix=".nrrd"
-        if node.__class__.__name__=="vtkMRMLDoubleArrayNode":
-            suffix=".mcsv"
-        if node.__class__.__name__=="vtkMRMLTransformNode":
-            suffix=".h5"
-        fileName=nodeName+suffix
-        file=os.path.join(localPath,fileName)
-        slicer.util.saveNode(node,file)
-        print("Stored to: {}".format(file))
-        f=open(file,"rb")
-
-        f.seek(0,2)
-        sz=f.tell()
-        print("File size in memory: {0}".format(sz))
-        f.seek(0)
-
-        localBuffer=f.read()
-        print("Local buffer size: {}".format(len(localBuffer)))
-        remoteFile=labkeyPath+'/'+fileName
-        resp=self.put(remoteFile,localBuffer)
-        print(resp.read())
-        f.close()
-        if removeFile:
-            os.remove(file)
-    
-    def entryExists(self,url):
-
-        #use head
-        response=self.head(url)
-        return labkeyURIHandler.HTTPStatus(response)
-
-    def remoteDirExists(self,url):
-        #weaker, just checks if there is an entry at url, does not check wheter it is a dir
-        return self.entryExists(url)
-        #stronger, but more complicated
-        return self.isRemoteDir(url)
-
-    def mkdir(self,remoteDir):
-        if self.remoteDirExists(remoteDir):
-            return False
-        response=self.mkcol(remoteDir)
-        return labkeyURIHandler.HTTPStatus(response)
-
-    def mkdirs(self,remoteDir):
-        relativePath=self.GetRelativePathFromLabkeyPath(remoteDir)
-        s=0
-        while True:
-            s1=relativePath.find('/',s)
-            if s1<0:
-                break
-            path=relativePath[0:s1]
-            remotePath=self.GetLabkeyPathFromRelativePath(relativePath)
-            dirExists=self.remoteDirExists(remotePath)
-            if not dirExists:
-                if not self.mkdir(remotePath):
-                    return False
-            s=s1+1
-        return self.mkdir(remoteDir)
-
-    def rmdir(self,remoteDir):
-        if not self.remoteDirExists(remoteDir):
-            return True
-        return labkeyURIHandler.HTTPStatus(self.delete(remoteDir))
-
-    #was listDir
-    def listRelativeDir(self,relativeDir):
-        print("Listing for {0}".format(relativeDir))
-        dirUrl=self.GetLabkeyPathFromRelativePath(relativeDir)
-        print("Setting url: {}".format(dirUrl))
-        status,dirs=self.listRemoteDir(dirUrl)
-        dirs=[self.GetRelativePathFromLabkeyPath(d) for d in dirs];
-        return dirs
-
-    #was isDir
-    def isRemoteDir(self, remotePath):
-        #print "isDir: {}".format(remotePath)
-        PROPFIND=u"""<?xml version="1.0" encoding="utf-8"?>\n
-            <a:propfind xmlns:a="DAV:">\n
-            <a:prop>\n
-            <a:resourcetype/>\n
-            </a:prop>\n
-            </a:propfind>"""
-        response=self.propfind(remotePath,PROPFIND)
-        if not labkeyURIHandler.HTTPStatus(response,method='propfind'):
-            print("Bad status")
-            return False
-        
-        try:
-            tree=ET.XML(response.data)
-        except ET.ParseError:
-            #print(f.data.decode('utf-8'))
-            #if directory is not there, a 404 response will be made by HTTP, which is not an xml file
-            #we are safe to assume the directory is not there
-            return False
-        
-        try:
-            rps=tree.find('{DAV:}response').find('{DAV:}propstat')
-            rps=rps.find('{DAV:}prop')
-            rps=rps.find('{DAV:}resourcetype').find('{DAV:}collection')
-            if rps != None:
-                return True
-            else:
-                return False
-        except:
-            return False
-
-    def listRemoteDir(self,dirUrl):
-        #input is remoteDir, result are remoteDirs
-
-        PROPFIND=u"""<?xml version="1.0" encoding="utf-8"?>\n
-                    <propfind xmlns="DAV:">\n
-                    <prop>\n
-                    <getetag/>\n
-                    </prop>\n
-                    </propfind>"""
-        response=self.propfind(dirUrl,PROPFIND)
-        if not labkeyURIHandler.HTTPStatus(response,method='propfind'):
-            print("Bad status")
-            return False,[]
-
-        try:
-            tree=ET.XML(response.data)
-        except ET.ParseError:
-            print("Fail to parse XML")
-            return False,[]
-
-        rps=tree.findall('{DAV:}response')
-        dirs=[]
-        for r in rps:
-            hr=r.find('{DAV:}href')
-            dirent=hr.text
-            #dirent=re.sub('/labkey/_webdav/','',dirent)
-            dirent=self.GetHostName()+dirent
-            dirs.append(dirent)
-        del dirs[0]
-        return True,dirs
-
-    def toRelativePath(self,dirs):
-        flist1=[]
-        for d in dirs:
-            if d[-1]=='/':
-                d=d[:-1]
-            if d.rfind('/')>-1:
-                d=d[d.rfind('/')+1:]
-            flist1.append(d)
-        return flist1
-
-    def readFileToBuffer(self, relativePath):
-        dirUrl=self.GetLabkeyPathFromRelativePath(relativePath)
-        response=self.get(dirUrl,binary=True)
-        if not labkeyURIHandler.HTTPStatus(response):
-            return io.BytesIO()
-        #this will collect for all data
-        remoteBuffer=io.BytesIO(response.data)
-        response.release_conn()
-        return remoteBuffer
-
-    def uploadFile(self,localPath):
-        #get upstream directories sorted out
-        relativePath=self.GetRelativePathFromLocalPath(localPath)
-        if relativePath=="NULL":
-            errorCode="Failed to upload {}. Potential incorrect location"
-            errorCode+=". Should be in labkeyCache!"
-            print(errorCode.format(relativePath))
-            return False
-        relativeDir=relativePath[0:labkeyPath.rfind('/')]
-        remoteDir=self.GetLabkeyPathFromRemotePath(relativeDir)
-        if not self.remoteDirExists(remoteDir):
-            if not self.mkdirs(remoteDir):
-                errorCode="UploadFile: Could not create directory {}"
-                print(errorCode.format(remoteDir))
-                return False
-
-        #make an URL request
-        with open(localPath, 'rb') as f:
-            data=f.read()
-        remotePath=self.GetLabkeyPathFromRelativePath(relativePath)
-        self.put(remotePath,data)
-
-    #was copyFileToRemote
-    def copyLocalFileToRemote(self,localPath, remotePath):
-        #get upstream directories sorted out
-
-        remoteDir=os.path.dirname(remotePath)
-        if not self.remoteDirExists(remoteDir):
-            if not self.mkdirs(remoteDir):
-                errorCode="UploadFile: Could not create directory {}"
-                print(errorCode.format(remoteDir))
-                return False
-
-        #make an URL request
-        if (self.isRemoteDir(remotePath)):
-            remotePath=remotePath+'/'+os.path.basename(localPath)
-
-        with open(localPath, 'rb') as f:
-            data=f.read()
-        self.put(remotePath,data)
-
-    #was loadDir
-    def DownloadDirToCache(self, relativePath):
-
-        files=self.listRelativeDir(relativePath)
-        fdir="NONE"
-        for f in files:
-            #f is local path
-            try:
-                localDir=os.path.dirname(self.DownloadFileToCache(f))
-            except:
-                #fails if there is a subdirectory; go recursively
-                print("self.readDir(f) not implemented")
-        return localDir
-
-    #database routines
-    @staticmethod
-    def getJSON(response):
-        encoding=chardet.detect(response.data)['encoding']
-        return json.loads(response.data.decode(encoding))
-
-
-    def loadDataset(self,project,dataset):
-        url=self.GetLabkeyUrl()+'/'+project
-        url+='/query-selectRows.api?schemaName=study&query.queryName='+dataset
-        return labkeyURIHandler.getJSON(self.get(url))
-
-    def filterDataset(self,project,dataset,filter):
-        debug=False
-        url=self.GetLabkeyUrl()+'/'+project
-        url+='/query-selectRows.api?schemaName=study&query.queryName='+dataset
-        for f in filter:
-            url+="&query."+f['variable']+"~"+f['oper']+"="+f['value']
-        if debug:
-            print("Sending {}".format(url))
-        return labkeyURIHandler.getJSON(self.get(url))
-
-
-    def modifyDataset(self,method,project,dataset,rows):
-        #method can be insert or update
-        data={}
-        data['schemaName']='study'
-        data['queryName']=dataset
-        data['rows']=rows
-        url=self.GetLabkeyUrl()+'/'+project
-        url+='/query-'+method+'Rows.api?'
-        return self.post(url,json.dumps(data)).data
-
-    def filterList(self,project,dataset,filter):
-        schemaName='lists'
-        debug=False
-        url=self.GetLabkeyUrl()+'/'+project
-        url+='/query-selectRows.api?schemaName='+schemaName+'&query.queryName='+dataset
-        for f in filter:
-            url+="&query."+f['variable']+"~"+f['oper']+"="+f['value']
-        if debug:
-            print("Sending {}".format(url))
-        return labkeyURIHandler.getJSON(self.get(url))
-
-
-    def modifyList(self,method,project,dataset,rows):
-        #method can be insert or update
-        data={}
-        schemaName='lists'
-        data['schemaName']=schemaName
-        data['queryName']=dataset
-        data['rows']=rows
-        url=self.GetLabkeyUrl()+'/'+project
-        url+='/query-'+method+'Rows.api?'
-        return self.post(url,json.dumps(data)).data