mirror of
https://github.com/robweber/xbmcbackup.git
synced 2025-06-23 19:14:33 +02:00
Update for Leia (#117)
* updated addon.xml for Krypton * default log level is always debug now * added screenshots per krypton format * started new way of defining backup directories * reconfigured simple backup process * added an advanced backup editor and combined settings.xml scripts into a launcher * added strings for advanced editor * there was a function to do this * match excluded with regex * updated def for the addons set * directory has to end in slash to use exists() * added a backup set chooser on restore * added string for restore browser * utilize details to show root folder and icons * save non translated paths, better cross platform support * revert dropbox python 2.6 changes * start of #132 * can't have duplicate ids * updated strings * closes #132 * added a disclaimer for breaking changes * split backup and restore into separate functions * updated scripting to pass in list of sets to restore * beta version * added 2 min delay in startup - part of #147 * forgot to remove debug message * change to wait for abort in case someone tries to close Kodi * add retroplayer game saves to default file list * display restore points with most recent on top * remove length check, breaking change with this version means old archives are no longer compatible * format restore list according to regional settings * this function isn't used anymore, legacy of old file manager * use images folder as default * added note about compatibility * added utils function for regional date, use for scheduler notifications as well * add/remove include and exclude directories to a set * paths should have / at the end * show path relative to root * if in advanced mode allow jumping to editor from launch screen * check that path is within root folder of set * cannot have duplicate set names or rules regarding folders within a set * put strings in correct lang file * beta version bump * accidentally deleted string id * change exclude criteria. Regex was not matching in complex cases * make sure the dest folder (backup set root) exists before writing to it * modify select display to show recursive value for included folders * use a context menu here * added ability to toggle recursion of sub folders * beta 3 * added support doc * wrong branch * don't need this import anymore * don't need these imports * part of #133
This commit is contained in:
229
resources/lib/advanced_editor.py
Normal file
229
resources/lib/advanced_editor.py
Normal file
@ -0,0 +1,229 @@
|
||||
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 validateSetName(self,name):
|
||||
return (name not in self.getSets())
|
||||
|
||||
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 _cleanPath(self,root,path):
|
||||
return path[len(root)-1:]
|
||||
|
||||
def _validatePath(self,root,path):
|
||||
return path.startswith(root)
|
||||
|
||||
def createSet(self):
|
||||
backupSet = None
|
||||
|
||||
name = self.dialog.input(utils.getString(30110),defaultt='Backup Set')
|
||||
|
||||
if(name != None):
|
||||
|
||||
#give a choice to start in home or enter a root path
|
||||
enterHome = self.dialog.yesno(utils.getString(30111),line1=utils.getString(30112) + " - " + utils.getString(30114),line2=utils.getString(30113) + " - " + utils.getString(30115),nolabel=utils.getString(30112),yeslabel=utils.getString(30113))
|
||||
|
||||
rootFolder = 'special://home'
|
||||
if(enterHome):
|
||||
rootFolder = self.dialog.input(utils.getString(30116),defaultt=rootFolder)
|
||||
|
||||
#direcotry has to end in slash
|
||||
if(rootFolder[:-1] != '/'):
|
||||
rootFolder = rootFolder + '/'
|
||||
|
||||
#check that this path even exists
|
||||
if(not xbmcvfs.exists(xbmc.translatePath(rootFolder))):
|
||||
self.dialog.ok(utils.getString(30117),utils.getString(30118),rootFolder)
|
||||
return None
|
||||
else:
|
||||
#select path to start set
|
||||
rootFolder = self.dialog.browse(type=0,heading=utils.getString(30119),shares='files',defaultt=rootFolder)
|
||||
|
||||
backupSet = {'name':name,'root':rootFolder}
|
||||
|
||||
return backupSet
|
||||
|
||||
def editSet(self,name,backupSet):
|
||||
optionSelected = ''
|
||||
rootPath = backupSet['root']
|
||||
utils.log(rootPath)
|
||||
while(optionSelected != -1):
|
||||
options = [xbmcgui.ListItem(utils.getString(30120),"Exclude a specific folder from this backup set"),xbmcgui.ListItem(utils.getString(30135),"Include a specific folder to this backup set"),xbmcgui.ListItem(rootPath,utils.getString(30121))]
|
||||
|
||||
for aDir in backupSet['dirs']:
|
||||
if(aDir['type'] == 'exclude'):
|
||||
options.append(xbmcgui.ListItem(self._cleanPath(rootPath,aDir['path']),"%s: %s" % ("Type",utils.getString(30129))))
|
||||
elif(aDir['type'] == 'include'):
|
||||
options.append(xbmcgui.ListItem(self._cleanPath(rootPath,aDir['path']),"%s: %s | %s: %s" % ("Type",utils.getString(30134),"Include Sub Folders",str(aDir['recurse']))))
|
||||
|
||||
optionSelected = self.dialog.select(utils.getString(30122) + ' ' + name,options,useDetails=True)
|
||||
|
||||
if(optionSelected == 0 or optionSelected == 1):
|
||||
#add a folder, will equal root if cancel is hit
|
||||
addFolder = self.dialog.browse(type=0,heading=utils.getString(30120),shares='files',defaultt=backupSet['root'])
|
||||
|
||||
if(addFolder.startswith(rootPath)):
|
||||
|
||||
if(not any(addFolder == aDir['path'] for aDir in backupSet['dirs'])):
|
||||
#cannot add root as an exclusion
|
||||
if(optionSelected == 0 and addFolder != backupSet['root']):
|
||||
backupSet['dirs'].append({"path":addFolder,"type":"exclude"})
|
||||
elif(optionSelected == 1):
|
||||
#can add root as inclusion
|
||||
backupSet['dirs'].append({"path":addFolder,"type":"include","recurse":True})
|
||||
else:
|
||||
#this path is already part of another include/exclude rule
|
||||
self.dialog.ok(utils.getString(30117),utils.getString(30137),addFolder)
|
||||
else:
|
||||
#folder must be under root folder
|
||||
self.dialog.ok(utils.getString(30117), utils.getString(30136),rootPath)
|
||||
elif(optionSelected == 2):
|
||||
self.dialog.ok(utils.getString(30121),utils.getString(30130),backupSet['root'])
|
||||
elif(optionSelected > 2):
|
||||
|
||||
cOptions = ['Delete']
|
||||
if(backupSet['dirs'][optionSelected - 3]['type'] == 'include'):
|
||||
cOptions.append('Toggle Sub Folders')
|
||||
|
||||
contextOption = self.dialog.contextmenu(cOptions)
|
||||
|
||||
if(contextOption == 0):
|
||||
if(self.dialog.yesno(heading=utils.getString(30123),line1=utils.getString(30128))):
|
||||
#remove folder
|
||||
del backupSet['dirs'][optionSelected - 3]
|
||||
elif(contextOption == 1 and backupSet['dirs'][optionSelected - 3]['type'] == 'include'):
|
||||
#toggle if this folder should be recursive
|
||||
backupSet['dirs'][optionSelected - 3]['recurse'] = not backupSet['dirs'][optionSelected - 3]['recurse']
|
||||
|
||||
return backupSet
|
||||
|
||||
|
||||
def showMainScreen(self):
|
||||
exitCondition = ""
|
||||
customPaths = BackupSetManager()
|
||||
|
||||
#show this every time
|
||||
self.dialog.ok(utils.getString(30036),utils.getString(30037))
|
||||
|
||||
while(exitCondition != -1):
|
||||
#load the custom paths
|
||||
options = [xbmcgui.ListItem(utils.getString(30126),'',utils.addon_dir() + '/resources/images/plus-icon.png')]
|
||||
|
||||
for index in range(0,len(customPaths.getSets())):
|
||||
aSet = customPaths.getSet(index)
|
||||
options.append(xbmcgui.ListItem(aSet['name'],utils.getString(30121) + ': ' + aSet['set']['root'],utils.addon_dir() + '/resources/images/folder-icon.png'))
|
||||
|
||||
#show the gui
|
||||
exitCondition = self.dialog.select(utils.getString(30125),options,useDetails=True)
|
||||
|
||||
if(exitCondition >= 0):
|
||||
if(exitCondition == 0):
|
||||
newSet = self.createSet()
|
||||
|
||||
#check that the name is unique
|
||||
if(customPaths.validateSetName(newSet['name'])):
|
||||
customPaths.addSet(newSet)
|
||||
else:
|
||||
self.dialog.ok(utils.getString(30117), utils.getString(30138),newSet['name'])
|
||||
else:
|
||||
#bring up a context menu
|
||||
menuOption = self.dialog.contextmenu([utils.getString(30122),utils.getString(30123)])
|
||||
|
||||
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=utils.getString(30127),line1=utils.getString(30128))):
|
||||
#delete this path - subtract one because of "add" item
|
||||
customPaths.deleteSet(exitCondition -1)
|
||||
|
||||
def copySimpleConfig(self):
|
||||
#disclaimer in case the user hit this on accident
|
||||
shouldContinue = self.dialog.yesno(utils.getString(30139),utils.getString(30140),utils.getString(30141))
|
||||
|
||||
if(shouldContinue):
|
||||
source = xbmc.translatePath(utils.addon_dir() + "/resources/data/default_files.json")
|
||||
dest = xbmc.translatePath(utils.data_dir() + "/custom_paths.json")
|
||||
|
||||
xbmcvfs.copy(source,dest)
|
||||
|
||||
|
||||
|
@ -3,9 +3,18 @@ import xbmcgui
|
||||
import xbmcvfs
|
||||
import resources.lib.tinyurl as tinyurl
|
||||
import resources.lib.utils as utils
|
||||
import dropbox
|
||||
from resources.lib.pydrive.auth import GoogleAuth
|
||||
from resources.lib.pydrive.drive import GoogleDrive
|
||||
|
||||
#don't die on import error yet, these might not even get used
|
||||
try:
|
||||
import dropbox
|
||||
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 = ""
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -511,9 +511,5 @@ def _params_to_urlencoded(params):
|
||||
else:
|
||||
return str(o).encode('utf-8')
|
||||
|
||||
#fix for python 2.6
|
||||
utf8_params = {}
|
||||
for k,v in six.iteritems(params):
|
||||
utf8_params[encode(k)] = encode(v)
|
||||
|
||||
utf8_params = {encode(k): encode(v) for k, v in six.iteritems(params)}
|
||||
return url_encode(utf8_params)
|
||||
|
@ -237,12 +237,11 @@ class StoneToPythonPrimitiveSerializer(StoneSerializerBase):
|
||||
def encode_map(self, validator, value):
|
||||
validated_value = validator.validate(value)
|
||||
|
||||
#fix for python 2.6
|
||||
result = {}
|
||||
for key, value in validated_value.items():
|
||||
result[self.encode_sub(validator.key_validator,key)] = self.encode_sub(validator.value_validator, value)
|
||||
|
||||
return result
|
||||
return {
|
||||
self.encode_sub(validator.key_validator, key):
|
||||
self.encode_sub(validator.value_validator, value) for
|
||||
key, value in validated_value.items()
|
||||
}
|
||||
|
||||
def encode_nullable(self, validator, value):
|
||||
if value is None:
|
||||
@ -831,12 +830,11 @@ def _decode_list(
|
||||
if not isinstance(obj, list):
|
||||
raise bv.ValidationError(
|
||||
'expected list, got %s' % bv.generic_type_name(obj))
|
||||
|
||||
result = []
|
||||
for item in obj:
|
||||
result.append(_json_compat_obj_decode_helper(data_type.item_validator, item, alias_validators, strict,old_style, for_msgpack))
|
||||
|
||||
return result
|
||||
return [
|
||||
_json_compat_obj_decode_helper(
|
||||
data_type.item_validator, item, alias_validators, strict,
|
||||
old_style, for_msgpack)
|
||||
for item in obj]
|
||||
|
||||
|
||||
def _decode_map(
|
||||
@ -848,12 +846,15 @@ def _decode_map(
|
||||
if not isinstance(obj, dict):
|
||||
raise bv.ValidationError(
|
||||
'expected dict, got %s' % bv.generic_type_name(obj))
|
||||
|
||||
result = {}
|
||||
for key, value in obj.items():
|
||||
result[_json_compat_obj_decode_helper(data_type.key_validator, key, alias_validators, strict,old_style, for_msgpack)] = _json_compat_obj_decode_helper(data_type.value_validator, value, alias_validators, strict,old_style, for_msgpack)
|
||||
|
||||
return result
|
||||
return {
|
||||
_json_compat_obj_decode_helper(
|
||||
data_type.key_validator, key, alias_validators, strict,
|
||||
old_style, for_msgpack):
|
||||
_json_compat_obj_decode_helper(
|
||||
data_type.value_validator, value, alias_validators, strict,
|
||||
old_style, for_msgpack)
|
||||
for key, value in obj.items()
|
||||
}
|
||||
|
||||
|
||||
def _decode_nullable(
|
||||
|
@ -422,13 +422,10 @@ class Map(Composite):
|
||||
def validate(self, val):
|
||||
if not isinstance(val, dict):
|
||||
raise ValidationError('%r is not a valid dict' % val)
|
||||
|
||||
#fix for python 2.6
|
||||
result = {}
|
||||
for key, value in val.items():
|
||||
result[self.key_validator.validate(key)] = self.value_validator.validate(value)
|
||||
|
||||
return result
|
||||
return {
|
||||
self.key_validator.validate(key):
|
||||
self.value_validator.validate(value) for key, value in val.items()
|
||||
}
|
||||
|
||||
|
||||
class Struct(Composite):
|
||||
|
@ -14,11 +14,11 @@ def addon_dir():
|
||||
def openSettings():
|
||||
__Addon.openSettings()
|
||||
|
||||
def log(message,loglevel=xbmc.LOGNOTICE):
|
||||
def log(message,loglevel=xbmc.LOGDEBUG):
|
||||
xbmc.log(encode(__addon_id__ + "-" + __Addon.getAddonInfo('version') + ": " + message),level=loglevel)
|
||||
|
||||
def showNotification(message):
|
||||
xbmcgui.Dialog().notification(encode(getString(30010)),encode(message),time=4000,icon=xbmc.translatePath(__Addon.getAddonInfo('path') + "/resources/media/icon.png"))
|
||||
xbmcgui.Dialog().notification(encode(getString(30010)),encode(message),time=4000,icon=xbmc.translatePath(__Addon.getAddonInfo('path') + "/resources/images/icon.png"))
|
||||
|
||||
def getSetting(name):
|
||||
return __Addon.getSetting(name)
|
||||
@ -29,6 +29,14 @@ def setSetting(name,value):
|
||||
def getString(string_id):
|
||||
return __Addon.getLocalizedString(string_id)
|
||||
|
||||
def getRegionalTimestamp(date_time,dateformat=['dateshort']):
|
||||
result = ''
|
||||
|
||||
for aFormat in dateformat:
|
||||
result = result + ("%s " % date_time.strftime(xbmc.getRegion(aFormat)))
|
||||
|
||||
return result.strip()
|
||||
|
||||
def encode(string):
|
||||
result = ''
|
||||
|
||||
|
@ -1,16 +1,12 @@
|
||||
import utils as utils
|
||||
import tinyurl as tinyurl
|
||||
import xbmc
|
||||
import xbmcvfs
|
||||
import xbmcgui
|
||||
import zipfile
|
||||
import zlib
|
||||
import os
|
||||
import os.path
|
||||
import sys
|
||||
import dropbox
|
||||
from dropbox.files import WriteMode,CommitInfo,UploadSessionCursor
|
||||
from pydrive.drive import GoogleDrive
|
||||
from authorizers import DropboxAuthorizer,GoogleDriveAuthorizer
|
||||
|
||||
class Vfs:
|
||||
@ -232,7 +228,7 @@ class DropboxFileSystem(Vfs):
|
||||
self.client.files_upload_session_append_v2(f.read(self.MAX_CHUNK),upload_cursor)
|
||||
upload_cursor.offset = f.tell()
|
||||
|
||||
#if no errors we're good!
|
||||
#if no errors we're good!
|
||||
return True
|
||||
except Exception as anError:
|
||||
utils.log(str(anError))
|
||||
|
Reference in New Issue
Block a user