2019-11-25 22:48:42 +01:00
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
2019-08-26 22:40:15 +02:00
|
|
|
import resources.lib.utils as utils
|
|
|
|
from resources.lib.backup import XbmcBackup
|
|
|
|
|
2019-11-25 22:56:59 +01:00
|
|
|
|
2019-08-26 22:40:15 +02:00
|
|
|
def get_params():
|
|
|
|
param = {}
|
2019-08-27 22:04:30 +02:00
|
|
|
try:
|
2019-08-26 22:40:15 +02:00
|
|
|
for i in sys.argv:
|
|
|
|
args = i
|
2019-08-27 22:04:30 +02:00
|
|
|
if('=' in args):
|
|
|
|
if(args.startswith('?')):
|
2019-11-26 17:43:38 +01:00
|
|
|
args = args[1:] # legacy in case of url params
|
2019-08-27 22:04:30 +02:00
|
|
|
splitString = args.split('=')
|
|
|
|
param[splitString[0]] = splitString[1]
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2019-08-26 22:40:15 +02:00
|
|
|
return param
|
|
|
|
|
2019-11-25 22:56:59 +01:00
|
|
|
|
2019-11-25 22:19:57 +01:00
|
|
|
# the program mode
|
2019-08-26 22:40:15 +02:00
|
|
|
mode = -1
|
|
|
|
params = get_params()
|
|
|
|
|
|
|
|
|
|
|
|
if("mode" in params):
|
|
|
|
if(params['mode'] == 'backup'):
|
|
|
|
mode = 0
|
|
|
|
elif(params['mode'] == 'restore'):
|
|
|
|
mode = 1
|
|
|
|
|
2019-11-25 22:56:59 +01:00
|
|
|
|
2019-11-25 22:19:57 +01:00
|
|
|
# if mode wasn't passed in as arg, get from user
|
2019-08-26 22:40:15 +02:00
|
|
|
if(mode == -1):
|
2019-11-25 22:19:57 +01:00
|
|
|
# by default, Backup,Restore,Open Settings
|
2019-11-25 22:45:41 +01:00
|
|
|
options = [utils.getString(30016), utils.getString(30017), utils.getString(30099)]
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2019-11-25 22:19:57 +01:00
|
|
|
# find out if we're using the advanced editor
|
2019-11-27 21:19:41 +01:00
|
|
|
if(utils.getSettingInt('backup_selection_type') == 1):
|
2019-08-26 22:40:15 +02:00
|
|
|
options.append(utils.getString(30125))
|
|
|
|
|
2019-11-25 22:19:57 +01:00
|
|
|
# figure out if this is a backup or a restore from the user
|
2019-11-25 22:45:41 +01:00
|
|
|
mode = xbmcgui.Dialog().select(utils.getString(30010) + " - " + utils.getString(30023), options)
|
2019-08-26 22:40:15 +02:00
|
|
|
|
2019-11-25 22:19:57 +01:00
|
|
|
# check if program should be run
|
2019-08-26 22:40:15 +02:00
|
|
|
if(mode != -1):
|
2019-11-25 22:19:57 +01:00
|
|
|
# run the profile backup
|
2019-08-26 22:40:15 +02:00
|
|
|
backup = XbmcBackup()
|
|
|
|
|
|
|
|
if(mode == 2):
|
2019-11-25 22:19:57 +01:00
|
|
|
# open the settings dialog
|
2019-08-26 22:40:15 +02:00
|
|
|
utils.openSettings()
|
2019-11-27 21:19:41 +01:00
|
|
|
elif(mode == 3 and utils.getSettingInt('backup_selection_type') == 1):
|
2019-11-25 22:19:57 +01:00
|
|
|
# open the advanced editor
|
2019-11-25 22:45:41 +01:00
|
|
|
xbmc.executebuiltin('RunScript(special://home/addons/script.xbmcbackup/launcher.py, action=advanced_editor)')
|
2019-08-26 22:40:15 +02:00
|
|
|
elif(backup.remoteConfigured()):
|
|
|
|
|
|
|
|
if(mode == backup.Restore):
|
2019-11-25 22:19:57 +01:00
|
|
|
# get list of valid restore points
|
2019-08-26 22:40:15 +02:00
|
|
|
restorePoints = backup.listBackups()
|
|
|
|
pointNames = []
|
|
|
|
folderNames = []
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2019-08-26 22:40:15 +02:00
|
|
|
for aDir in restorePoints:
|
|
|
|
pointNames.append(aDir[1])
|
|
|
|
folderNames.append(aDir[0])
|
|
|
|
|
|
|
|
selectedRestore = -1
|
|
|
|
|
|
|
|
if("archive" in params):
|
2019-11-25 22:19:57 +01:00
|
|
|
# check that the user give archive exists
|
2019-08-26 22:40:15 +02:00
|
|
|
if(params['archive'] in folderNames):
|
2019-11-25 22:19:57 +01:00
|
|
|
# set the index
|
2019-08-26 22:40:15 +02:00
|
|
|
selectedRestore = folderNames.index(params['archive'])
|
|
|
|
utils.log(str(selectedRestore) + " : " + params['archive'])
|
|
|
|
else:
|
|
|
|
utils.showNotification(utils.getString(30045))
|
|
|
|
utils.log(params['archive'] + ' is not a valid restore point')
|
|
|
|
else:
|
2019-11-25 22:19:57 +01:00
|
|
|
# allow user to select the backup to restore from
|
2019-11-25 22:45:41 +01:00
|
|
|
selectedRestore = xbmcgui.Dialog().select(utils.getString(30010) + " - " + utils.getString(30021), pointNames)
|
2019-08-26 22:40:15 +02:00
|
|
|
|
|
|
|
if(selectedRestore != -1):
|
|
|
|
backup.selectRestore(restorePoints[selectedRestore][0])
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2019-08-26 22:40:15 +02:00
|
|
|
if('sets' in params):
|
|
|
|
backup.restore(selectedSets=params['sets'].split('|'))
|
|
|
|
else:
|
|
|
|
backup.restore()
|
|
|
|
else:
|
|
|
|
backup.backup()
|
|
|
|
else:
|
2019-11-25 22:19:57 +01:00
|
|
|
# can't go any further
|
2019-11-25 22:45:41 +01:00
|
|
|
xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30045))
|
2019-08-26 22:40:15 +02:00
|
|
|
utils.openSettings()
|