implemented mkdir, exists, and copy for dropbox vfs

removed "dropbox path" setting
This commit is contained in:
robweber 2012-11-05 12:25:25 -06:00
parent 33e10c2a61
commit 5b6b5d6c9a
3 changed files with 64 additions and 13 deletions

View File

@ -118,7 +118,7 @@ class XbmcBackup:
self.remote_vfs.set_root(utils.getSetting("remote_path"))
elif(utils.getSetting('remote_selection') == '2'):
self.remote_vfs = DropboxFileSystem()
self.remote_vfs.set_root(utils.getSetting("dropbox_path"))
self.remote_vfs.set_root('/')
def run(self,mode=-1,runSilent=False):
#check if we should use the progress bar

View File

@ -1,6 +1,8 @@
import utils as utils
import xbmc
import xbmcvfs
import xbmcgui
import sys
from dropbox import client, rest, session
APP_KEY = 'f5wlmek6aoriqax'
@ -56,24 +58,74 @@ class XBMCFileSystem(Vfs):
return xbmcvfs.exists(aFile)
class DropboxFileSystem(Vfs):
user_token = None
client = None
def __init__(self):
self.user_token = utils.getSetting('dropbox_token')
user_token_key,user_token_secret = self.getToken()
sess = session.DropboxSession(APP_KEY,APP_SECRET,"app_folder")
if(self.user_token == ''):
if(user_token_key == '' and user_token_secret == ''):
token = sess.obtain_request_token()
url = sess.build_authorize_url(token)
try:
self.user_token = sess.obtain_access_token(token)
utils.setSetting("dropbox_token",self.user_token)
except:
xbmcgui.Dialog().ok(utils.getString(30010),"Authorize Dropbox URL, also in log",url)
#print url in log
utils.log("Authorize URL: " + url)
xbmcgui.Dialog().ok(utils.getString(30010),"Check Log For Dropbox Authorize URL","Click OK When Authorized")
#if user authorized this will work
user_token = sess.obtain_access_token(token)
self.setToken(user_token.key,user_token.secret)
else:
sess.set_token(user_token_key,user_token_secret)
self.client = client.DropboxClient(sess)
utils.log(self.client.account_info())
utils.log(str(self.client.account_info()))
def mkdir(self,directory):
if(self.client != None):
if(not self.exists(directory)):
self.client.file_create_folder(directory)
return True
else:
return False
def exists(self,aFile):
if(self.client != None):
try:
meta_data = self.client.metadata(aFile)
#if we make it here the file does exist
return True
except:
return False
else:
return False
def copy(self,source,dest):
if(self.client != None):
f = open(source,'rb')
response = self.client.put_file(dest,f,True)
return True
else:
return False
def setToken(self,key,secret):
#write the token files
token_file = open(xbmc.translatePath(utils.data_dir() + "tokens.txt"),'w')
token_file.write("%s|%s" % (key,secret))
token_file.close()
def getToken(self):
#get tokens, if they exist
if(xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + "tokens.txt"))):
token_file = open(xbmc.translatePath(utils.data_dir() + "tokens.txt"))
key,secret = token_file.read().split('|')
token_file.close()
return [key,secret]
else:
return ["",""]

View File

@ -5,8 +5,7 @@
<setting id="remote_selection" type="enum" lvalues="30018|30019|30027" default="0" label="30025"/>
<setting id="remote_path_2" type="text" label="30024" default="" visible="eq(-1,1)" />
<setting id="remote_path" type="folder" label="30020" visible="eq(-2,0)" />
<setting id="dropbox_path" type="text" label="Dropbox Path" visible="eq(-3,2)" default="/xbmc" />
<setting id="backup_name" type="text" label="30021" default="backup_date" visible="eq(-5,1)"/>
<setting id="backup_name" type="text" label="30021" default="backup_date" visible="eq(-4,1)"/>
<setting id="backup_rotation" type="number" label="30026" default="0" />
<setting id="run_silent" type="bool" label="30022" default="false" />
</category>