Get information about all the cron jobs accessible to the current user
426213
async def listCronJobs(self):
        '''
        
        '''
        crons = []
        for iden, cron in self.cell.agenda.list():
            useriden = cron['useriden']
            if not (self.user.admin or useriden == self.user.iden):
                continue
            user = self.cell.auth.user(useriden)
            cron['username'] = '<unknown>' if user is None else user.name
            crons.append((iden, cron))

        return crons
394371
def UpdateCronJob(self,
                    cronjob_id,
                    last_run_status=db.Database.unchanged,
                    last_run_time=db.Database.unchanged,
                    current_run_id=db.Database.unchanged,
                    state=db.Database.unchanged,
                    forced_run_requested=db.Database.unchanged):
    """"""
    job = self.cronjobs.get(cronjob_id)
    if job is None:
      raise db.UnknownCronJobError("Cron job %s not known." % cronjob_id)

    if last_run_status != db.Database.unchanged:
      job.last_run_status = last_run_status
    if last_run_time != db.Database.unchanged:
      job.last_run_time = last_run_time
    if current_run_id != db.Database.unchanged:
      job.current_run_id = current_run_id
    if state != db.Database.unchanged:
      job.state = state
    if forced_run_requested != db.Database.unchanged:
      job.forced_run_requested = forced_run_requested
740616
def _IsCronJobFailing(self, cron_job):
    """"""
    status = cron_job.Get(cron_job.Schema.LAST_RUN_STATUS)
    if status is None:
      return False

    return status.status != rdf_cronjobs.CronJobRunStatus.Status.OK
315571
def _check_cron(user,
                path,
                mask,
                cmd):
    '''
    
    '''
    arg_mask = mask.split(',')
    arg_mask.sort()

    lst = __salt__['incron.list_tab'](user)
    for cron in lst['crons']:
        if path == cron['path'] and cron['cmd'] == cmd:
            cron_mask = cron['mask'].split(',')
            cron_mask.sort()
            if cron_mask == arg_mask:
                return 'present'
            if any([x in cron_mask for x in arg_mask]):
                return 'update'
    return 'absent'
838299
def sources(scheduled=False):
    ''''''
    sources = actions.list_sources()
    if scheduled:
        sources = [s for s in sources if s.periodic_task]
    if sources:
        for source in sources:
            msg = '{source.name} ({source.backend}): {cron}'
            if source.periodic_task:
                cron = source.periodic_task.schedule_display
            else:
                cron = 'not scheduled'
            log.info(msg.format(source=source, cron=cron))
    elif scheduled:
        log.info('No sources scheduled yet')
    else:
        log.info('No sources defined yet')
1310349
def ReadCronJobRuns(self, job_id, cursor=None):
    """"""
    query = """
    SELECT run, UNIX_TIMESTAMP(write_time)
      FROM cron_job_runs
     WHERE job_id = %s
    """
    cursor.execute(query, [job_id])
    runs = [self._CronJobRunFromRow(row) for row in cursor.fetchall()]
    return sorted(runs, key=lambda run: run.started_at, reverse=True)
1329601
def users():
    """"""
    for admin in current_app.config['ADMIN_USERS']:
        try:
            db.get_db()  # init db on global app context
            user = User.find_by_username(admin)
        except Exception as e:
            click.echo('ERROR: {}'.format(e))
        else:
            if user:
                click.echo('{} {}'.format(user.id, user.name))
789894
def list(self, allJobs=False):
        

        jobs = self.server.call('get', '/job')

        return [Job(job['id'], self.server) for job in jobs if allJobs or self._job_owned(job)]
1281461
def _check_cron_env(user,
                    name,
                    value=None):
    '''
    
    '''
    if value is None:
        value = ""  # Matching value set in salt.modules.cron._render_tab
    lst = __salt__['cron.list_tab'](user)
    for env in lst['env']:
        if name == env['name']:
            if value != env['value']:
                return 'update'
            return 'present'
    return 'absent'
558465
public function listAction()
    {
        $this->performAccessChecks();

        $crons = $this->cronService->getCrons();

        return $this->render('SmileEzUICronBundle:cron:tab/crons/list.html.twig', [
            'datas' => $crons
        ]);
    }
323031
def getent(refresh=False):
    '''
    
    '''
    if 'user.getent' in __context__ and not refresh:
        return __context__['user.getent']

    ret = []
    for data in pwd.getpwall():
        ret.append(info(data.pw_name))
    __context__['user.getent'] = ret
    return ret
