def temporary_dir(delete=True, dir=None,
                  prefix='elasticluster.', suffix='.d'):
    """
    Make a temporary directory and make it current for the code in this context.

    Delete temporary directory upon exit from the context, unless
    ``delete=False`` is passed in the arguments.

    Arguments *suffix*, *prefix* and *dir* are exactly as in
    :func:`tempfile.mkdtemp()` (but have different defaults).
    """
    cwd = os.getcwd()
    tmpdir = tempfile.mkdtemp(suffix, prefix, dir)
    os.chdir(tmpdir)
    yield
    os.chdir(cwd)
    if delete:
        shutil.rmtree(tmpdir, ignore_errors=True)
Make a temporary directory and make it current for the code in this context.

    Delete temporary directory upon exit from the context, unless
    ``delete=False`` is passed in the arguments.

    Arguments *suffix*, *prefix* and *dir* are exactly as in
    :func:`tempfile.mkdtemp()` (but have different defaults).