Ejemplo n.º 1
0
def test_git_cloned_yet(tmpdir):
    assert utils.git_cloned_yet(str(tmpdir)) is False

    # create .git dir
    tmpdir.mkdir('.git')

    assert utils.git_cloned_yet(str(tmpdir)) is True
Ejemplo n.º 2
0
def test_git_cloned_yet(tmpdir):
    assert utils.git_cloned_yet(str(tmpdir)) is False

    # create .git dir
    tmpdir.mkdir('.git')

    assert utils.git_cloned_yet(str(tmpdir)) is True
Ejemplo n.º 3
0
def main(config):
    """Command builder.

    :param config: config snippet for this plugin
    :type config: dict
    :returns: Commands to create the backup
    :rtype: list
    """
    commands = []

    destination = config['destination']

    # git init if its not a repo yet
    if config['mode'] == 'git':
        cloned_yet = utils.git_cloned_yet(destination)
        if not cloned_yet:
            commands.append(['cd', destination, '&&', 'git', 'init'])

    # slapcat command
    commands.append([
        'slapcat', '-l',
        join(utils.absolutenormpath(destination), 'backup.ldif')
    ])

    # commit if git mode is used
    if config['mode'] == 'git':
        if not cloned_yet or utils.git_something_to_commit(destination):
            commands.append([
                'cd', destination, '&&', 'git', 'add', 'backup.ldif', '&&',
                'git', 'commit', '-m', '"new export"'
            ])

    return commands
Ejemplo n.º 4
0
def main(config):
    """Command builder.

    :param config: config snippet for this plugin
    :type config: dict
    :returns: Commands to create the backup
    :rtype: list
    """
    commands = []

    destination = config['destination']

    # git init if its not a repo yet
    if config['mode'] == 'git':
        cloned_yet = utils.git_cloned_yet(destination)
        if not cloned_yet:
            commands.append(['cd', destination, '&&', 'git', 'init'])

    # slapcat command
    commands.append(['slapcat', '-l',
                     join(utils.absolutenormpath(destination), 'backup.ldif')])

    # commit if git mode is used
    if config['mode'] == 'git':
        if not cloned_yet or utils.git_something_to_commit(destination):
            commands.append(
                ['cd', destination,
                 '&&',
                 'git', 'add', 'backup.ldif',
                 '&&',
                 'git', 'commit', '-m', '"new export"'])

    return commands
Ejemplo n.º 5
0
def main(config: CONFIGTYPE) -> COMMANDLISTTYPE:
    """Command builder.

    :param config: config snippet for this plugin
    :returns: Commands to create the backup
    """
    commands = []

    destination = config['destination']

    # if commiting every dump to a git repo it has to init first if
    # its not there
    if config['mode'] == 'git':
        cloned_yet = utils.git_cloned_yet(destination)
        if not cloned_yet:
            commands.append(['cd', destination, '&&', 'git', 'init'])

    # mysqldump command
    commands.append(
        [
            'mysqldump', '--skip-extended-insert', '--skip-comments',
            '--user={}'.format(config['username']),
            '--password={}'.format(config['password']),
            '--host={}'.format(config['server']),
            config['database'],
            '>',
            path.join(
                utils.absolutenormpath(destination),
                '{}.sql'.format(config['database'])
            )
        ]
    )

    # commit if git mode is used
    if config['mode'] == 'git':

        # only commit if there is something to be commited
        if not cloned_yet or utils.git_something_to_commit(destination):

            commands.append(
                [
                    'cd', destination,
                    '&&',
                    'git', 'add', '{}.sql'.format(config['database']),
                    '&&',
                    'git', 'commit', '-m', '"new dump"'
                ]
            )

    return commands
Ejemplo n.º 6
0
def main(config):
    """Command builder.

    :param config: config snippet for this plugin
    :type config: dict
    :returns: Commands to create the backup
    :rtype: list
    """
    commands = []

    # if there is no cloned repo yet... do it first
    if not utils.git_cloned_yet(config['destination']):
        commands.append(
            ['git', 'clone', config['source'], config['destination']])

    commands.append(['cd', config['destination'], '&&', 'git', 'pull'])

    return commands
Ejemplo n.º 7
0
def main(config):
    """Command builder.

    :param config: config snippet for this plugin
    :type config: dict
    :returns: Commands to create the backup
    :rtype: list
    """
    commands = []

    # if there is no cloned repo yet... do it first
    if not utils.git_cloned_yet(config['destination']):
        commands.append(['git', 'clone', config['source'],
                         config['destination']])

    commands.append(['cd', config['destination'], '&&', 'git', 'pull'])

    return commands
Ejemplo n.º 8
0
def main(config):
    """Command builder.

    :param config: config snippet for this plugin
    :type config: dict
    :returns: Commands to create the backup
    :rtype: list
    """
    commands = []

    destination = config['destination']

    # if commiting every dump to a git repo it has to init first if
    # its not there
    if config['mode'] == 'git':
        cloned_yet = utils.git_cloned_yet(destination)
        if not cloned_yet:
            commands.append(['cd', destination, '&&', 'git', 'init'])

    # mysqldump command
    commands.append(['mysqldump', '--skip-extended-insert', '--skip-comments',
                     '--user={}'.format(config['username']),
                     '--password={}'.format(config['password']),
                     '--host={}'.format(config['server']),
                     config['database'],
                     '>',
                     path.join(
                         utils.absolutenormpath(destination),
                         '{}.sql'.format(config['database']))])

    # commit if git mode is used
    if config['mode'] == 'git':

        # only commit if there is something to be commited
        if not cloned_yet or utils.git_something_to_commit(destination):

            commands.append(['cd', destination,
                             '&&',
                             'git', 'add', '{}.sql'.format(config['database']),
                             '&&',
                             'git', 'commit', '-m', '"new dump"'])

    return commands
Ejemplo n.º 9
0
def main(config: CONFIGTYPE) -> COMMANDLISTTYPE:
    """Command builder.

    :param config: config snippet for this plugin
    :returns: Commands to create the backup
    """
    commands = []

    # if there is no cloned repo yet... do it first
    if not utils.git_cloned_yet(config['destination']):
        commands.append(
            [
                'git', 'clone', config['source'],
                config['destination']
            ]
        )

    commands.append(['cd', config['destination'], '&&', 'git', 'pull'])

    return commands
Ejemplo n.º 10
0
def main(config: CONFIGTYPE) -> COMMANDLISTTYPE:
    """Command builder.

    :param config: config snippet for this plugin
    :returns: Commands to create the backup
    """
    commands = []

    # walk through the github repos
    for repo in get_repos(config['username']):

        destination = os.path.join(config['destination'], repo['name'])

        # if the repo is not cloned yet, do it first
        if not utils.git_cloned_yet(destination):
            commands.append(['git', 'clone', repo['clone_url'], destination])

        # add git pull command
        commands.append(['cd', destination, '&&', 'git', 'pull'])

    return commands
Ejemplo n.º 11
0
def main(config):
    """Command builder.

    :param config: config snippet for this plugin
    :type config: dict
    :returns: Commands to create the backup
    :rtype: list
    """
    commands = []

    # walk through the github repos
    for repo in get_repos(config['username']):

        destination = os.path.join(config['destination'], repo['name'])

        # if the repo is not cloned yet, do it first
        if not utils.git_cloned_yet(destination):
            commands.append(['git', 'clone', repo['clone_url'], destination])

        # add git pull command
        commands.append(['cd', destination, '&&', 'git', 'pull'])

    return commands