Skip to content

Commit

Permalink
check for advanced settings and restart xbmc to continue (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
robweber committed May 9, 2013
1 parent c9d285c commit af11c1a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 16 deletions.
58 changes: 43 additions & 15 deletions resources/lib/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class XbmcBackup:

fileManager = None
restore_point = None

skip_advanced = False #if we should check for the existance of advancedsettings in the restore

def __init__(self):
self.xbmc_vfs = XBMCFileSystem(xbmc.translatePath('special://home'))

Expand Down Expand Up @@ -58,6 +59,9 @@ def listBackups(self):
def selectRestore(self,restore_point):
self.restore_point = restore_point

def skipAdvanced(self):
self.skip_advanced = True

def run(self,mode=-1,runSilent=False):
#append backup folder name
progressBarTitle = utils.getString(30010) + " - "
Expand Down Expand Up @@ -184,6 +188,38 @@ def run(self,mode=-1,runSilent=False):
fileManager = FileManager(self.remote_vfs)

#go through each of the user selected items and write them to the backup store

if(utils.getSetting("backup_config") == "true"):
#check for the existance of an advancedsettings file
if(self.remote_vfs.exists(self.remote_vfs.root_path + "userdata/advancedsettings.xml") and not self.skip_advanced):
#let the user know there is an advanced settings file present
restartXbmc = xbmcgui.Dialog().yesno("Advanced Settings Detected","The advancedsettings file should be restored first","Select Yes to restore this file and restart XBMC", "Select No to continue")

if(restartXbmc):
#add only this file to the file list
fileManager.addFile(self.remote_vfs.root_path + "userdata/advancedsettings.xml")
self.backupFiles(fileManager.getFiles(),self.remote_vfs,self.xbmc_vfs)

#let the service know to resume this backup on startup
self._createResumeBackupFile()

#do not continue running
xbmcgui.Dialog().ok("Restart XBMC","You should restart XBMC to continue")

return

self.xbmc_vfs.mkdir(xbmc.translatePath('special://home/userdata/keymaps'))
fileManager.walkTree(self.remote_vfs.root_path + "userdata/keymaps")

self.xbmc_vfs.mkdir(xbmc.translatePath('special://home/userdata/peripheral_data'))
fileManager.walkTree(self.remote_vfs.root_path + "userdata/peripheral_data")

#this part is an oddity
dirs,configFiles = self.remote_vfs.listdir(self.remote_vfs.root_path + "userdata/")
for aFile in configFiles:
if(aFile.endswith(".xml")):
fileManager.addFile(self.remote_vfs.root_path + "userdata/" + aFile)

if(utils.getSetting('backup_addons') == 'true'):
self.xbmc_vfs.mkdir(xbmc.translatePath('special://home/addons'))
fileManager.walkTree(self.remote_vfs.root_path + "addons")
Expand All @@ -206,19 +242,6 @@ def run(self,mode=-1,runSilent=False):
self.xbmc_vfs.mkdir(xbmc.translatePath('special://home/userdata/Thumbnails'))
fileManager.walkTree(self.remote_vfs.root_path + "userdata/Thumbnails")

if(utils.getSetting("backup_config") == "true"):
self.xbmc_vfs.mkdir(xbmc.translatePath('special://home/userdata/keymaps'))
fileManager.walkTree(self.remote_vfs.root_path + "userdata/keymaps")

self.xbmc_vfs.mkdir(xbmc.translatePath('special://home/userdata/peripheral_data'))
fileManager.walkTree(self.remote_vfs.root_path + "userdata/peripheral_data")

#this part is an oddity
dirs,configFiles = self.remote_vfs.listdir(self.remote_vfs.root_path + "userdata/")
for aFile in configFiles:
if(aFile.endswith(".xml")):
fileManager.addFile(self.remote_vfs.root_path + "userdata/" + aFile)

#add to array
self.filesTotal = fileManager.size()
allFiles.append({"source":self.remote_vfs.root_path,"dest":self.xbmc_vfs.root_path,"files":fileManager.getFiles()})
Expand Down Expand Up @@ -329,11 +352,16 @@ def _rotateBackups(self):

def _createValidationFile(self):
vFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "xbmcbackup.val"),'w')
vFile.write("XBMC Backup Validation File");
vFile.write("XBMC Backup Validation File")
vFile.close()

self.remote_vfs.put(xbmc.translatePath(utils.data_dir() + "xbmcbackup.val"),self.remote_vfs.root_path + "xbmcbackup.val")

def _createResumeBackupFile(self):
rFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "resume.txt"),'w')
rFile.write(self.restore_point)
rFile.close()

class FileManager:
fileArray = []
not_dir = ['.zip','.xsp','.rar']
Expand Down
28 changes: 27 additions & 1 deletion scheduler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import xbmc
import xbmcvfs
import xbmcgui
import datetime
import time
import os
Expand All @@ -10,6 +12,7 @@ class BackupScheduler:
monitor = None
enabled = "false"
next_run = 0
restore_point = None

def __init__(self):
self.monitor = UpdateMonitor(update_method = self.settingsChanged)
Expand All @@ -25,6 +28,17 @@ def setup(self):
utils.log("scheduler will run again on " + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M'))

def start(self):

#check if a backup should be resumed
resumeRestore = self._resumeCheck()

if(resumeRestore):
restore = XbmcBackup()
restore.selectRestore(self.restore_point)
#skip the advanced settings check
restore.skipAdvanced()
restore.run(XbmcBackup.Restore)

while(not xbmc.abortRequested):

if(self.enabled == "true"):
Expand Down Expand Up @@ -92,7 +106,19 @@ def parseSchedule(self):
#first day of month
cron_exp = "0 " + str(hour_of_day) + " 1 * *"

return cron_exp
return cron_exp

def _resumeCheck(self):
shouldContinue = False
if(xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + "resume.txt"))):
rFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "resume.txt"),'r')
self.restore_point = rFile.read()
rFile.close()
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "resume.txt"))
shouldContinue = xbmcgui.Dialog().yesno("Resume Restore","XBMC Backup has detected an unfinished restore","Would you like to continue?")

return shouldContinue


class UpdateMonitor(xbmc.Monitor):
update_method = None
Expand Down

0 comments on commit af11c1a

Please sign in to comment.