Merge pull request #116 from robweber/miss_scheduled

Miss scheduled
This commit is contained in:
Rob 2017-11-07 15:11:23 -06:00 committed by GitHub
commit 71e8e44e27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 20 deletions

View File

@ -100,4 +100,5 @@
<string id="30106">is authorized</string>
<string id="30107">error authorizing</string>
<string id="30108">Visit https://console.developers.google.com/</string>
<string id="30109">Run on startup if missed</string>
</strings>

View File

@ -36,6 +36,7 @@
<setting id="schedule_time" type="labelenum" label="30062" values="00:00|01:00|02:00|03:00|04:00|05:00|06:00|07:00|08:00|09:00|10:00|11:00|12:00|13:00|14:00|15:00|16:00|17:00|18:00|19:00|20:00|21:00|22:00|23:00" default="00:00" visible="!eq(-1,4)" enable="eq(-2,true)"/>
<setting id="day_of_week" type="enum" label="30063" lvalues="30065|30066|30067|30068|30069|30070|30071" default="0" visible="eq(-2,2)" enable="eq(-3,true)"/>
<setting id="cron_schedule" type="text" label="30064" default="0 0 * * *" visible="eq(-3,4)" enable="eq(-4,true)"/>
<setting id="cron_shutdown" type="bool" label="30076" default="false" enable="eq(-5,true)" />
<setting id="schedule_miss" type="bool" label="30109" default="false" enable="eq(-5,true)" />
<setting id="cron_shutdown" type="bool" label="30076" default="false" enable="eq(-6,true)" />
</category>
</settings>

View File

@ -12,13 +12,38 @@ 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 = xbmc.translatePath(utils.data_dir()) + 'next_run.txt'
if(self.enabled == "true"):
if(xbmcvfs.exists(self.next_run_path)):
nr = 0
fh = xbmcvfs.File(self.next_run_path)
try:
#check if we saved a run time from the last run
nr = float(fh.read())
except ValueError:
nr = 0
fh.close()
#if we missed and the user wants to play catch-up
if(0 < nr <= time.time() and utils.getSetting('schedule_miss') == 'true'):
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)
self.setup()
def setup(self):
@ -46,26 +71,8 @@ class BackupScheduler:
if(self.next_run <= now):
progress_mode = int(utils.getSetting('progress_mode'))
if(progress_mode != 2):
utils.showNotification(utils.getString(30053))
backup = XbmcBackup()
self.doScheduledBackup(progress_mode)
if(backup.remoteConfigured()):
if(int(utils.getSetting('progress_mode')) in [0,1]):
backup.run(XbmcBackup.Backup,True)
else:
backup.run(XbmcBackup.Backup,False)
#check if this is a "one-off"
if(int(utils.getSetting("schedule_interval")) == 0):
#disable the scheduler after this run
self.enabled = "false"
utils.setSetting('enable_scheduler','false')
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
@ -80,6 +87,27 @@ class BackupScheduler:
#delete monitor to free up memory
del self.monitor
def doScheduledBackup(self,progress_mode):
if(progress_mode != 2):
utils.showNotification(utils.getString(30053))
backup = XbmcBackup()
if(backup.remoteConfigured()):
if(int(utils.getSetting('progress_mode')) in [0,1]):
backup.run(XbmcBackup.Backup,True)
else:
backup.run(XbmcBackup.Backup,False)
#check if this is a "one-off"
if(int(utils.getSetting("schedule_interval")) == 0):
#disable the scheduler after this run
self.enabled = "false"
utils.setSetting('enable_scheduler','false')
else:
utils.showNotification(utils.getString(30045))
def findNextRun(self,now):
progress_mode = int(utils.getSetting('progress_mode'))
@ -93,6 +121,11 @@ class BackupScheduler:
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'))
#write the next time to a file
fh = xbmcvfs.File(self.next_run_path, 'w')
fh.write(str(self.next_run))
fh.close()
#only show when not in silent mode
if(progress_mode != 2):
utils.showNotification(utils.getString(30081) + " " + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M'))