Example #1
0
    def addJob(self, job):

        try:
            # verify the cron expression here, throws ValueError if wrong
            croniter(job.expression)
        except:
            # didn't work
            return False

        # set the addon id if there isn't one
        if (job.addon is None):
            job.addon = utils.addon_id()

        self._refreshJobs()

        if (job.id >= 0):
            # replace existing job
            self.jobs[job.id] = job
        else:
            # set the job id
            job.id = self._nextId()

            # add a new job
            self.jobs[job.id] = job

        # write the file
        self._writeCronFile()

        return True
Example #2
0
    def calcNextRun(self,cronExp,startTime):
        
        #create croniter for this expression
        cron = croniter(cronExp,startTime)
        nextRun = cron.get_next(float)

        return nextRun
    def findNextRun(self, now):
        progress_mode = int(utils.getSetting('progress_mode'))

        #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'))

            #write the next time to a file
            fh = xbmcvfs.File(self.next_run_path, 'w')
            fh.write(str(self.next_run))
            fh.close()

            #only show when not in silent mode
            if (progress_mode != 2):
                utils.showNotification(
                    utils.getString(30081) + " " +
                    datetime.datetime.fromtimestamp(self.next_run).strftime(
                        '%m-%d-%Y %H:%M'))
    def calcNextRun(self,cronExp,startTime):
        
        #create croniter for this expression
        cron = croniter(cronExp,startTime)
        nextRun = cron.get_next(float)

        return nextRun
Example #5
0
    def nextRun(self, cronJob):
        # create a cron expression
        now = datetime.datetime.now()
        cron_exp = croniter(cronJob.expression, now)

        # compare now with next date
        nextRun = cron_exp.get_next(datetime.datetime)
        cronDiff = (nextRun - now).total_seconds()
        hours = int((cronDiff / 60) / 60)
        minutes = int(cronDiff / 60 - hours * 60)

        # we always have at least one minute
        if minutes == 0:
            minutes = 1

        result = str(hours) + " h " + str(minutes) + " m"
        if hours == 0:
            result = str(minutes) + " m"
        elif hours > 36:
            # just show the date instead
            result = utils.getRegionalTimestamp(nextRun, ['dateshort', 'time'])
        elif hours > 24:
            days = int(hours / 24)
            hours = hours - days * 24
            result = str(days) + " d " + str(hours) + " h " + str(
                minutes) + " m"

        return result
Example #6
0
    def findNextRun(self, now):
        progress_mode = utils.getSettingInt('progress_mode')

        # find the cron expression and get the next run time
        cron_exp = self.parseSchedule()

        cron_ob = croniter(cron_exp, 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 " +
                      utils.getRegionalTimestamp(
                          datetime.fromtimestamp(self.next_run),
                          ['dateshort', 'time']))

            # write the next time to a file
            with xbmcvfs.File(self.next_run_path, 'w') as fh:
                fh.write(str(self.next_run))

            # only show when not in silent mode
            if (progress_mode != 2):
                utils.showNotification(
                    utils.getString(30081) + " " + utils.getRegionalTimestamp(
                        datetime.fromtimestamp(self.next_run),
                        ['dateshort', 'time']))
Example #7
0
    def runProgram(self):
        monitor = xbmc.Monitor()

        # run until abort requested
        while (True):

            structTime = time.localtime()
            now = datetime.datetime.now()

            # only do all this if we are in a new minute
            if (structTime[4] != self.last_check):
                self.last_check = structTime[4]

                # get a list of all the cron jobs
                cron_jobs = self.manager.getJobs()

                for command in cron_jobs:
                    # create a cron expression for this command (using previous minute)
                    cron_exp = croniter(command.expression,
                                        now - datetime.timedelta(seconds=60))

                    runTime = cron_exp.get_next(datetime.datetime)
                    # if this command should run then run it
                    if (runTime <= now):
                        self.runJob(command)
                        utils.log(command.name + " will run again on " +
                                  utils.getRegionalTimestamp(
                                      cron_exp.get_next(datetime.datetime),
                                      ['dateshort', 'time']))

            # calculate the sleep time (next minute)
            currentSec = datetime.datetime.now()
            if (monitor.waitForAbort(60 - currentSec.second)):
                break
