当前位置: 首页>>代码示例>>Python>>正文


Python crontab.CronTab方法代码示例

本文整理汇总了Python中crontab.CronTab方法的典型用法代码示例。如果您正苦于以下问题:Python crontab.CronTab方法的具体用法?Python crontab.CronTab怎么用?Python crontab.CronTab使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在crontab的用法示例。


在下文中一共展示了crontab.CronTab方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def __init__(self):
        self.cron = CronTab(user=True)
        params = PARAMS % os.getuid()
        filename = os.path.join(os.path.expanduser('~'), FILE)
        desktop_environment = get_desktop_environment()
        if desktop_environment == 'gnome' or \
                desktop_environment == 'unity' or \
                desktop_environment == 'budgie-desktop':
            gset = GSET_GNOME % filename
        elif desktop_environment == "mate":
            gset = GSET_MATE % filename
        elif desktop_environment == "cinnamon":
            gset = GSET_CINNAMON % filename
        else:
            gset = None
        if gset is not None:
            self.command = 'sleep 20;{0};{1} {2} {4} && {3} {4}'.format(
                params, EXEC, SCRIPT, gset, NO_OUTPUT)
        else:
            self.command = None 
开发者ID:atareao,项目名称:daily-wallpaper,代码行数:22,代码来源:croni.py

示例2: uninstall_cron

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def uninstall_cron():
    if os.geteuid() != 0:
        print("It seems you are not root, please run \"muninflux fetch --uninstall-cron\" again with root privileges".format(sys.argv[0]))
        sys.exit(1)

    try:
        import crontab
    except ImportError:
        from vendor import crontab

    cron = crontab.CronTab(user=CRON_USER)
    jobs = list(cron.find_comment(CRON_COMMENT))
    cron.remove(*jobs)
    cron.write()

    return len(jobs) 
开发者ID:mvonthron,项目名称:munin-influxdb,代码行数:18,代码来源:fetch.py

示例3: install_cron

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def install_cron(script_file, period):
    if os.geteuid() != 0:
        print("It seems you are not root, please run \"muninflux fetch --install-cron\" again with root privileges".format(sys.argv[0]))
        sys.exit(1)

    try:
        import crontab
    except ImportError:
        from vendor import crontab

    cron = crontab.CronTab(user=CRON_USER)
    job = cron.new(command=script_file, user=CRON_USER, comment=CRON_COMMENT)
    job.minute.every(period)

    if job.is_valid() and job.is_enabled():
        cron.write()

    return job.is_valid() and job.is_enabled() 
开发者ID:mvonthron,项目名称:munin-influxdb,代码行数:20,代码来源:fetch.py

示例4: setupCron

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def setupCron(self):
        cron = CronTab()
        cron_setting = textwrap.dedent("""\
            ┌───────────── minute (0 - 59)
            │ ┌───────────── hour (0 - 23)
            │ │ ┌───────────── day of month (1 - 31)
            │ │ │ ┌───────────── month (1 - 12)
            │ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday;
            │ │ │ │ │                                       7 is also Sunday on some systems)
            │ │ │ │ │
            │ │ │ │ │
            * * * * *  command to execute
        """)
        choice = input(cron_setting)

# Reddit class 
开发者ID:amcquade,项目名称:fresh_script,代码行数:18,代码来源:models.py

示例5: cron_tab

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def cron_tab(self):
        #Count need to be 1 in order to write to the crontab.
        #Basically, checking for grep being None or not None will 
        #not work in this case and we need to check for 2 occurances.
        count=0
        cmd="/bin/bash /home/root/.ssh/is_sshm_running.sh"
        cron = CronTab(user='root')
        job  = cron.new(command=cmd)
        job.minute.every(1)
        for job in cron:
            grep = re.search(r'\/is_sshm_running.sh', str(job))
            if grep is not None:
                count+=1
        #if count < 2 and self.install:
        if count < 2:
            Logger.log("INFO", "Installing crontab.")
            cron.write()
            Logger.log("WARN","Please nesure that the crontab was actually installed!")
            Logger.log("WARN","To do so please run(without quotes) => 'sudo crontab -l -u root'") 
开发者ID:amboxer21,项目名称:SSHMonitor2.7,代码行数:21,代码来源:setup.py

示例6: schedule_synch

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def schedule_synch(day, email, password):
    if not day:
        exit_with_message('Failed to schedule synch: Invalid day')
    if not email or not password:
        exit_with_message('Invalid username and password')
    day = day.upper()
    if not day in ['MON','TUE','WED','THU','FRI','SAT','SUN']:
        exit_with_message('Failed to schedule synch: Invalid day')
    user_cron = CronTab(user=True)
    cmd = "%s -d %s -S -e %s -p %s" % (os.path.abspath(__file__), COURSE_DIR, email, password)
    job = user_cron.new(command=cmd)
    job.hour.on(11)
    job.minute.on(59)
    job.dow.on(day)
    user_cron.write()
    print 'Cron Job added' 
开发者ID:sanketh95,项目名称:coursera-offline,代码行数:18,代码来源:coursera_offline.py

示例7: schedule_cron

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def schedule_cron(command, interval, crontab=None):
    from crontab import CronTab, CronItem
    if not os.path.exists(crontab):
        with open(crontab, 'w'):
            pass

    if crontab:
        c = CronTab(tabfile=crontab)
    else:
        c = CronTab(user=getpass.getuser())

    job = CronItem.from_line(interval + ' ' + command, cron=c)

    c.append(job)
    c.write()
    return c, job 
开发者ID:timkpaine,项目名称:paperboy,代码行数:18,代码来源:__init__.py

