def showNotify(self,displayToScreen = True):
        #go through and find the next schedule to run
        next_run_time = CronSchedule()
        for cronJob in self.schedules:
            if(cronJob.next_run < next_run_time.next_run or next_run_time.next_run == 0):
                next_run_time = cronJob

        inWords = self.nextRunCountdown(next_run_time.next_run)
        #show the notification (if applicable)
        if(next_run_time.next_run > time.time() and utils.getSetting('notify_next_run') == 'true' and displayToScreen == True):
            utils.showNotification(utils.getString(30000),next_run_time.name + " - " + inWords)
                                   
        return inWords    
Beispiel #2
0
    def databaseUpdated(self, database):
        showDialogs = utils.getSettingBool(
            'notify_next_run'
        )  # if the user has selected to show dialogs for library operations
        # check if we should clean the library
        if (utils.getSettingBool('clean_libraries')):
            # check if should update while playing media
            if (not xbmc.Player().isPlaying()
                    or utils.getSettingBool("run_during_playback")):
                if (utils.getSettingInt("clean_timer") == 0):
                    # check if we should clean music, or video
                    aJob = CronSchedule()
                    aJob.name = utils.getString(30048)
                    aJob.timer_type = utils.__addon_id__
                    if ((utils.getSettingInt('library_to_clean') == 0
                         or utils.getSettingInt('library_to_clean') == 1)
                            and database == 'video'):
                        # create the clean job schedule
                        aJob.command = {
                            'method': 'VideoLibrary.Clean',
                            'params': {
                                'showdialogs': showDialogs
                            }
                        }
                    if ((utils.getSettingInt('library_to_clean') == 2
                         or utils.getSettingInt('library_to_clean') == 0)
                            and database == 'music'):
                        aJob.command = {
                            'method': 'AudioLibrary.Clean',
                            'params': {
                                'showdialogs': showDialogs
                            }
                        }

                    self.cleanLibrary(aJob)

        # writeLastRun will trigger notifications
        self.writeLastRun()
    def createSchedules(self,forceUpdate = False):
        utils.log("update timers")
        self.lock = True   #lock so the eval portion does not run
        self.schedules = []
            
        if(utils.getSetting('clean_libraries') == 'true'):
            #create clean schedule (if needed)
            if(int(utils.getSetting("clean_timer")) != 0):
                    
                if(utils.getSetting('library_to_clean') == '0' or utils.getSetting('library_to_clean') == '1'):
                    #video clean schedule starts at 12am by default
                    aSchedule = CronSchedule()
                    aSchedule.name = utils.getString(30048)
                    aSchedule.timer_type = utils.__addon_id__
                    aSchedule.command = 'video'
                    if(int(utils.getSetting("clean_timer")) == 4):
                        aSchedule.expression = utils.getSetting("clean_video_cron_expression")
                    else:
                        aSchedule.expression = "0 0 " + aSchedule.cleanLibrarySchedule(int(utils.getSetting("clean_timer")))
                    aSchedule.next_run = self.calcNextRun(aSchedule.expression,time.time())

                    self.schedules.append(aSchedule)
                        
                if(utils.getSetting('library_to_clean') == '2' or utils.getSetting('library_to_clean') == '0'):
                    #music clean schedule starts at 2am by default
                    aSchedule = CronSchedule()
                    aSchedule.name = utils.getString(30049)
                    aSchedule.timer_type = utils.__addon_id__
                    aSchedule.command = 'music'
                    if(int(utils.getSetting("clean_timer")) == 4):
                        aSchedule.expression = utils.getSetting("clean_music_cron_expression")
                    else:
                        aSchedule.expression = "0 2 " + aSchedule.cleanLibrarySchedule(int(utils.getSetting("clean_timer")))
                    aSchedule.next_run = self.calcNextRun(aSchedule.expression,time.time())
    
                    self.schedules.append(aSchedule)
                                                                                

        if(utils.getSetting('update_video') == 'true'):
            utils.log("Creating timer for Video Library");
            #create the video schedule
            aSchedule = CronSchedule()
            aSchedule.name = utils.getString(30012)
            aSchedule.command = 'UpdateLibrary(video)'
            aSchedule.expression = self.checkTimer('video')
            aSchedule.next_run = self.calcNextRun(aSchedule.expression,self.last_run)
                
            self.schedules.append(aSchedule)

        if(utils.getSetting('update_music') == 'true'):
            utils.log("Creating timer for Music Library");
            #create the music schedule
            aSchedule = CronSchedule()
            aSchedule.name = utils.getString(30013)
            aSchedule.command = 'UpdateLibrary(music)'
            aSchedule.expression = self.checkTimer('music')
            aSchedule.next_run = self.calcNextRun(aSchedule.expression,self.last_run)
                
            self.schedules.append(aSchedule)

        if(utils.getSetting('use_custom_1_path') == 'true'):
            utils.log("Creating timer for Custom Path 1");
            #create a custom video path schedule
            aSchedule = CronSchedule()
            aSchedule.name = utils.getString(30020)
            aSchedule.command = 'UpdateLibrary(video,' + utils.getSetting('custom_1_scan_path') + ')'
            aSchedule.expression = self.checkTimer('custom_1')
            aSchedule.next_run = self.calcNextRun(aSchedule.expression,self.last_run)
                
            self.schedules.append(aSchedule)

        if(utils.getSetting('use_custom_2_path') == 'true'):
            utils.log("Creating timer for Custom Path 2");
            #create a custom video path schedule
            aSchedule = CronSchedule()
            aSchedule.name = utils.getString(30021)
            aSchedule.command = 'UpdateLibrary(video,' + utils.getSetting('custom_2_scan_path') + ')'
            aSchedule.expression = self.checkTimer('custom_2')
            aSchedule.next_run = self.calcNextRun(aSchedule.expression,self.last_run)
                
            self.schedules.append(aSchedule)

        if(utils.getSetting('use_custom_3_path') == 'true'):
            utils.log("Creating timer for Custom Path 3");
            #create a custom video path schedule
            aSchedule = CronSchedule()
            aSchedule.name = utils.getString(30022)
            aSchedule.command = 'UpdateLibrary(video,' + utils.getSetting('custom_3_scan_path') + ')'
            aSchedule.expression = self.checkTimer('custom_3')
            aSchedule.next_run = self.calcNextRun(aSchedule.expression,self.last_run)
                
            self.schedules.append(aSchedule)

        #read in any custom path options
        for aJob in self.customPaths.getJobs():
            utils.log("Creating timer " + aJob.name)
            aJob.next_run = self.calcNextRun(aJob.expression, self.last_run)
            self.schedules.append(aJob)

        #release the lock
        self.lock = False
        
        utils.log("Created " + str(len(self.schedules)) + " schedules",xbmc.LOGDEBUG)
        
        #show any notifications
        self.showNotify(not forceUpdate)
