mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-15 04:45:49 +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))
|
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
|
#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 = xbmcgui.DialogProgress()
|
||||||
self.progressBar.create(utils.getString(30010),utils.getString(30049) + "......")
|
self.progressBar.create(utils.getString(30010),utils.getString(30049) + "......")
|
||||||
|
|
||||||
@ -148,6 +148,9 @@ class XbmcBackup:
|
|||||||
else:
|
else:
|
||||||
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30045),self.remote_path)
|
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):
|
def syncFiles(self):
|
||||||
|
|
||||||
#make the remote directory
|
#make the remote directory
|
||||||
@ -188,9 +191,6 @@ class XbmcBackup:
|
|||||||
else:
|
else:
|
||||||
vfs.copy(xbmc.makeLegalFilename(source + aFile),xbmc.makeLegalFilename(dest + aFile,False))
|
vfs.copy(xbmc.makeLegalFilename(source + aFile),xbmc.makeLegalFilename(dest + aFile,False))
|
||||||
|
|
||||||
if(utils.getSetting('run_silent') == 'false'):
|
|
||||||
self.progressBar.close()
|
|
||||||
|
|
||||||
def updateProgress(self,message=''):
|
def updateProgress(self,message=''):
|
||||||
self.filesLeft = self.filesLeft - 1
|
self.filesLeft = self.filesLeft - 1
|
||||||
|
|
||||||
|
@ -8,6 +8,9 @@ __Addon = xbmcaddon.Addon(__addon_id__)
|
|||||||
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)
|
||||||
|
|
||||||
|
def showNotification(message):
|
||||||
|
xbmc.executebuiltin("Notification(" + getString(30010) + "," + message + ",4000," + xbmc.translatePath(__Addon.getAddonInfo('path') + "/icon.png") + ")")
|
||||||
|
|
||||||
def getSetting(name):
|
def getSetting(name):
|
||||||
return __Addon.getSetting(name)
|
return __Addon.getSetting(name)
|
||||||
|
|
||||||
|
39
scheduler.py
39
scheduler.py
@ -1,25 +1,58 @@
|
|||||||
import xbmc
|
import xbmc
|
||||||
|
import datetime
|
||||||
import time
|
import time
|
||||||
import resources.lib.utils as utils
|
import resources.lib.utils as utils
|
||||||
|
from resources.lib.croniter import croniter
|
||||||
from resources.lib.backup import XbmcBackup
|
from resources.lib.backup import XbmcBackup
|
||||||
|
|
||||||
class BackupScheduler:
|
class BackupScheduler:
|
||||||
enabled = "false"
|
enabled = "false"
|
||||||
|
next_run = 0
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.enabled = utils.getSetting("enable_scheduler")
|
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):
|
def start(self):
|
||||||
while(not xbmc.abortRequested):
|
while(not xbmc.abortRequested):
|
||||||
if(self.enabled == "true"):
|
if(self.enabled == "true"):
|
||||||
cron_exp = self.parseSchedule()
|
now = time.time()
|
||||||
utils.log(cron_exp)
|
|
||||||
|
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:
|
else:
|
||||||
utils.log("backup not enabled")
|
|
||||||
self.enabled = utils.getSetting("enable_scheduler")
|
self.enabled = utils.getSetting("enable_scheduler")
|
||||||
|
|
||||||
|
if(self.enabled == "true"):
|
||||||
|
self.setup()
|
||||||
|
|
||||||
time.sleep(10)
|
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):
|
def parseSchedule(self):
|
||||||
schedule_type = int(utils.getSetting("schedule_interval"))
|
schedule_type = int(utils.getSetting("schedule_interval"))
|
||||||
cron_exp = utils.getSetting("cron_schedule")
|
cron_exp = utils.getSetting("cron_schedule")
|
||||||
|
Loading…
Reference in New Issue
Block a user