updated dropbox methods - listdir now works

This commit is contained in:
robweber 2012-11-05 15:46:17 -06:00
parent 5b6b5d6c9a
commit 535cd43e8a

View File

@ -83,6 +83,23 @@ class DropboxFileSystem(Vfs):
self.client = client.DropboxClient(sess)
utils.log(str(self.client.account_info()))
def listdir(self,directory):
if(self.client != None and self.exists(directory)):
files = []
dirs = []
metadata = self.client.metadata(directory)
for aFile in metadata['contents']:
if(aFile['is_dir']):
dirs.append(aFile['path'][len(directory):])
else:
files.append(aFile['path'][len(directory):])
return [dirs,files]
else:
return [[],[]]
def mkdir(self,directory):
if(self.client != None):
if(not self.exists(directory)):
@ -91,6 +108,12 @@ class DropboxFileSystem(Vfs):
else:
return False
def rmdir(self,directory):
if(self.client != None and self.exists(directory)):
self.client.file_delete(directory)
else:
return False
def exists(self,aFile):
if(self.client != None):
try:
@ -105,8 +128,13 @@ class DropboxFileSystem(Vfs):
def copy(self,source,dest):
if(self.client != None):
f = open(source,'rb')
response = self.client.put_file(dest,f,True)
return True
try:
response = self.client.put_file(dest,f,True)
return True
except:
#if we have an exception retry
retry = True
return self.copy(source,dest)
else:
return False