示例8: _set_auto_update

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def _set_auto_update(interval):
    """
    Creates cron job for auto updating repository
    :param interval: (every x minutes)
    :return:
    """
    os.system(f'crond')
    cron = CronTab(user='root')
    cron.remove_all()
    job = cron.new(command='bootstrap update', comment='update')
    job.minute.every(interval)
    cron.write() 
开发者ID:pozgo,项目名称:docker-mkdocs,代码行数:14,代码来源:common.py

示例9: __init__

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def __init__(self, platform_config):
        self.platform_config = platform_config
        self.cron = CronTab(user=self.platform_config.cron_user())
        self.log = logger.get_logger('cron') 
开发者ID:syncloud,项目名称:platform,代码行数:6,代码来源:cron.py

示例10: clear_cron

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def clear_cron():
    """ This is needed so that if any one removes his scaling action
          it should not be trigger again """
    my_cron = CronTab(user='root')
    my_cron.remove_all(comment="Scheduling_Jobs")
    my_cron.write() 
开发者ID:amelbakry,项目名称:kube-schedule-scaler,代码行数:8,代码来源:schedule_scaling.py

示例11: handle

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def handle(self, *args, **options):
        """Installs Cron

        :param args: None
        :param options: None
        :return: None
        """
        action = options.get('action')
        tab = CronTab(user=True)
        virtualenv = os.environ.get('VIRTUAL_ENV', None)

        jobs = [
            {'name': 'janeway_cron_job', 'time': 30, 'task': 'execute_cron_tasks'},
            {'name': 'janeway_ithenticate_job', 'time': 30, 'task': 'store_ithenticate_scores'},
        ]

        if settings.ENABLE_ENHANCED_MAILGUN_FEATURES:
            jobs.append({'name': 'janeway_mailgun_job', 'time': 60, 'task': 'check_mailgun_stat'})

        for job in jobs:
            current_job = find_job(tab, job['name'])

            if not current_job:
                django_command = "{0}/manage.py {1}".format(settings.BASE_DIR, job['task'])
                if virtualenv:
                    command = '%s/bin/python3 %s' % (virtualenv, django_command)
                else:
                    command = '%s' % (django_command)

                cron_job = tab.new(command, comment=job['name'])
                cron_job.minute.every(job['time'])

            else:
                print("{name} cron job already exists.".format(name=job['name']))

        if action == 'test':
            print(tab.render())
        elif action == 'quiet':
            pass
        else:
            tab.write() 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:43,代码来源:install_cron.py

示例12: __init__

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def __init__(self, *args, **kwargs):
        super(FastCronTab, self).__init__(*args, **kwargs)
        # Degenerate case where CronTab is much too slow
        self.every_minute = args[0] == '* * * * *'
        self.cached_now = None
        self.cached_next = None 
开发者ID:quantopian,项目名称:coal-mine,代码行数:8,代码来源:crontab_schedule.py

示例13: set_crontab_tasks

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def set_crontab_tasks():
    """
        设置定时任务:

        1. 定期删除过期的ES索引
        2. 定时扫描万能钥匙
    """
    logger.info("set crontab tasks.")
    my_user_cron = CronTab(user=True)

    # 定时扫描万能钥匙 每2分钟一次
    skeleton_job = my_user_cron.new(
        command='/usr/bin/python3 {project_dir}/scripts/skeleton_key_scan.py >/dev/null 2>&1'
        .format(project_dir=project_dir))
    skeleton_job.minute.every(2)
    skeleton_job.set_comment("skeleton_job")
    logger.info("set skeleton_key_scan every 2 min.")
    # my_user_cron.remove(skeleton_job)

    # 定时删除过期索引 每天删除
    delete_index_job = my_user_cron.new(
        command='/usr/bin/python3 {project_dir}/scripts/delete_index.py >/dev/null 2>&1'
        .format(project_dir=project_dir))
    delete_index_job.day.every(1)
    delete_index_job.hour.on(0)
    delete_index_job.minute.on(0)
    delete_index_job.set_comment("delete_index_job")
    logger.info("set delete_index_job every day.")
    # my_user_cron.remove(delete_index_job)

    my_user_cron.write() 
开发者ID:0Kee-Team,项目名称:WatchAD,代码行数:33,代码来源:init_settings.py

示例14: get_cron_tab

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def get_cron_tab(self):
        return CronTab(user=True) 
开发者ID:dagster-io,项目名称:dagster,代码行数:4,代码来源:cron_scheduler.py

示例15: _install_cron

# 需要导入模块: import crontab [as 别名]
# 或者: from crontab import CronTab [as 别名]
def _install_cron(args):
    # Get user's current crontab, so as not to override it
    old_content = []
    cron = CronTab(user=True)
    with tempfile.NamedTemporaryFile() as temp:
        cron.write(temp.name)

        # Ignore all previous entries
        for line in temp.readlines():
            line = line.decode()
            if line and 'detect-secrets-server' not in line:
                old_content.append(line.strip())

    # Create jobs from tracked repositories
    jobs = []
    for repo, is_local in list_tracked_repositories(args):
        command = '{}    detect-secrets-server scan {}'.format(
            repo['crontab'],
            repo['repo']
        )
        if is_local:
            command += ' --local'
        if args.root_dir:
            command += ' --root-dir {}'.format(args.root_dir)
        if args.output_hook_command:
            command += ' {}'.format(args.output_hook_command)
        jobs.append(command.strip())

    # Construct new crontab
    content = '\n'.join(jobs)
    if old_content:
        content = '{}\n\n{}'.format(
            '\n'.join(old_content),
            content,
        )

    cron = CronTab(
        tab=content,
        user=True,
    )
    cron.write_to_user(user=True) 
开发者ID:Yelp,项目名称:detect-secrets-server,代码行数:43,代码来源:install.py


注:本文中的crontab.CronTab方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。