mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-14 20:35:48 +01:00
added call to XbmcBackup.run() in service.py file
added showNotification() method so that a notification can display when backup starts via scheduler
This commit is contained in:
parent
0bb915ae3a
commit
9bda2055b3
@ -106,9 +106,9 @@ class XbmcBackup:
|
||||
|
||||
utils.log(utils.getString(30046))
|
||||
|
||||
def run(self,mode=-1):
|
||||
def run(self,mode=-1,runSilent=False):
|
||||
#check if we should use the progress bar
|
||||
if(utils.getSetting('run_silent') == 'false'):
|
||||
if(utils.getSetting('run_silent') == 'false' and not runSilent):
|
||||
self.progressBar = xbmcgui.DialogProgress()
|
||||
self.progressBar.create(utils.getString(30010),utils.getString(30049) + "......")
|
||||
|
||||
@ -147,6 +147,9 @@ class XbmcBackup:
|
||||
self.restoreFiles()
|
||||
else:
|
||||
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30045),self.remote_path)
|
||||
|
||||
if(utils.getSetting('run_silent') == 'false' and not runSilent):
|
||||
self.progressBar.close()
|
||||
|
||||
def syncFiles(self):
|
||||
|
||||
@ -188,9 +191,6 @@ class XbmcBackup:
|
||||
else:
|
||||
vfs.copy(xbmc.makeLegalFilename(source + aFile),xbmc.makeLegalFilename(dest + aFile,False))
|
||||
|
||||
if(utils.getSetting('run_silent') == 'false'):
|
||||
self.progressBar.close()
|
||||
|
||||
def updateProgress(self,message=''):
|
||||
self.filesLeft = self.filesLeft - 1
|
||||
|
||||
|
@ -8,6 +8,9 @@ __Addon = xbmcaddon.Addon(__addon_id__)
|
||||
def log(message,loglevel=xbmc.LOGNOTICE):
|
||||
xbmc.log(encode(__addon_id__ + ": " + message),level=loglevel)
|
||||
|
||||
def showNotification(message):
|
||||
xbmc.executebuiltin("Notification(" + getString(30010) + "," + message + ",4000," + xbmc.translatePath(__Addon.getAddonInfo('path') + "/icon.png") + ")")
|
||||
|
||||
def getSetting(name):
|
||||
return __Addon.getSetting(name)
|
||||
|
||||
|
41
scheduler.py
41
scheduler.py
@ -1,25 +1,58 @@
|
||||
import xbmc
|
||||
import datetime
|
||||
import time
|
||||
import resources.lib.utils as utils
|
||||
from resources.lib.croniter import croniter
|
||||
from resources.lib.backup import XbmcBackup
|
||||
|
||||
class BackupScheduler:
|
||||
enabled = "false"
|
||||
|
||||
next_run = 0
|
||||
|
||||
def __init__(self):
|
||||
self.enabled = utils.getSetting("enable_scheduler")
|
||||
|
||||
if(self.enabled == "true"):
|
||||
self.setup()
|
||||
|
||||
def setup(self):
|
||||
#scheduler was turned on, find next run time
|
||||
utils.log("scheduler enabled, finding next run time")
|
||||
self.findNextRun(time.time())
|
||||
utils.log("scheduler will run again on " + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M'))
|
||||
|
||||
def start(self):
|
||||
while(not xbmc.abortRequested):
|
||||
if(self.enabled == "true"):
|
||||
cron_exp = self.parseSchedule()
|
||||
utils.log(cron_exp)
|
||||
now = time.time()
|
||||
|
||||
if(self.next_run <= now):
|
||||
if(utils.getSetting('run_silent') == 'false'):
|
||||
utils.showNotification("Starting scheduled backup")
|
||||
#run the job in backup mode, hiding the dialog box
|
||||
backup = XbmcBackup()
|
||||
backup.run(XbmcBackup.Backup,True)
|
||||
|
||||
self.findNextRun(now)
|
||||
else:
|
||||
utils.log("backup not enabled")
|
||||
self.enabled = utils.getSetting("enable_scheduler")
|
||||
|
||||
if(self.enabled == "true"):
|
||||
self.setup()
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
def findNextRun(self,now):
|
||||
#find the cron expression and get the next run time
|
||||
cron_exp = self.parseSchedule()
|
||||
|
||||
cron_ob = croniter(cron_exp,datetime.datetime.fromtimestamp(now))
|
||||
new_run_time = cron_ob.get_next(float)
|
||||
|
||||
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):
|
||||
schedule_type = int(utils.getSetting("schedule_interval"))
|
||||
cron_exp = utils.getSetting("cron_schedule")
|
||||
|
Loading…
Reference in New Issue
Block a user