def _remote_fetch(env, url, out_file=None, allow_fail=False, fix_fn=None, samedir=False):
    """Retrieve url using wget, performing download in a temporary directory.

    Provides a central location to handle retrieval issues and avoid
    using interrupted downloads.
    """
    if out_file is None:
        out_file = os.path.basename(url)
    if not env.safe_exists(out_file):
        if samedir and os.path.isabs(out_file):
            orig_dir = os.path.dirname(out_file)
            out_file = os.path.basename(out_file)
        else:
            orig_dir = env.safe_run_output("pwd").strip()
        temp_ext = "/%s" % uuid.uuid3(uuid.NAMESPACE_URL,
                                      str("file://%s/%s/%s" %
                                          (env.host, socket.gethostname(), out_file)))
        with _make_tmp_dir(ext=temp_ext, work_dir=orig_dir if samedir else None) as tmp_dir:
            with cd(tmp_dir):
                with warn_only():
                    result = env.safe_run("wget --continue --no-check-certificate -O %s '%s'" % (out_file, url))
                if result.succeeded:
                    if fix_fn:
                        out_file = fix_fn(env, out_file)
                    env.safe_run("mv %s %s" % (out_file, orig_dir))
                elif allow_fail:
                    out_file = None
                else:
                    raise IOError("Failure to retrieve remote file")
        if samedir and out_file:
            out_file = os.path.join(orig_dir, out_file)
    return out_file
dataset/ETHPy150Open chapmanb/cloudbiolinux/cloudbio/custom/shared.py/_remote_fetch/original