2017-12-05 21:20:32 +01:00
|
|
|
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
|
|
|
|
|
2017-12-05 22:04:20 +01:00
|
|
|
name = self.dialog.input(utils.getString(30110),defaultt='Backup Set')
|
2017-12-05 21:20:32 +01:00
|
|
|
|
2017-12-05 22:04:20 +01:00
|
|
|
if(name != None):
|
2017-12-05 21:20:32 +01:00
|
|
|
|
|
|
|
#give a choice to start in home or enter a root path
|
2017-12-05 22:04:20 +01:00
|
|
|
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))
|
2017-12-05 21:20:32 +01:00
|
|
|
|
|
|
|
rootFolder = 'special://home'
|
|
|
|
if(enterHome):
|
2017-12-05 22:04:20 +01:00
|
|
|
rootFolder = self.dialog.input(utils.getString(30116),defaultt=rootFolder)
|
2017-12-05 21:20:32 +01:00
|
|
|
|
|
|
|
#check that this path even exists
|
|
|
|
if(not xbmcvfs.exists(xbmc.translatePath(rootFolder))):
|
2017-12-05 22:04:20 +01:00
|
|
|
self.dialog.ok(utils.getString(30117),utils.getString(30118),rootFolder)
|
2017-12-05 21:20:32 +01:00
|
|
|
else:
|
|
|
|
#select path to start set
|
2017-12-05 22:04:20 +01:00
|
|
|
rootFolder = self.dialog.browse(type=0,heading=utils.getString(30119),shares='files',defaultt=rootFolder)
|
2017-12-05 21:20:32 +01:00
|
|
|
|
|
|
|
backupSet = {'name':name,'root':rootFolder}
|
|
|
|
|
|
|
|
return backupSet
|
|
|
|
|
|
|
|
def editSet(self,name,backupSet):
|
|
|
|
optionSelected = ''
|
|
|
|
|
|
|
|
while(optionSelected != -1):
|
2017-12-05 22:04:20 +01:00
|
|
|
options = [utils.getString(30120),utils.getString(30121) + ": " + backupSet['root']]
|
2017-12-05 21:20:32 +01:00
|
|
|
|
|
|
|
for aDir in backupSet['dirs']:
|
|
|
|
if(aDir['type'] == 'exclude'):
|
2017-12-05 22:04:20 +01:00
|
|
|
options.append(utils.getString(30129) + ': ' + aDir['path'])
|
2017-12-05 21:20:32 +01:00
|
|
|
|
2017-12-05 22:04:20 +01:00
|
|
|
optionSelected = self.dialog.select(utils.getString(30122) + ' ' + name,options)
|
2017-12-05 21:20:32 +01:00
|
|
|
|
|
|
|
if(optionSelected == 0):
|
|
|
|
#add an exclusion
|
2017-12-05 22:04:20 +01:00
|
|
|
excludeFolder = self.dialog.browse(type=0,heading=utils.getString(30120),shares='files',defaultt=backupSet['root'])
|
2017-12-05 21:20:32 +01:00
|
|
|
|
|
|
|
#will equal root if cancel is hit
|
|
|
|
if(excludeFolder != backupSet['root']):
|
|
|
|
backupSet['dirs'].append({"path":excludeFolder,"type":"exclude"})
|
|
|
|
elif(optionSelected == 1):
|
2017-12-05 22:04:20 +01:00
|
|
|
self.dialog.ok(utils.getString(30121),utils.getString(30130),backupSet['root'])
|
2017-12-05 21:20:32 +01:00
|
|
|
elif(optionSelected > 1):
|
|
|
|
#remove exclusion folder
|
|
|
|
del backupSet['dirs'][optionSelected - 2]
|
|
|
|
|
|
|
|
return backupSet
|
|
|
|
|
|
|
|
|
|
|
|
def showMainScreen(self):
|
|
|
|
exitCondition = ""
|
|
|
|
customPaths = BackupSetManager()
|
|
|
|
|
|
|
|
#show this every time
|
2017-12-05 22:04:20 +01:00
|
|
|
self.dialog.ok(utils.getString(30036),utils.getString(30037))
|
2017-12-05 21:20:32 +01:00
|
|
|
|
|
|
|
while(exitCondition != -1):
|
|
|
|
#load the custom paths
|
2017-12-05 22:04:20 +01:00
|
|
|
options = [utils.getString(30126)]
|
2017-12-05 21:20:32 +01:00
|
|
|
|
|
|
|
for aPath in customPaths.getSets():
|
|
|
|
options.append(aPath)
|
|
|
|
|
|
|
|
#show the gui
|
2017-12-05 22:04:20 +01:00
|
|
|
exitCondition = self.dialog.select(utils.getString(30125),options)
|
2017-12-05 21:20:32 +01:00
|
|
|
|
|
|
|
if(exitCondition >= 0):
|
|
|
|
if(exitCondition == 0):
|
|
|
|
newSet = self.createSet()
|
|
|
|
|
|
|
|
customPaths.addSet(newSet)
|
|
|
|
else:
|
|
|
|
#bring up a context menu
|
2017-12-05 22:04:20 +01:00
|
|
|
menuOption = self.dialog.select(heading=utils.getString(30124),list=[utils.getString(30122),utils.getString(30123)],preselect=0)
|
2017-12-05 21:20:32 +01:00
|
|
|
|
|
|
|
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):
|
2017-12-05 22:04:20 +01:00
|
|
|
if(self.dialog.yesno(heading=utils.getString(30127),line1=utils.getString(30128))):
|
2017-12-05 21:20:32 +01:00
|
|
|
#delete this path - subtract one because of "add" item
|
|
|
|
customPaths.deleteSet(exitCondition -1)
|
|
|
|
|
|
|
|
|