Example #8
0
    def runProgram(self):
        #run until XBMC quits
        while(not xbmc.abortRequested):

            structTime = time.localtime()
            now = time.time()
            
            #only do all this if we are in a new minute
            if(structTime[4] != self.last_check):
                self.last_check = structTime[4]

                #get a list of all the cron jobs
                cron_jobs = self.readCronFile()

                for command in cron_jobs:
                    #create a cron expression for this command
                    cron_exp = croniter(command.expression,datetime.datetime.fromtimestamp(now - 60))
                    self.nextRun(command)
                    runTime = cron_exp.get_next(float);
                    #if this command should run then run it
                    if(runTime <= now):
                        self.runJob(command)
                        self.log(command.name + " will run again on " + datetime.datetime.fromtimestamp(cron_exp.get_next(float)).strftime('%m-%d-%Y %H:%M'))

            #get as close to the top of each minute as we can
            self.sleep_time = 10 - (time.time() % 60 % 10)
            if(int(self.sleep_time) == 0):
                self.sleep_time = 10
                
            time.sleep(self.sleep_time)
Example #9
0
    def nextRun(self,cronJob):
        #create a cron expression
        cron_exp = croniter(cronJob.expression,datetime.datetime.fromtimestamp(time.time()))

        #compare now with next date
        nextRun = cron_exp.get_next(float)
        cronDiff = nextRun - time.time()
        hours = int((cronDiff / 60) / 60)
        minutes = int(cronDiff / 60 - hours * 60)

        #we always have at least one minute
        if minutes == 0:
            minutes = 1

        result = str(hours) + " h " + str(minutes) + " m"

        if hours == 0:
            result = str(minutes) + " m"
        elif hours > 36:
            #just show the date instead
            result = datetime.datetime.fromtimestamp(nextRun).strftime('%m/%d %I:%M%p')
        elif hours > 24:
            days = int(hours / 24)
            hours = hours - days * 24
            result = str(days) + " d " + str(hours) + " h " + str(minutes) + " m"
        
        return result
Example #10
0
    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'))
Example #11
0
 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)
     # utils.log('new run time' +  str(new_run_time))
     # utils.log('next run time' + str(self.next_run))
     if(new_run_time != self.next_run):
         self.next_run = new_run_time
         utils.showNotification('EPG Updater', 'Next Update: ' + 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'))
Example #12
0
    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.showNotification(
                utils.getString(30081) + " " + 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'))
Example #13
0
    def calcNextRun(self, cronExp, startTime):
        nextRun = -1

        try:
            # create croniter for this expression
            cron = croniter(cronExp, startTime)
            nextRun = cron.get_next(float)
        except ValueError:
            # error in syntax
            xbmcgui.Dialog().ok(utils.getString(30000),
                                utils.getString(30016) % cronExp)
            utils.log('Cron syntax error %s' % cronExp, xbmc.LOGDEBUG)

            # rerun with a valid syntax
            nextRun = self.calcNextRun('0 */2 * * *', startTime)

        return nextRun
Example #14
0
    def findNextRun(self,now):
        progress_mode = int(utils.getSetting('progress_mode'))
        
        #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'))

            #write the next time to a file
            fh = xbmcvfs.File(self.next_run_path, 'w')
            fh.write(str(self.next_run))
            fh.close()

            #only show when not in silent mode
            if(progress_mode != 2):                        
                utils.showNotification(utils.getString(30081) + " " + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M'))
Example #15
0
    def findNextRun(self,now,forceUpdate = False):
        mod_time = self.settings_update_time
        
        #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

        if(mod_time > self.settings_update_time or forceUpdate):
            self.settings_update_time = mod_time
            
            #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'))