Example #1
0
def test_generate_git_tgz(kctx: kitipy.Context, keep: bool):
    """(Re) Generate tests/git-archive.tgz.
    
    This command has been implemented and used to generate the original
    tests/git-archive.tgz file, which is used to test git-related helper
    functions.
    """
    tempdir = kctx.executor.mkdtemp()
    commands = ['cd ' + tempdir, 'git init']
    commits = (
        ('foo', 'v0.1'),
        ('bar', 'v0.2'),
        ('baz', 'v0.3'),
        ('pi', 'v0.4'),
        ('yolo', 'v0.5'),
    )

    for commit, tag in commits:
        commands.append('touch ' + commit)
        commands.append('git add ' + commit)
        commands.append('git commit -m "%s"' % (commit))
        commands.append('git tag %s HEAD' % (tag))

    basedir = os.path.dirname(os.path.abspath(__file__))
    tgz_path = os.path.join(basedir, 'tests', 'tasks', 'testdata',
                            'git-repo.tgz')
    commands.append('tar zcf %s .' % (tgz_path))

    try:
        kctx.run(' && '.join(commands))
    finally:
        if not keep:
            kctx.run('rm -rf %s' % (tempdir))
Example #2
0
def galaxy_install(kctx: Context,
                   dest: str,
                   file: str = 'galaxy-requirements.yml',
                   force: bool = False):
    """Install Ansible dependencies using ``ansible-galaxy install``.

    Args:
        kctx (kitipy.Context):
            Context to use to run ``ansible-galaxy``.
        dest (str):
            Directory path where dependencies should be installed.
        file (str):
            Requirements file (defaults to ``galaxy-requirements.yml``).
        force (bool):
            Whehter ``--force`` flag should be added to ``ansible-galaxy`` command.
    """
    kctx.run('ansible-galaxy install -r %s -p %s %s' % (
        file,
        dest,
        '--force' if force else '',
    ))