Example #1
0
def upload(hostname, local_path, remote_path, mode=None, owner="",
           group="", ignore_failure=False, password=None):
    """
    Upload a file.
    """
    LOG.debug(_("uploading {path} -> {host}:{target}").format(
        host=hostname, path=local_path, target=remote_path))
    env.host_string = hostname
    env.password = password
    temp_filename = ".bundlewrap_tmp_" + randstr()

    fabric_result = _fabric_put(
        local_path=local_path,
        remote_path=temp_filename,
        mirror_local_mode=False,
        mode=S_IRUSR | S_IWUSR,
    )
    if not ignore_failure and fabric_result.failed:
        raise RemoteException(_(
            "upload to {host} failed for: {failed}").format(
                failed=", ".join(fabric_result.failed),
                host=hostname,
            )
        )

    if owner or group:
        if group:
            group = ":" + quote(group)
        run(
            hostname,
            "chown {}{} {}".format(
                quote(owner),
                group,
                quote(temp_filename),
            ),
            password=password,
        )

    if mode:
        run(
            hostname,
            "chmod {} {}".format(
                mode,
                quote(temp_filename),
            ),
            password=password,
        )

    run(
        hostname,
        "mv -f {} {}".format(
            quote(temp_filename),
            quote(remote_path),
        ),
        password=password,
    )
Example #2
0
def upload(hostname, local_path, remote_path):
    """
    Upload a file.
    """
    env.host_string = hostname
    return _fabric_put(
        local_path=local_path,
        remote_path=remote_path,
        use_sudo=True,
        mirror_local_mode=False,
        mode=S_IRUSR | S_IWUSR,
    )