mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-15 04:45:49 +01:00
Merge branch 'master' of https://github.com/robweber/xbmcbackup into frodo-dev
This commit is contained in:
commit
a3724657c7
@ -4,7 +4,9 @@ import xbmcaddon
|
|||||||
__addon_id__= 'script.xbmcbackup'
|
__addon_id__= 'script.xbmcbackup'
|
||||||
__Addon = xbmcaddon.Addon(__addon_id__)
|
__Addon = xbmcaddon.Addon(__addon_id__)
|
||||||
|
|
||||||
#global functions for logging and encoding
|
def data_dir():
|
||||||
|
return __Addon.getAddonInfo('profile')
|
||||||
|
|
||||||
def log(message,loglevel=xbmc.LOGNOTICE):
|
def log(message,loglevel=xbmc.LOGNOTICE):
|
||||||
xbmc.log(encode(__addon_id__ + ": " + message),level=loglevel)
|
xbmc.log(encode(__addon_id__ + ": " + message),level=loglevel)
|
||||||
|
|
||||||
|
50
scheduler.py
50
scheduler.py
@ -1,6 +1,7 @@
|
|||||||
import xbmc
|
import xbmc
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
|
import os
|
||||||
import resources.lib.utils as utils
|
import resources.lib.utils as utils
|
||||||
from resources.lib.croniter import croniter
|
from resources.lib.croniter import croniter
|
||||||
from resources.lib.backup import XbmcBackup
|
from resources.lib.backup import XbmcBackup
|
||||||
@ -8,6 +9,7 @@ from resources.lib.backup import XbmcBackup
|
|||||||
class BackupScheduler:
|
class BackupScheduler:
|
||||||
enabled = "false"
|
enabled = "false"
|
||||||
next_run = 0
|
next_run = 0
|
||||||
|
settings_update_time = 0
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.enabled = utils.getSetting("enable_scheduler")
|
self.enabled = utils.getSetting("enable_scheduler")
|
||||||
@ -18,12 +20,22 @@ class BackupScheduler:
|
|||||||
def setup(self):
|
def setup(self):
|
||||||
#scheduler was turned on, find next run time
|
#scheduler was turned on, find next run time
|
||||||
utils.log("scheduler enabled, finding next run time")
|
utils.log("scheduler enabled, finding next run time")
|
||||||
self.findNextRun(time.time())
|
self.findNextRun(time.time(),True)
|
||||||
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'))
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
while(not xbmc.abortRequested):
|
while(not xbmc.abortRequested):
|
||||||
if(self.enabled == "true"):
|
current_enabled = utils.getSetting("enable_scheduler")
|
||||||
|
|
||||||
|
if(current_enabled == "true" and self.enabled == "false"):
|
||||||
|
#scheduler was just turned on
|
||||||
|
self.enabled = current_enabled
|
||||||
|
self.setup()
|
||||||
|
elif (current_enabled == "false" and self.enabled == "true"):
|
||||||
|
#schedule was turn off
|
||||||
|
self.enabled = current_enabled
|
||||||
|
elif(self.enabled == "true"):
|
||||||
|
#scheduler is still on
|
||||||
now = time.time()
|
now = time.time()
|
||||||
|
|
||||||
if(self.next_run <= now):
|
if(self.next_run <= now):
|
||||||
@ -34,24 +46,32 @@ class BackupScheduler:
|
|||||||
backup.run(XbmcBackup.Backup,True)
|
backup.run(XbmcBackup.Backup,True)
|
||||||
|
|
||||||
self.findNextRun(now)
|
self.findNextRun(now)
|
||||||
else:
|
|
||||||
self.enabled = utils.getSetting("enable_scheduler")
|
|
||||||
|
|
||||||
if(self.enabled == "true"):
|
|
||||||
self.setup()
|
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
def findNextRun(self,now):
|
def findNextRun(self,now,forceUpdate = False):
|
||||||
#find the cron expression and get the next run time
|
mod_time = self.settings_update_time
|
||||||
cron_exp = self.parseSchedule()
|
|
||||||
|
#check if the schedule has been modified
|
||||||
|
try:
|
||||||
|
#get the last modified time of the file
|
||||||
|
mod_time = os.path.getmtime(xbmc.translatePath(utils.data_dir()) + "settings.xml")
|
||||||
|
except:
|
||||||
|
#don't do anything here
|
||||||
|
mod_time = self.settings_update_time
|
||||||
|
|
||||||
cron_ob = croniter(cron_exp,datetime.datetime.fromtimestamp(now))
|
if(mod_time > self.settings_update_time or forceUpdate):
|
||||||
new_run_time = cron_ob.get_next(float)
|
self.settings_update_time = mod_time
|
||||||
|
|
||||||
|
#find the cron expression and get the next run time
|
||||||
|
cron_exp = self.parseSchedule()
|
||||||
|
|
||||||
if(new_run_time != self.next_run):
|
cron_ob = croniter(cron_exp,datetime.datetime.fromtimestamp(now))
|
||||||
self.next_run = new_run_time
|
new_run_time = cron_ob.get_next(float)
|
||||||
utils.log("scheduler will run again on " + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M'))
|
|
||||||
|
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'))
|
||||||
|
|
||||||
def parseSchedule(self):
|
def parseSchedule(self):
|
||||||
schedule_type = int(utils.getSetting("schedule_interval"))
|
schedule_type = int(utils.getSetting("schedule_interval"))
|
||||||
|
Loading…
Reference in New Issue
Block a user