Context manager to create and remove a transactional temporary directory.

    Handles creating a transactional directory for running commands in. Will
    use either the current directory or /tmp/bcbiotx.

    Creates an intermediary location and time specific directory for global
    temporary directories to prevent collisions.

    data can be the full world information object being process or a
    configuration dictionary.

def tx_tmpdir(data=None, base_dir=None, remove=True):
    """Context manager to create and remove a transactional temporary directory.

    Handles creating a transactional directory for running commands in. Will
    use either the current directory or /tmp/bcbiotx.

    Creates an intermediary location and time specific directory for global
    temporary directories to prevent collisions.

    data can be the full world information object being process or a
    configuration dictionary.
    """
    base_dir = base_dir or os.getcwd()
    tmpdir_base = utils.get_abspath(_get_base_tmpdir(data, base_dir))
    utils.safe_makedir(tmpdir_base)
    tmp_dir = tempfile.mkdtemp(dir=tmpdir_base)
    #logger.debug("Created tmp dir %s " % tmp_dir)
    try:
        yield tmp_dir
    finally:
        if remove:
            utils.remove_safe(tmp_dir)