copy/paste from the original pull request

This commit is contained in:
Rob Weber 2017-11-07 14:35:36 -06:00
parent 4689ce9b82
commit af93f1916b

View File

@ -12,13 +12,29 @@ class BackupScheduler:
monitor = None
enabled = "false"
next_run = 0
next_run_path = None
restore_point = None
def __init__(self):
self.monitor = UpdateMonitor(update_method = self.settingsChanged)
self.enabled = utils.getSetting("enable_scheduler")
self.next_run_path = os.path.join(xbmc.translatePath(utils.data_dir()),'next_run')
if(self.enabled == "true"):
try:
fh = open(self.next_run_path, 'r')
fc = fh.read()
fh.close()
nr = float(fc)
except:
nr = 0
if(0 < nr <= time.time()):
utils.log("scheduled backup was missed, doing it now...")
progress_mode = int(utils.getSetting('progress_mode'))
if(progress_mode == 0):
progress_mode = 1 # Kodi just started, don't block it with a foreground progress bar
self.doScheduledBackup(progress_mode)
utils.log("...completed!")
self.setup()
def setup(self):
@ -46,6 +62,23 @@ class BackupScheduler:
if(self.next_run <= now):
progress_mode = int(utils.getSetting('progress_mode'))
self.doScheduledBackup(progress_mode)
#check if we should shut the computer down
if(utils.getSetting("cron_shutdown") == 'true'):
#wait 10 seconds to make sure all backup processes and files are completed
time.sleep(10)
xbmc.executebuiltin('ShutDown()')
else:
#find the next run time like normal
self.findNextRun(now)
xbmc.sleep(500)
#delete monitor to free up memory
del self.monitor
def doScheduledBackup(self,progress_mode):
if(progress_mode != 2):
utils.showNotification(utils.getString(30053))
@ -66,20 +99,6 @@ class BackupScheduler:
else:
utils.showNotification(utils.getString(30045))
#check if we should shut the computer down
if(utils.getSetting("cron_shutdown") == 'true'):
#wait 10 seconds to make sure all backup processes and files are completed
time.sleep(10)
xbmc.executebuiltin('ShutDown()')
else:
#find the next run time like normal
self.findNextRun(now)
xbmc.sleep(500)
#delete monitor to free up memory
del self.monitor
def findNextRun(self,now):
progress_mode = int(utils.getSetting('progress_mode'))
@ -92,6 +111,11 @@ class BackupScheduler:
if(new_run_time != self.next_run):
self.next_run = new_run_time
utils.log("scheduler will run again on " + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M'))
try:
fh = open(self.next_run_path, 'w')
fh.write(str(self.next_run))
fh.close()
except: pass
#only show when not in silent mode
if(progress_mode != 2):