예제 #1
0
def _install_rbenv(repo_cmd_runner, version='default'):
    with tarfile_open(resource_filename('rbenv.tar.gz')) as tf:
        tf.extractall(repo_cmd_runner.path('.'))

    # Only install ruby-build if the version is specified
    if version != 'default':
        # ruby-download
        with tarfile_open(resource_filename('ruby-download.tar.gz')) as tf:
            tf.extractall(repo_cmd_runner.path('rbenv', 'plugins'))

        # ruby-build
        with tarfile_open(resource_filename('ruby-build.tar.gz')) as tf:
            tf.extractall(repo_cmd_runner.path('rbenv', 'plugins'))

    activate_path = repo_cmd_runner.path('rbenv', 'bin', 'activate')
    with io.open(activate_path, 'w') as activate_file:
        # This is similar to how you would install rbenv to your home directory
        # However we do a couple things to make the executables exposed and
        # configure it to work in our directory.
        # We also modify the PS1 variable for manual debugging sake.
        activate_file.write(
            '#!/usr/bin/env bash\n'
            "export RBENV_ROOT='{0}'\n"
            'export PATH="$RBENV_ROOT/bin:$PATH"\n'
            'eval "$(rbenv init -)"\n'
            'export PS1="(rbenv)$PS1"\n'
            # This lets us install gems in an isolated and repeatable
            # directory
            "export GEM_HOME='{0}/gems'\n"
            'export PATH="$GEM_HOME/bin:$PATH"\n'
            '\n'.format(repo_cmd_runner.path('rbenv')))

        # If we aren't using the system ruby, add a version here
        if version != 'default':
            activate_file.write('export RBENV_VERSION="{0}"\n'.format(version))
예제 #2
0
def test_make_archive(tmpdir_factory):
    output_dir = tmpdir_factory.get()
    git_path = git_dir(tmpdir_factory)
    # Add a files to the git directory
    with local.cwd(git_path):
        local['touch']('foo')
        local['git']('add', '.')
        local['git']('commit', '-m', 'foo')
        # We'll use this sha
        head_sha = get_head_sha('.')
        # And check that this file doesn't exist
        local['touch']('bar')
        local['git']('add', '.')
        local['git']('commit', '-m', 'bar')

    # Do the thing
    archive_path = make_archives.make_archive(
        'foo', git_path, head_sha, output_dir,
    )

    assert archive_path == os.path.join(output_dir, 'foo.tar.gz')
    assert os.path.exists(archive_path)

    extract_dir = tmpdir_factory.get()

    # Extract the tar
    with tarfile_open(archive_path) as tf:
        tf.extractall(extract_dir)

    # Verify the contents of the tar
    assert os.path.exists(os.path.join(extract_dir, 'foo'))
    assert os.path.exists(os.path.join(extract_dir, 'foo', 'foo'))
    assert not os.path.exists(os.path.join(extract_dir, 'foo', '.git'))
    assert not os.path.exists(os.path.join(extract_dir, 'foo', 'bar'))
예제 #3
0
def make_archive(name, repo, ref, destdir):
    """Makes an archive of a repository in the given destdir.

    :param text name: Name to give the archive.  For instance foo.  The file
    that is created will be called foo.tar.gz.
    :param text repo: Repository to clone.
    :param text ref: Tag/SHA/branch to check out.
    :param text destdir: Directory to place archives in.
    """
    output_path = os.path.join(destdir, name + '.tar.gz')
    with tmpdir() as tempdir:
        # Clone the repository to the temporary directory
        cmd_output('git', 'clone', repo, tempdir)
        with cwd(tempdir):
            cmd_output('git', 'checkout', ref)

        # We don't want the '.git' directory
        # It adds a bunch of size to the archive and we don't use it at
        # runtime
        rmtree(os.path.join(tempdir, '.git'))

        with tarfile_open(five.n(output_path), 'w|gz') as tf:
            tf.add(tempdir, name)

    return output_path
예제 #4
0
def make_archive(name, repo, ref, destdir):
    """Makes an archive of a repository in the given destdir.

    :param text name: Name to give the archive.  For instance foo.  The file
    that is created will be called foo.tar.gz.
    :param text repo: Repository to clone.
    :param text ref: Tag/SHA/branch to check out.
    :param text destdir: Directory to place archives in.
    """
    output_path = os.path.join(destdir, name + '.tar.gz')
    with tmpdir() as tempdir:
        # Clone the repository to the temporary directory
        local['git']('clone', repo, tempdir)
        with local.cwd(tempdir):
            local['git']('checkout', ref)

        # We don't want the '.git' directory
        # It adds a bunch of size to the archive and we don't use it at
        # runtime
        shutil.rmtree(os.path.join(tempdir, '.git'))

        # XXX: py2.6 derps if filename is unicode while writing
        # XXX: str() is used to preserve behavior in py3
        with tarfile_open(str(output_path), 'w|gz') as tf:
            tf.add(tempdir, name)

    return output_path
