|
@@ -9,10 +9,17 @@ class labkeyFileBrowser:
|
|
|
|
|
|
def GetRootUrl(self):
|
|
|
return self.net.GetLabkeyUrl()+"/_webdav"
|
|
|
-
|
|
|
+
|
|
|
+ def entryExists(self,url):
|
|
|
+ #check if entry (file/directory) exists
|
|
|
+ r=self.net.head(url)
|
|
|
+ if r.status==200:
|
|
|
+ return True
|
|
|
+ return False
|
|
|
+
|
|
|
def listRemoteDir(self,url):
|
|
|
#input is remoteDir, result are remoteDirs
|
|
|
-
|
|
|
+ dirs=[]
|
|
|
#r=MethodRequest(dirUrl,method="PROPFIND")
|
|
|
PROPFIND=u"""<?xml version="1.0" encoding="utf-8"?>\n
|
|
|
<propfind xmlns="DAV:">\n
|
|
@@ -34,9 +41,15 @@ class labkeyFileBrowser:
|
|
|
print(e)
|
|
|
return False,dirs
|
|
|
|
|
|
- tree=ET.XML(f.data)
|
|
|
+ try:
|
|
|
+ tree=ET.XML(f.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,dirs
|
|
|
+
|
|
|
rps=tree.findall('{DAV:}response')
|
|
|
- dirs=[]
|
|
|
for r in rps:
|
|
|
hr=r.find('{DAV:}href')
|
|
|
dirent=hr.text
|
|
@@ -46,6 +59,17 @@ class labkeyFileBrowser:
|
|
|
del dirs[0]
|
|
|
return True,dirs
|
|
|
|
|
|
+ def buildPathURL(self,project,pathList):
|
|
|
+ #build/check remote directory structure
|
|
|
+ remoteDir=self.formatPathURL(project,'')
|
|
|
+ for p in pathList:
|
|
|
+ remoteDir+='/'+p
|
|
|
+ if not self.entryExists(remoteDir):
|
|
|
+ self.mkdir(remoteDir)
|
|
|
+
|
|
|
+ return remoteDir
|
|
|
+
|
|
|
+
|
|
|
def readFileToBuffer(self, url):
|
|
|
return self.net.get(url,binary=True)
|
|
|
|