95119
def list_tab(user):
    '''
    
    '''
    data = raw_cron(user)
    ret = {'pre': [],
           'crons': [],
           'special': [],
           'env': []}
    flag = False
    comment = None
    identifier = None
    for line in data.splitlines():
        if line == '# Lines below here are managed by Salt, do not edit':
            flag = True
            continue
        if flag:
            commented_cron_job = False
            if line.startswith('#DISABLED#'):
                # It's a commented cron job
                line = line[10:]
                commented_cron_job = True
            if line.startswith('@'):
                # Its a "special" line
                dat = {}
                comps = line.split()
                if len(comps) < 2:
                    # Invalid line
                    continue
                dat['spec'] = comps[0]
                dat['cmd'] = ' '.join(comps[1:])
                dat['identifier'] = identifier
                dat['comment'] = comment
                dat['commented'] = False
                if commented_cron_job:
                    dat['commented'] = True
                ret['special'].append(dat)
                identifier = None
                comment = None
                commented_cron_job = False
            elif line.startswith('#'):
                # It's a comment! Catch it!
                comment_line = line.lstrip('# ')

                # load the identifier if any
                if SALT_CRON_IDENTIFIER in comment_line:
                    parts = comment_line.split(SALT_CRON_IDENTIFIER)
                    comment_line = parts[0].rstrip()
                    # skip leading :
                    if len(parts[1]) > 1:
                        identifier = parts[1][1:]

                if comment is None:
                    comment = comment_line
                else:
                    comment += '\n' + comment_line
            elif line.find('=') > 0 and (' ' not in line or line.index('=') < line.index(' ')):
                # Appears to be a ENV setup line
                comps = line.split('=', 1)
                dat = {}
                dat['name'] = comps[0]
                dat['value'] = comps[1]
                ret['env'].append(dat)
            elif len(line.split(' ')) > 5:
                # Appears to be a standard cron line
                comps = line.split(' ')
                dat = {'minute': comps[0],
                       'hour': comps[1],
                       'daymonth': comps[2],
                       'month': comps[3],
                       'dayweek': comps[4],
                       'identifier': identifier,
                       'cmd': ' '.join(comps[5:]),
                       'comment': comment,
                       'commented': False}
                if commented_cron_job:
                    dat['commented'] = True
                ret['crons'].append(dat)
                identifier = None
                comment = None
                commented_cron_job = False
        else:
            ret['pre'].append(line)
    return ret
1160227
def list_tab(user):
    '''
    
    '''
    if user == 'system':
        data = raw_system_incron()
    else:
        data = raw_incron(user)
        log.debug('incron user data %s', data)
    ret = {'crons': [],
           'pre': []
           }
    flag = False
    comment = None
    tag = '# Line managed by Salt, do not edit'
    for line in data.splitlines():
        if line.endswith(tag):
            if len(line.split()) > 3:
                # Appears to be a standard incron line
                comps = line.split()
                path = comps[0]
                mask = comps[1]
                (cmd, comment) = ' '.join(comps[2:]).split(' # ')

                dat = {'path': path,
                       'mask': mask,
                       'cmd': cmd,
                       'comment': comment}
                ret['crons'].append(dat)
                comment = None
        else:
            ret['pre'].append(line)
    return ret
398762
def ReadCronJobs(self, cronjob_ids=None):
    """"""
    if cronjob_ids is None:
      res = [job.Copy() for job in itervalues(self.cronjobs)]

    else:
      res = []
      for job_id in cronjob_ids:
        try:
          res.append(self.cronjobs[job_id].Copy())
        except KeyError:
          raise db.UnknownCronJobError("Cron job with id %s not found." %
                                       job_id)

    for job in res:
      lease = self.cronjob_leases.get(job.cron_job_id)
      if lease:
        job.leased_until, job.leased_by = lease
    return res
1100222
def _setup_crontab():
    """"""
    from crontab import CronTab
    #Since CI works out of a virtualenv anyway, the `ci.py` script will be
    #installed in the bin already, so we can call it explicitly.
    command = '/bin/bash -c "source ~/.cron_profile; workon {}; ci.py -cron"'.format(settings.venv)
    user = _get_real_user()
    if args["nolive"]:
        vms("Skipping cron tab configuration because 'nolive' enabled.")
        return
    cron = CronTab(user=user)
    
    #We need to see if the cron has already been created for this command.
    existing = False
    possible = cron.find_comment("pyci_cron")
    if len(list(possible)) > 0:
        if args["rollback"]:
            vms("Removing {} from cron tab.".format(command))
            cron.remove_all(command)
            cron.write()
            db["cron"] = False
            _save_db()
        else:
            existing = True
    
    if not existing and not args["rollback"]:
        job = cron.new(command=command, comment="pyci_cron")
        #Run the cron every minute of every hour every day.
        if args["cronfreq"] == 1:
            vms("New cron tab configured *minutely* for {}".format(command))
            job.setall("* * * * *")
        else:
            vms("New cron tab configured every {} minutes for {}.".format(args["cronfreq"], command))
            job.setall("*/{} * * * *".format(args["cronfreq"]))
        cron.write()
        db["cron"] = True
        _save_db()
1317298
def get_all_tasks(conf):
    

    db = HamsterDB(conf)

    fact_list = db.all_facts_id
    security_days = int(conf.get_option('tasks.security_days'))
    today = datetime.today()

    tasks = {}

    for fact_id in fact_list:
        ht = HamsterTask(fact_id, conf, db)
        if ht.end_time:
            end_time = ht.get_object_dates()[1]
            if today - timedelta(security_days) <= end_time:
                rt = ht.get_remote_task()
                tasks[rt.task_id] = rt

    db.close_connection()

    print 'Obtained %d tasks' % len(tasks)
    return tasks
555467
def activate_crontab(self):
        
        self._crontab = []
        if hasattr(self, 'CRONTAB'):
            for crontab_spec in self.CRONTAB:
                args = cronjob.parse_crontab(crontab_spec)
                job = cronjob.CronJob()
                if args['_timer'] == 'datetime':
                    job.set_triggers(args['trigger_format'], args['trigger_time'])
                if args['_timer'] == 'crontab':
                    job.set_crontab(args['crontab'])
                if args['action'].startswith('.'):
                    action_name = args['action'][1:]
                    action_ = getattr(self.__class__, action_name)
                else:
                    action_ = args['action']
                job.set_action(action_, *args['args'])
                self._crontab.append(job)
        self.start_poller(30, self.poll_crontab)