initial checkin

This commit is contained in:
kodistuff1 2017-10-14 18:01:51 +03:00
parent 2927e31c59
commit 1f5e4709bc

View File

@ -12,13 +12,29 @@ class BackupScheduler:
monitor = None monitor = None
enabled = "false" enabled = "false"
next_run = 0 next_run = 0
next_run_path = None
restore_point = None restore_point = None
def __init__(self): def __init__(self):
self.monitor = UpdateMonitor(update_method = self.settingsChanged) self.monitor = UpdateMonitor(update_method = self.settingsChanged)
self.enabled = utils.getSetting("enable_scheduler") self.enabled = utils.getSetting("enable_scheduler")
self.next_run_path = os.path.join(xbmc.translatePath(utils.data_dir()),'next_run')
if(self.enabled == "true"): 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() self.setup()
def setup(self): def setup(self):
@ -46,6 +62,23 @@ class BackupScheduler:
if(self.next_run <= now): if(self.next_run <= now):
progress_mode = int(utils.getSetting('progress_mode')) 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): if(progress_mode != 2):
utils.showNotification(utils.getString(30053)) utils.showNotification(utils.getString(30053))
@ -66,20 +99,6 @@ class BackupScheduler:
else: else:
utils.showNotification(utils.getString(30045)) 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): def findNextRun(self,now):
progress_mode = int(utils.getSetting('progress_mode')) progress_mode = int(utils.getSetting('progress_mode'))
@ -92,6 +111,11 @@ class BackupScheduler:
if(new_run_time != self.next_run): if(new_run_time != self.next_run):
self.next_run = new_run_time 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')) 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 #only show when not in silent mode
if(progress_mode != 2): if(progress_mode != 2):