diff --git a/addon.xml b/addon.xml index a58bd05..285ed85 100644 --- a/addon.xml +++ b/addon.xml @@ -2,12 +2,10 @@ - - diff --git a/launcher.py b/launcher.py index 8588799..5db2126 100644 --- a/launcher.py +++ b/launcher.py @@ -1,7 +1,7 @@ import sys from kodi_six import xbmc, xbmcgui, xbmcvfs import resources.lib.utils as utils -from resources.lib.authorizers import DropboxAuthorizer,GoogleDriveAuthorizer +from resources.lib.authorizers import DropboxAuthorizer from resources.lib.advanced_editor import AdvancedBackupEditor @@ -17,15 +17,6 @@ def authorize_cloud(cloudProvider): else: xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30107) + ' ' + utils.getString(30027)) - #google drive - elif(cloudProvider == 'google_drive'): - authorizer = GoogleDriveAuthorizer() - - if(authorizer.authorize()): - xbmcgui.Dialog().ok("Backup",utils.getString(30098) + ' ' + utils.getString(30106)) - else: - xbmcgui.Dialog().ok("Backup",utils.getString(30107) + ' ' + utils.getString(30098)) - def remove_auth(): #triggered from settings.xml - asks if user wants to delete OAuth token information shouldDelete = xbmcgui.Dialog().yesno(utils.getString(30093),utils.getString(30094),utils.getString(30095),autoclose=7000) diff --git a/resources/lib/authorizers.py b/resources/lib/authorizers.py index 0763017..98ff8d7 100644 --- a/resources/lib/authorizers.py +++ b/resources/lib/authorizers.py @@ -8,12 +8,6 @@ try: except ImportError: pass -try: - from resources.lib.pydrive.auth import GoogleAuth - from resources.lib.pydrive.drive import GoogleDrive -except ImportError: - pass - class DropboxAuthorizer: APP_KEY = "" APP_SECRET = "" @@ -110,62 +104,3 @@ class DropboxAuthorizer: def _deleteToken(self): if(xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + "tokens.txt"))): xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "tokens.txt")) - -class GoogleDriveAuthorizer: - CLIENT_ID = '' - CLIENT_SECRET = '' - - def __init__(self): - self.CLIENT_ID = utils.getSetting('google_drive_id') - self.CLIENT_SECRET = utils.getSetting('google_drive_secret') - - def setup(self): - result = True - - if(self.CLIENT_ID == '' and self.CLIENT_SECRET == ''): - #we can't go any farther, need these for sure - xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30098) + ' ' + utils.getString(30058),utils.getString(30108)) - result = False - - return result - - def isAuthorized(self): - return xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + "google_drive.dat")) - - def authorize(self): - result = True - - if(not self.setup()): - return False - - #create authorization helper and load default settings - gauth = GoogleAuth(xbmc.validatePath(xbmc.translatePath(utils.addon_dir() + '/resources/lib/pydrive/settings.yaml'))) - gauth.LoadClientConfigSettings() - - settings = {"client_id":self.CLIENT_ID,'client_secret':self.CLIENT_SECRET} - - drive_url = gauth.GetAuthUrl(settings) - - utils.log("Google Drive Authorize URL: " + drive_url) - - xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30056),utils.getString(30102),tinyurl.shorten(drive_url)) - code = xbmcgui.Dialog().input(utils.getString(30098) + ' ' + utils.getString(30103)) - - gauth.Auth(code) - gauth.SaveCredentialsFile(xbmc.validatePath(xbmc.translatePath(utils.data_dir() + 'google_drive.dat'))) - - return result - - def getClient(self): - #create authorization helper and load default settings - gauth = GoogleAuth(xbmc.validatePath(xbmc.translatePath(utils.addon_dir() + '/resources/lib/pydrive/settings.yaml'))) - gauth.LoadClientConfigSettings() - - gauth.LoadCredentialsFile(xbmc.validatePath(xbmc.translatePath(utils.data_dir() + 'google_drive.dat'))) - - result = GoogleDrive(gauth) - - return result - - - diff --git a/resources/lib/backup.py b/resources/lib/backup.py index e51b81e..393ce8c 100644 --- a/resources/lib/backup.py +++ b/resources/lib/backup.py @@ -4,7 +4,7 @@ import json from kodi_six import xbmc, xbmcgui, xbmcvfs from . import utils as utils from datetime import datetime -from . vfs import XBMCFileSystem,DropboxFileSystem,ZipFileSystem,GoogleDriveFilesystem +from . vfs import XBMCFileSystem,DropboxFileSystem,ZipFileSystem from . progressbar import BackupProgressBar from resources.lib.guisettings import GuiSettingsManager from resources.lib.extractor import ZipExtractor @@ -59,9 +59,6 @@ class XbmcBackup: elif(utils.getSetting('remote_selection') == '2'): self.remote_base_path = "/" self.remote_vfs = DropboxFileSystem("/") - elif(utils.getSetting('remote_selection') == '3'): - self.remote_base_path = '/Kodi Backup/' - self.remote_vfs = GoogleDriveFilesystem('/Kodi Backup/') def remoteConfigured(self): result = True @@ -397,7 +394,7 @@ class XbmcBackup: else: self._updateProgress() wroteFile = True - if(isinstance(source,DropboxFileSystem) or isinstance(source,GoogleDriveFilesystem)): + if(isinstance(source,DropboxFileSystem)): #if copying from cloud storage we need the file handle, use get_file wroteFile = source.get_file(aFile,dest.root_path + aFile[len(source.root_path):]) else: diff --git a/resources/lib/vfs.py b/resources/lib/vfs.py index 23dda35..d137973 100644 --- a/resources/lib/vfs.py +++ b/resources/lib/vfs.py @@ -6,7 +6,7 @@ from kodi_six import xbmc, xbmcvfs, xbmcgui from . import dropbox from . import utils as utils from . dropbox.files import WriteMode,CommitInfo,UploadSessionCursor -from . authorizers import DropboxAuthorizer,GoogleDriveAuthorizer +from . authorizers import DropboxAuthorizer class Vfs: root_path = None @@ -261,191 +261,3 @@ class DropboxFileSystem(Vfs): result = result[:-1] return result - - -class GoogleDriveFilesystem(Vfs): - drive = None - history = {} - FOLDER_TYPE = 'application/vnd.google-apps.folder' - - def __init__(self,rootString): - self.set_root(rootString) - - authorizer = GoogleDriveAuthorizer() - - if(authorizer.isAuthorized()): - self.drive = authorizer.getClient() - else: - #tell the user to go back and run the authorizer - xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30105)) - sys.exit() - - #make sure we have the folder we need - xbmc_folder = self._getGoogleFile(self.root_path) - if(xbmc_folder == None): - self.mkdir(self.root_path) - - def listdir(self,directory): - files = [] - dirs = [] - - if(not directory.startswith('/')): - directory = '/' + directory - - #get the id of this folder - parentFolder = self._getGoogleFile(directory) - - #need to do this after - if(not directory.endswith('/')): - directory = directory + '/' - - if(parentFolder != None): - - fileList = self.drive.ListFile({'q':"'" + parentFolder['id'] + "' in parents and trashed = false"}).GetList() - - for aFile in fileList: - if(aFile['mimeType'] == self.FOLDER_TYPE): - dirs.append(aFile['title']) - else: - files.append(aFile['title']) - - - return [dirs,files] - - def mkdir(self,directory): - result = True - - if(not directory.startswith('/')): - directory = '/' + directory - - if(directory.endswith('/')): - directory = directory[:-1] - - #split the string by the directory separator - pathList = os.path.split(directory) - - if(pathList[0] == '/'): - - #we're at the root, just make the folder - newFolder = self.drive.CreateFile({'title': pathList[1], 'parent':'root','mimeType':self.FOLDER_TYPE}) - newFolder.Upload() - else: - #get the id of the parent folder - parentFolder = self._getGoogleFile(pathList[0]) - - if(parentFolder != None): - newFolder = self.drive.CreateFile({'title': pathList[1],"parents":[{'kind':'drive#fileLink','id':parentFolder['id']}],'mimeType':self.FOLDER_TYPE}) - newFolder.Upload() - else: - result = False - - return result - - def put(self,source,dest): - result = True - - #make the name separate from the path - if(not dest.startswith('/')): - dest = '/' + dest - - pathList = os.path.split(dest) - - #get the parent location - parentFolder = self._getGoogleFile(pathList[0]) - - if(parentFolder != None): - #create a new file in this folder - newFile = self.drive.CreateFile({"title":pathList[1],"parents":[{'kind':'drive#fileLink','id':parentFolder['id']}]}) - newFile.SetContentFile(source) - newFile.Upload() - else: - result = False - - return result - - def get_file(self,source, dest): - result = True - - #get the id of this file - file = self._getGoogleFile(source) - - if(file != None): - file.GetContentFile(dest) - else: - result = False - - return result - - def rmdir(self,directory): - result = True - - #check that the folder exists - folder = self._getGoogleFile(directory) - - if(folder != None): - #delete the folder - folder.Delete() - else: - result = False - - return result - - def rmfile(self,aFile): - #really just the same as the remove directory function - return self.rmdir(aFile) - - def exists(self,aFile): - #attempt to get this file - foundFile = self._getGoogleFile(aFile) - - if(foundFile != None): - return True - else: - return False - - def rename(self,aFile,newName): - return True - - def _getGoogleFile(self,file): - result = None - - #file must start with / and not end with one (even directory) - if(not file.startswith('/')): - file = '/' + file - - if(file.endswith('/')): - file = file[:-1] - - if(self.history.has_key(file)): - - result = self.history[file] - else: - pathList = os.path.split(file) - - #end of recurision, we got the root - if(pathList[0] == '/'): - #get the id of this file (if it exists) - file_list = self.drive.ListFile({'q':"title='" + pathList[1] + "' and 'root' in parents and trashed=false"}).GetList() - - if(len(file_list) > 0): - result = file_list[0] - self.history[pathList[1]] = result - else: - #recurse down the tree - current_file = pathList[1] - - parentId = self._getGoogleFile(pathList[0]) - - if(parentId != None): - self.history[pathList[0]] = parentId - - #attempt to get the id of this file, with this parent - file_list = file_list = self.drive.ListFile({'q':"title='" + current_file + "' and '" + parentId['id'] + "' in parents and trashed=false"}).GetList() - - if(len(file_list) > 0): - result = file_list[0] - self.history[file] = result - - - return result - diff --git a/resources/settings.xml b/resources/settings.xml index d45c3a2..12189a7 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -7,7 +7,7 @@ - +