Esempio n. 1
0
def teardown():
    global crontab_backup

    if crontab_backup:
        write_crontab(crontab_backup)
    else:
        delete_crontab()
Esempio n. 2
0
def uninstall():
    """
    Uninstall tasks from cron.
    """
    current_crontab = read_crontab()
    new_crontab = find_existing_jobs(current_crontab)

    if new_crontab:
        write_crontab(new_crontab)
    else:
        delete_crontab()
Esempio n. 3
0
    def test_write_crontab(self, mock):
        """Test writing to the crontab."""
        mock.return_value = Mock(
            stdout=StringIO('crontab: installing new crontab'),
            stderr=StringIO(''))

        write_crontab("* * * * * echo\n")

        mock.assert_called_with(args='printf \'* * * * * echo\n\' | crontab',
                                shell=True,
                                stdout=PIPE,
                                stderr=PIPE)
Esempio n. 4
0
def install():
    """
    Register tasks with cron.
    """
    load()
    current_crontab = six.u(read_crontab())

    new_crontab = ''
    for task in tasks:
        new_crontab += '%s\n' % task['fn'].cron_expression

    write_crontab(current_crontab + new_crontab)
Esempio n. 5
0
def install():
    """
    Register tasks with cron.
    """
    load()
    current_crontab = read_crontab()

    new_crontab = ''
    for task in tasks:
        new_crontab += '%s\n' % task['fn'].cron_expression

    write_crontab(current_crontab + new_crontab)
Esempio n. 6
0
    def test_write_crontab(self, mock):
        """Test writing to the crontab."""
        mock.return_value = Mock(
            stdout=StringIO('crontab: installing new crontab'),
            stderr=StringIO('')
        )

        write_crontab("* * * * * echo\n")

        mock.assert_called_with(
            args='printf \'* * * * * echo\n\' | crontab',
            shell=True,
            stdout=PIPE,
            stderr=PIPE
        )
Esempio n. 7
0
def install():
    """
    Register tasks with cron.
    """
    load()
    current_crontab = six.u(read_crontab())

    new_crontab = ''

    for env_line in KRONOS_ENV.splitlines():
        new_crontab += '# KRONOS_ENV_BREAD_CRUMB for next\n%s\n' % env_line

    for task in tasks:
        new_crontab += '%s\n' % task['fn'].cron_expression

    write_crontab(current_crontab + new_crontab)
Esempio n. 8
0
def uninstall():
    """
    Uninstall tasks from cron.
    """
    current_crontab = read_crontab()

    new_crontab = ''
    for line in current_crontab.split('\n')[:-1]:
        if '%(python)s %(manage)s runtask' % {
                'python': KRONOS_PYTHON,
                'manage': KRONOS_MANAGE,
        } not in line:
            new_crontab += '%s\n' % line

    if new_crontab:
        write_crontab(new_crontab)
    else:
        delete_crontab()
Esempio n. 9
0
def uninstall():
    """
    Uninstall tasks from cron.
    """
    current_crontab = read_crontab()

    new_crontab = ''
    for line in current_crontab.split('\n')[:-1]:
        if '%(python)s %(manage)s runtask' % {
            'python': KRONOS_PYTHON,
            'manage': KRONOS_MANAGE,
        } not in line:
            new_crontab += '%s\n' % line

    if new_crontab:
        write_crontab(new_crontab)
    else:
        delete_crontab()
Esempio n. 10
0
def uninstall():
    """
    Uninstall tasks from cron.
    """
    current_crontab = read_crontab()

    new_crontab = ''
    for line in current_crontab.split('\n')[:-1]:
        if '%(python)s %(project_path)s/manage.py runtask' % {
            'python': sys.executable,
            'project_path': PROJECT_PATH,
        } not in line:
            new_crontab += '%s\n' % line

    if new_crontab:
        write_crontab(new_crontab)
    else:
        delete_crontab()
Esempio n. 11
0
def uninstall():
    """
    Uninstall tasks from cron.
    """
    current_crontab = read_crontab()

    new_crontab = ''
    for line in current_crontab.split('\n')[:-1]:
        if '%(python)s %(project_path)s/manage.py runtask' % {
                'python': sys.executable,
                'project_path': PROJECT_PATH,
        } not in line:
            new_crontab += '%s\n' % line

    if new_crontab:
        write_crontab(new_crontab)
    else:
        delete_crontab()
Esempio n. 12
0
def uninstall():
    """
    Uninstall tasks from cron.
    """
    current_crontab = read_crontab()

    new_crontab = ''
    for line in six.u(current_crontab).split('\n')[:-1]:
        exp = '%(python)s %(manage)s runtask' % {
            'python': KRONOS_PYTHON,
            'manage': KRONOS_MANAGE,
            }
        if '$KRONOS_BREAD_CRUMB' not in line and exp not in line:
            new_crontab += '%s\n' % line

    if new_crontab:
        write_crontab(new_crontab)
    else:
        delete_crontab()
Esempio n. 13
0
def uninstall():
    """
    Uninstall tasks from cron.
    """
    current_crontab = read_crontab()

    new_crontab = ''
    for line in six.u(current_crontab).split('\n')[:-1]:
        exp = '%(python)s %(manage)s runtask' % {
            'python': KRONOS_PYTHON,
            'manage': KRONOS_MANAGE,
        }
        if '$KRONOS_BREAD_CRUMB' not in line and exp not in line:
            new_crontab += '%s\n' % line

    if new_crontab:
        write_crontab(new_crontab)
    else:
        delete_crontab()
Esempio n. 14
0
def test_write_crontab():
    """Test writing to the crontab."""
    write_crontab("* * * * * echo\n")

    assert read_crontab() == '* * * * * echo\n'