예제 #5
0
def test_make_archive(tempdir_factory):
    output_dir = tempdir_factory.get()
    git_path = git_dir(tempdir_factory)
    # Add a files to the git directory
    with cwd(git_path):
        cmd_output('touch', 'foo')
        cmd_output('git', 'add', '.')
        cmd_output('git', 'commit', '-m', 'foo')
        # We'll use this sha
        head_sha = get_head_sha('.')
        # And check that this file doesn't exist
        cmd_output('touch', 'bar')
        cmd_output('git', 'add', '.')
        cmd_output('git', 'commit', '-m', 'bar')

    # Do the thing
    archive_path = make_archives.make_archive(
        'foo', git_path, head_sha, output_dir,
    )

    assert archive_path == os.path.join(output_dir, 'foo.tar.gz')
    assert os.path.exists(archive_path)

    extract_dir = tempdir_factory.get()

    # Extract the tar
    with tarfile_open(archive_path) as tf:
        tf.extractall(extract_dir)

    # Verify the contents of the tar
    assert os.path.exists(os.path.join(extract_dir, 'foo'))
    assert os.path.exists(os.path.join(extract_dir, 'foo', 'foo'))
    assert not os.path.exists(os.path.join(extract_dir, 'foo', '.git'))
    assert not os.path.exists(os.path.join(extract_dir, 'foo', 'bar'))
예제 #6
0
def _install_rbenv(repo_cmd_runner, version='default'):
    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)

    with tarfile_open(resource_filename('rbenv.tar.gz')) as tf:
        tf.extractall(repo_cmd_runner.path('.'))
    shutil.move(
        repo_cmd_runner.path('rbenv'),
        repo_cmd_runner.path(directory),
    )

    # Only install ruby-build if the version is specified
    if version != 'default':
        # ruby-download
        with tarfile_open(resource_filename('ruby-download.tar.gz')) as tf:
            tf.extractall(repo_cmd_runner.path(directory, 'plugins'))

        # ruby-build
        with tarfile_open(resource_filename('ruby-build.tar.gz')) as tf:
            tf.extractall(repo_cmd_runner.path(directory, 'plugins'))

    activate_path = repo_cmd_runner.path(directory, 'bin', 'activate')
    with io.open(activate_path, 'w') as activate_file:
        # This is similar to how you would install rbenv to your home directory
        # However we do a couple things to make the executables exposed and
        # configure it to work in our directory.
        # We also modify the PS1 variable for manual debugging sake.
        activate_file.write(
            '#!/usr/bin/env bash\n'
            "export RBENV_ROOT='{0}'\n"
            'export PATH="$RBENV_ROOT/bin:$PATH"\n'
            'eval "$(rbenv init -)"\n'
            'export PS1="(rbenv)$PS1"\n'
            # This lets us install gems in an isolated and repeatable
            # directory
            "export GEM_HOME='{0}/gems'\n"
            'export PATH="$GEM_HOME/bin:$PATH"\n'
            '\n'.format(repo_cmd_runner.path(directory)))

        # If we aren't using the system ruby, add a version here
        if version != 'default':
            activate_file.write('export RBENV_VERSION="{0}"\n'.format(version))
예제 #7
0
def _install_rbenv(repo_cmd_runner, version="default"):
    with tarfile_open(resource_filename("rbenv.tar.gz")) as tf:
        tf.extractall(repo_cmd_runner.path("."))

    # Only install ruby-build if the version is specified
    if version != "default":
        # ruby-download
        with tarfile_open(resource_filename("ruby-download.tar.gz")) as tf:
            tf.extractall(repo_cmd_runner.path("rbenv", "plugins"))

        # ruby-build
        with tarfile_open(resource_filename("ruby-build.tar.gz")) as tf:
            tf.extractall(repo_cmd_runner.path("rbenv", "plugins"))

    activate_path = repo_cmd_runner.path("rbenv", "bin", "activate")
    with io.open(activate_path, "w") as activate_file:
        # This is similar to how you would install rbenv to your home directory
        # However we do a couple things to make the executables exposed and
        # configure it to work in our directory.
        # We also modify the PS1 variable for manual debugging sake.
        activate_file.write(
            "#!/usr/bin/env bash\n"
            "export RBENV_ROOT='{0}'\n"
            'export PATH="$RBENV_ROOT/bin:$PATH"\n'
            'eval "$(rbenv init -)"\n'
            'export PS1="(rbenv)$PS1"\n'
            # This lets us install gems in an isolated and repeatable
            # directory
            "export GEM_HOME='{0}/gems'\n"
            'export PATH="$GEM_HOME/bin:$PATH"\n'
            "\n".format(repo_cmd_runner.path("rbenv"))
        )

        # If we aren't using the system ruby, add a version here
        if version != "default":
            activate_file.write('export RBENV_VERSION="{0}"\n'.format(version))