Exemplo n.º 1
0
    def test_read_empty_crontab(self, mock):
        """Test reading from an empty crontab."""
        mock.return_value = Mock(
            stdout=StringIO(''),
            stderr=StringIO('crontab: no crontab for <user>'))

        read_crontab()
Exemplo n.º 2
0
    def test_read_empty_crontab(self, mock):
        """Test reading from an empty crontab."""
        mock.return_value = Mock(
            stdout=StringIO(''),
            stderr=StringIO('crontab: no crontab for <user>')
        )

        read_crontab()
Exemplo n.º 3
0
    def test_read_crontab(self, mock):
        """Test reading from the crontab."""
        mock.return_value = Mock(
            stdout=StringIO('crontab: installing new crontab'),
            stderr=StringIO(''))

        read_crontab()

        mock.assert_called_with(args='crontab -l',
                                shell=True,
                                stdout=PIPE,
                                stderr=PIPE)
Exemplo n.º 4
0
    def test_read_crontab(self, mock):
        """Test reading from the crontab."""
        mock.return_value = Mock(
            stdout=StringIO('crontab: installing new crontab'),
            stderr=StringIO('')
        )

        read_crontab()

        mock.assert_called_with(
            args='crontab -l',
            shell=True,
            stdout=PIPE,
            stderr=PIPE
        )
Exemplo n.º 5
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()
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo 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 %(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()
Exemplo 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()
Exemplo 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 %(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()
Exemplo n.º 12
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()
Exemplo 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()
Exemplo n.º 14
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()
Exemplo n.º 15
0
def setup():
    global crontab_backup
    crontab_backup = read_crontab()
Exemplo n.º 16
0
def test_write_crontab():
    """Test writing to the crontab."""
    write_crontab("* * * * * echo\n")

    assert read_crontab() == '* * * * * echo\n'
Exemplo n.º 17
0
def test_unintalltasks():
    """Test uninstalling tasks via the ``uninstalltasks`` command."""
    call_command('uninstalltasks')

    for task in tasks:
        assert task.cron_expression not in read_crontab()
Exemplo n.º 18
0
def test_read_crontab():
    """Test reading from the crontab."""
    assert read_crontab() == crontab_backup