mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-14 20:35:48 +01:00
added an advanced backup editor and combined settings.xml scripts into a launcher
This commit is contained in:
parent
489dcd317f
commit
24f570e888
@ -1,37 +0,0 @@
|
||||
import sys
|
||||
import urlparse
|
||||
import xbmcgui
|
||||
import resources.lib.utils as utils
|
||||
from resources.lib.authorizers import DropboxAuthorizer,GoogleDriveAuthorizer
|
||||
|
||||
def get_params():
|
||||
param = {}
|
||||
try:
|
||||
for i in sys.argv:
|
||||
args = i
|
||||
if(args.startswith('?')):
|
||||
args = args[1:]
|
||||
param.update(dict(urlparse.parse_qsl(args)))
|
||||
except:
|
||||
pass
|
||||
return param
|
||||
|
||||
params = get_params()
|
||||
|
||||
#drobpox
|
||||
if(params['type'] == 'dropbox'):
|
||||
authorizer = DropboxAuthorizer()
|
||||
|
||||
if(authorizer.authorize()):
|
||||
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30027) + ' ' + utils.getString(30106))
|
||||
else:
|
||||
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30107) + ' ' + utils.getString(30027))
|
||||
|
||||
#google drive
|
||||
elif(params['type'] == '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))
|
61
launcher.py
Normal file
61
launcher.py
Normal file
@ -0,0 +1,61 @@
|
||||
import sys
|
||||
import urlparse
|
||||
import xbmc
|
||||
import xbmcgui
|
||||
import xbmcvfs
|
||||
import resources.lib.utils as utils
|
||||
from resources.lib.authorizers import DropboxAuthorizer,GoogleDriveAuthorizer
|
||||
from resources.lib.advanced_editor import AdvancedBackupEditor
|
||||
|
||||
|
||||
#launcher for various helpful functions found in the settings.xml area
|
||||
|
||||
def authorize_cloud(cloudProvider):
|
||||
#drobpox
|
||||
if(cloudProvider == 'dropbox'):
|
||||
authorizer = DropboxAuthorizer()
|
||||
|
||||
if(authorizer.authorize()):
|
||||
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30027) + ' ' + utils.getString(30106))
|
||||
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)
|
||||
|
||||
if(shouldDelete):
|
||||
#delete any of the known token file types
|
||||
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "tokens.txt")) #dropbox
|
||||
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "google_drive.dat")) #google drive
|
||||
|
||||
def get_params():
|
||||
param = {}
|
||||
try:
|
||||
for i in sys.argv:
|
||||
args = i
|
||||
if(args.startswith('?')):
|
||||
args = args[1:]
|
||||
param.update(dict(urlparse.parse_qsl(args)))
|
||||
except:
|
||||
pass
|
||||
return param
|
||||
|
||||
params = get_params()
|
||||
|
||||
if(params['action'] == 'authorize_cloud'):
|
||||
authorize_cloud(params['provider'])
|
||||
elif(params['action'] == 'remove_auth'):
|
||||
remove_auth()
|
||||
elif(params['action'] == 'advanced_editor'):
|
||||
editor = AdvancedBackupEditor()
|
||||
editor.showMainScreen()
|
@ -1,13 +0,0 @@
|
||||
import xbmc
|
||||
import xbmcgui
|
||||
import xbmcvfs
|
||||
import resources.lib.utils as utils
|
||||
|
||||
#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)
|
||||
|
||||
if(shouldDelete):
|
||||
#delete any of the known token file types
|
||||
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "tokens.txt")) #dropbox
|
||||
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "google_drive.dat")) #google drive
|
||||
|
172
resources/lib/advanced_editor.py
Normal file
172
resources/lib/advanced_editor.py
Normal file
@ -0,0 +1,172 @@
|
||||
import json
|
||||
import utils as utils
|
||||
import xbmcvfs
|
||||
import xbmc
|
||||
import xbmcgui
|
||||
|
||||
class BackupSetManager:
|
||||
jsonFile = xbmc.translatePath(utils.data_dir() + "custom_paths.json")
|
||||
paths = None
|
||||
|
||||
def __init__(self):
|
||||
self.paths = {}
|
||||
|
||||
#try and read in the custom file
|
||||
self._readFile()
|
||||
|
||||
def addSet(self,aSet):
|
||||
self.paths[aSet['name']] = {'root':aSet['root'],'dirs':[{"type":"include","path":aSet['root'],'recurse':True}]}
|
||||
|
||||
#save the file
|
||||
self._writeFile()
|
||||
|
||||
def updateSet(self,name,aSet):
|
||||
self.paths[name] = aSet
|
||||
|
||||
#save the file
|
||||
self._writeFile()
|
||||
|
||||
def deleteSet(self,index):
|
||||
#match the index to a key
|
||||
keys = self.getSets()
|
||||
|
||||
#delete this set
|
||||
del self.paths[keys[index]]
|
||||
|
||||
#save the file
|
||||
self._writeFile()
|
||||
|
||||
def getSets(self):
|
||||
#list all current sets by name
|
||||
keys = self.paths.keys()
|
||||
keys.sort()
|
||||
|
||||
return keys
|
||||
|
||||
def getSet(self,index):
|
||||
keys = self.getSets();
|
||||
|
||||
#return the set at this index
|
||||
return {'name':keys[index],'set':self.paths[keys[index]]}
|
||||
|
||||
def _writeFile(self):
|
||||
#create the custom file
|
||||
aFile = xbmcvfs.File(self.jsonFile,'w')
|
||||
aFile.write(json.dumps(self.paths))
|
||||
aFile.close()
|
||||
|
||||
def _readFile(self):
|
||||
|
||||
if(xbmcvfs.exists(self.jsonFile)):
|
||||
|
||||
#read in the custom file
|
||||
aFile = xbmcvfs.File(self.jsonFile)
|
||||
|
||||
#load custom dirs
|
||||
self.paths = json.loads(aFile.read())
|
||||
aFile.close()
|
||||
else:
|
||||
#write a blank file
|
||||
self._writeFile()
|
||||
|
||||
class AdvancedBackupEditor:
|
||||
dialog = None
|
||||
|
||||
def __init__(self):
|
||||
self.dialog = xbmcgui.Dialog()
|
||||
|
||||
def createSet(self):
|
||||
backupSet = None
|
||||
|
||||
name = self.dialog.input("Set Name",defaultt='Backup Set')
|
||||
|
||||
if(name != ''):
|
||||
|
||||
#give a choice to start in home or enter a root path
|
||||
enterHome = self.dialog.yesno('Root folder selection',line1='Browse Folder - starts in Kodi home',line2='Enter Own - enter path to start there',nolabel='Browse Folder',yeslabel='Enter Own')
|
||||
|
||||
rootFolder = 'special://home'
|
||||
if(enterHome):
|
||||
rootFolder = self.dialog.input('Enter root path',defaultt=rootFolder)
|
||||
|
||||
#check that this path even exists
|
||||
if(not xbmcvfs.exists(xbmc.translatePath(rootFolder))):
|
||||
self.dialog.ok('Path Error','Path does not exist',rootFolder)
|
||||
else:
|
||||
#select path to start set
|
||||
rootFolder = self.dialog.browse(type=0,heading="Select Root",shares='files',defaultt=rootFolder)
|
||||
|
||||
backupSet = {'name':name,'root':rootFolder}
|
||||
|
||||
return backupSet
|
||||
|
||||
def editSet(self,name,backupSet):
|
||||
optionSelected = ''
|
||||
|
||||
while(optionSelected != -1):
|
||||
options = ['Add Exclusion','Root: ' + backupSet['root']]
|
||||
|
||||
for aDir in backupSet['dirs']:
|
||||
if(aDir['type'] == 'exclude'):
|
||||
options.append('Exclude: ' + aDir['path'])
|
||||
|
||||
optionSelected = self.dialog.select('Edit ' + name,options)
|
||||
|
||||
if(optionSelected == 0):
|
||||
#add an exclusion
|
||||
excludeFolder = self.dialog.browse(type=0,heading="Add Exclusion",shares='files',defaultt=backupSet['root'])
|
||||
|
||||
#will equal root if cancel is hit
|
||||
if(excludeFolder != backupSet['root']):
|
||||
backupSet['dirs'].append({"path":excludeFolder,"type":"exclude"})
|
||||
elif(optionSelected == 1):
|
||||
self.dialog.ok('Root Folder','The root folder cannot be changed',backupSet['root'])
|
||||
elif(optionSelected > 1):
|
||||
#remove exclusion folder
|
||||
del backupSet['dirs'][optionSelected - 2]
|
||||
|
||||
return backupSet
|
||||
|
||||
|
||||
def showMainScreen(self):
|
||||
exitCondition = ""
|
||||
customPaths = BackupSetManager()
|
||||
|
||||
#show this every time
|
||||
self.dialog.ok('Disclaimer','Canceling this menu will close and save changes')
|
||||
|
||||
while(exitCondition != -1):
|
||||
#load the custom paths
|
||||
options = ['Add Set']
|
||||
|
||||
for aPath in customPaths.getSets():
|
||||
options.append(aPath)
|
||||
|
||||
#show the gui
|
||||
exitCondition = self.dialog.select('Advanced Editor',options)
|
||||
|
||||
if(exitCondition >= 0):
|
||||
if(exitCondition == 0):
|
||||
newSet = self.createSet()
|
||||
|
||||
customPaths.addSet(newSet)
|
||||
else:
|
||||
#bring up a context menu
|
||||
menuOption = self.dialog.select(heading="Choose Action",list=['Edit','Delete'],preselect=0)
|
||||
|
||||
if(menuOption == 0):
|
||||
#get the set
|
||||
aSet = customPaths.getSet(exitCondition -1)
|
||||
|
||||
#edit the set
|
||||
updatedSet = self.editSet(aSet['name'],aSet['set'])
|
||||
|
||||
#save it
|
||||
customPaths.updateSet(aSet['name'],updatedSet)
|
||||
|
||||
elif(menuOption == 1):
|
||||
if(self.dialog.yesno(heading="Delete Set",line1="Are you sure you want to delete?")):
|
||||
#delete this path - subtract one because of "add" item
|
||||
customPaths.deleteSet(exitCondition -1)
|
||||
|
||||
|
@ -8,6 +8,7 @@ from vfs import XBMCFileSystem,DropboxFileSystem,ZipFileSystem,GoogleDriveFilesy
|
||||
from progressbar import BackupProgressBar
|
||||
from resources.lib.guisettings import GuiSettingsManager
|
||||
from resources.lib.extractor import ZipExtractor
|
||||
from resources.lib.advanced_editor import BackupSetManager
|
||||
|
||||
def folderSort(aKey):
|
||||
result = aKey[0]
|
||||
@ -171,12 +172,24 @@ class XbmcBackup:
|
||||
allFiles = []
|
||||
fileManager = FileManager(self.xbmc_vfs)
|
||||
|
||||
#get file listings for all enabled directories
|
||||
if(utils.getSetting('backup_selection_type') == 0):
|
||||
#simple mode - get file listings for all enabled directories
|
||||
for aDir in self.simple_directory_list:
|
||||
#if this dir enabled
|
||||
if(utils.getSetting('backup_' + aDir) == 'true'):
|
||||
#get a file listing and append it to the allfiles array
|
||||
allFiles.append(self._addBackupDir(aDir,xbmc.translatePath(selectedDirs[aDir]['root']),selectedDirs[aDir]['dirs']))
|
||||
else:
|
||||
#advanced mode - open custom editor
|
||||
setManager = BackupSetManager()
|
||||
|
||||
#go through the custom sets
|
||||
for index in range(0,len(setManager.getSets())):
|
||||
#get the set
|
||||
aSet = setManager.getSet(index)
|
||||
utils.log(str(aSet))
|
||||
#get file listing and append
|
||||
allFiles.append(self._addBackupDir(aSet['name'],xbmc.translatePath(aSet['set']['root']),aSet['set']['dirs']))
|
||||
|
||||
#create a validation file for backup rotation
|
||||
writeCheck = self._createValidationFile(allFiles)
|
||||
|
@ -13,9 +13,9 @@
|
||||
<setting id="dropbox_secret" type="text" label="30029" visible="eq(-4,2)" default="" />
|
||||
<setting id="google_drive_id" type="text" label="Client ID" visible="eq(-5,3)" default="" />
|
||||
<setting id="google_drive_secret" type="text" label="Client Secret" visible="eq(-6,3)" default="" />
|
||||
<setting id="remove_auth_button" type="action" label="30104" action="RunScript(special://home/addons/script.xbmcbackup/authorize_cloud.py,type=dropbox)" visible="eq(-7,2)"/>
|
||||
<setting id="remove_auth_button" type="action" label="30104" action="RunScript(special://home/addons/script.xbmcbackup/authorize_cloud.py,type=google_drive)" visible="eq(-8,3)"/>
|
||||
<setting id="remove_auth_button" type="action" label="30093" action="RunScript(special://home/addons/script.xbmcbackup/remove_auth.py)" visible="gt(-9,1)"/>
|
||||
<setting id="remove_auth_button" type="action" label="30104" action="RunScript(special://home/addons/script.xbmcbackup/launcher.py,action=authorize_cloud&provider=dropbox)" visible="eq(-7,2)"/>
|
||||
<setting id="remove_auth_button" type="action" label="30104" action="RunScript(special://home/addons/script.xbmcbackup/launcher.py,action=authorize_cloud&provider=google_drive)" visible="eq(-8,3)"/>
|
||||
<setting id="remove_auth_button" type="action" label="30093" action="RunScript(special://home/addons/script.xbmcbackup/launcher.py,action=remove_auth)" visible="gt(-9,1)"/>
|
||||
</category>
|
||||
<category id="selection" label="30012">
|
||||
<setting id="backup_selection_type" type="enum" lvalues="Simple|Advanced" default="0" label="File Selection Type" />
|
||||
@ -26,6 +26,7 @@
|
||||
<setting id="backup_profiles" type="bool" label="30080" default="false" visible="eq(-5,0)"/>
|
||||
<setting id="backup_thumbnails" type="bool" label="30034" default="true" visible="eq(-6,0)"/>
|
||||
<setting id="backup_config" type="bool" label="30035" default="true" visible="eq(-7,0)"/>
|
||||
<setting id="advanced_button" type="action" label="Select Files" visible="eq(-8,1)" action="RunScript(special://home/addons/script.xbmcbackup/launcher.py,action=advanced_editor)" />
|
||||
</category>
|
||||
<category id="scheduling" label="30013">
|
||||
<setting id="enable_scheduler" type="bool" label="30060" default="false" />
|
||||
|
Loading…
Reference in New Issue
Block a user