diff --git a/resources/lib/backup.py b/resources/lib/backup.py index 7924644..986f893 100644 --- a/resources/lib/backup.py +++ b/resources/lib/backup.py @@ -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 diff --git a/resources/lib/vfs.py b/resources/lib/vfs.py index e73928a..c43fcf5 100644 --- a/resources/lib/vfs.py +++ b/resources/lib/vfs.py @@ -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) - utils.log("Authorize URL: " + 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 ["",""] diff --git a/resources/settings.xml b/resources/settings.xml index 72f36cc..203998c 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -5,8 +5,7 @@ - - +