def teardown_tempdir(dir):
    r'''
    Cleanup temporary directory.
    '''

    if ssh_conn:
        delete_tree(dir)

    assert_valid_dir(dir)
    shutil.rmtree(dir)
r'''
    Cleanup temporary directory.