Beispiel #4
0
    def createSchedules(self, forceUpdate=False):
        utils.log("update timers")
        self.lock = True  # lock so the eval portion does not run
        self.schedules = []
        showDialogs = utils.getSettingBool(
            'notify_next_run'
        )  # if the user has selected to show dialogs for library operations

        if (utils.getSettingBool('clean_libraries')):
            # create clean schedule (if needed)
            if (utils.getSettingInt("clean_timer") != 0):

                if (utils.getSettingInt('library_to_clean') == 0
                        or utils.getSettingInt('library_to_clean') == 1):
                    # video clean schedule starts at 12am by default
                    aSchedule = CronSchedule()
                    aSchedule.name = utils.getString(30048)
                    aSchedule.timer_type = utils.__addon_id__
                    aSchedule.command = {
                        'method': 'VideoLibrary.Clean',
                        'params': {
                            'showdialogs': showDialogs
                        }
                    }
                    if (utils.getSettingInt("clean_timer") == 4):
                        aSchedule.expression = utils.getSetting(
                            "clean_video_cron_expression")
                    else:
                        aSchedule.expression = "0 0 " + aSchedule.cleanLibrarySchedule(
                            utils.getSettingInt("clean_timer"))
                    aSchedule.next_run = self.calcNextRun(
                        aSchedule.expression, time.time())

                    self.schedules.append(aSchedule)

                if (utils.getSettingInt('library_to_clean') == 2
                        or utils.getSettingInt('library_to_clean') == 0):
                    # music clean schedule starts at 2am by default
                    aSchedule = CronSchedule()
                    aSchedule.name = utils.getString(30049)
                    aSchedule.timer_type = utils.__addon_id__
                    aSchedule.command = {
                        'method': 'AudioLibrary.Clean',
                        'params': {
                            'showdialogs': showDialogs
                        }
                    }
                    if (utils.getSettingInt("clean_timer") == 4):
                        aSchedule.expression = utils.getSetting(
                            "clean_music_cron_expression")
                    else:
                        aSchedule.expression = "0 2 " + aSchedule.cleanLibrarySchedule(
                            utils.getSettingInt("clean_timer"))
                    aSchedule.next_run = self.calcNextRun(
                        aSchedule.expression, time.time())

                    self.schedules.append(aSchedule)

        if (utils.getSettingBool('update_video')):
            utils.log("Creating timer for Video Library")
            # create the video schedule
            aSchedule = CronSchedule()
            aSchedule.name = utils.getString(30012)
            aSchedule.command = {
                'method': 'VideoLibrary.Scan',
                'params': {
                    'showdialogs': showDialogs
                }
            }
            aSchedule.expression = self.checkTimer('video')
            aSchedule.next_run = self.calcNextRun(aSchedule.expression,
                                                  self.last_run)
            self.schedules.append(aSchedule)

        # add custom video paths (separate timers)
        customPaths = CustomPathFile('video')
        for aJob in customPaths.getSchedules(showDialogs):
            utils.log("Creating timer " + aJob.name)
            aJob.next_run = self.calcNextRun(aJob.expression, self.last_run)
            self.schedules.append(aJob)

        if (utils.getSettingBool('update_music')):
            utils.log("Creating timer for Music Library")
            # create the music schedule
            aSchedule = CronSchedule()
            aSchedule.name = utils.getString(30013)
            aSchedule.command = {
                'method': 'AudioLibrary.Scan',
                'params': {
                    'showdialogs': showDialogs
                }
            }
            aSchedule.expression = self.checkTimer('music')
            aSchedule.next_run = self.calcNextRun(aSchedule.expression,
                                                  self.last_run)

            self.schedules.append(aSchedule)

        # add custom music paths (separate timers)
        customPaths = CustomPathFile('music')
        for aJob in customPaths.getSchedules(showDialogs):
            utils.log("Creating timer " + aJob.name)
            aJob.next_run = self.calcNextRun(aJob.expression, self.last_run)
            self.schedules.append(aJob)

        # release the lock
        self.lock = False

        utils.log("Created " + str(len(self.schedules)) + " schedules",
                  xbmc.LOGDEBUG)

        # show any notifications
        self.showNotify(not forceUpdate)