mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-14 20:35:48 +01:00
removed Google Drive support - too many python2/3 dependency issues
This commit is contained in:
parent
b9e0424ea5
commit
aa94060cfe
@ -2,12 +2,10 @@
|
||||
<addon id="script.xbmcbackup"
|
||||
name="Backup" version="1.5.1~beta1" provider-name="robweber">
|
||||
<requires>
|
||||
<!-- jarvis -->
|
||||
<import addon="xbmc.python" version="2.26.0"/>
|
||||
<import addon="script.module.kodi-six" version="0.1.0"/>
|
||||
<import addon="script.module.future" version="0.16.0.4"/>
|
||||
<import addon="script.module.six" version="1.11.0"/>
|
||||
<import addon="script.module.pydrive" version="1.3.1"/>
|
||||
<import addon="script.module.requests" version="2.9.1" />
|
||||
</requires>
|
||||
<extension point="xbmc.python.script" library="default.py">
|
||||
|
11
launcher.py
11
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)
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<setting id="upgrade_notes" type="number" label="upgrade_notes" visible="false" default="1" />
|
||||
</category>
|
||||
<category id="backup_path" label="30048">
|
||||
<setting id="remote_selection" type="enum" lvalues="30018|30019|30027|30098" default="0" label="30025"/>
|
||||
<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_key" type="text" label="30028" visible="eq(-3,2)" default="" />
|
||||
|
Loading…
Reference in New Issue
Block a user