@contextmanager
def _make_tmp_dir(ext=None, work_dir=None):
    if not work_dir:
        work_dir = __work_dir()
    if ext:
        work_dir += ext
    use_sudo = False
    if not env.safe_exists(work_dir):
        with settings(warn_only=True):
            # Try to create this directory without using sudo, but
            # if needed fallback.
            result = env.safe_run("mkdir -p '%s'" % work_dir)
            if result.return_code != 0:
                use_sudo = True
        if use_sudo:
            env.safe_sudo("mkdir -p '%s'" % work_dir)
            env.safe_sudo("chown -R %s '%s'" % (env.user, work_dir))
    yield work_dir
    if env.safe_exists(work_dir):
        run_func = env.safe_sudo if use_sudo else env.safe_run
        run_func("rm -rf %s" % work_dir)
Setup a temporary working directory for building custom software. First checks
dataset/ETHPy150Open chapmanb/cloudbiolinux/cloudbio/custom/shared.py/_make_tmp_dir