Пример #1
0
def clone(url, name=None, parent_dir=None, repo_name=''):
    start_msg('----- Cloning git repo: "{url}"'.format(**locals()))
    if not name:
        name = ctx().name
        message('Using context name: "{0}"'.format(name))
    if not parent_dir:
        parent_dir = ctx().repos_root()
        message('Using parent directory: "{0}"'.format(parent_dir))

    # make sure the parent directory exists.
    result = sudo('mkdir -p -m 0777 {0}'.format(parent_dir))
    if result.failed:
        raise HaltError('Unable to create repo parent directory: {0}'.format(parent_dir))

    with cd(parent_dir):
        result = run('git clone {url} {repo_name}'.format(**locals()))
        if result.return_code != 0:
            raise HaltError('Failed to clone repo: "{url}"'.format(**locals()))
    succeed_msg('Clone successful.')
Пример #2
0
def append_ssh_config(host, opts):
    """
    Appends a "Host" entry to the ssh config file, and adds the specified options.

    :param host: the name of the host (e.g., "github.com")
    :param opts: an option string, or iterable of option strings (e.g., ['StrictKeyChecking no'])
    :return: None
    """
    if isinstance(opts, basestring):
        opts = [opts]

    start_msg('----- Appending to file: "~/.ssh/config":')
    str = 'Host {0}\n\t{1}\n'.format(host, '\n\t'.join(opts))
    result = run('echo -e "{0}" >> ~/.ssh/config'.format(str))
    if result.failed:
        raise HaltError('The "echo" command failed on the remote host. Permissions issue?')
    message('Appended entry to ssh config; setting permissions.')

    result = run('chmod 0600 ~/.ssh/config')
    if result.failed:
        raise HaltError('Unable to set permissions on file "~/.ssh.config".')
    succeed_msg('Success.')