@contextlib.contextmanager<EOL>def pushd(path, mkdir=True, cleanup=False):
cwd = os.getcwd()<EOL>exists = osp.exists(path)<EOL>if mkdir and not exists:<EOL><INDENT>os.makedirs(path)<EOL><DEDENT>os.chdir(path)<EOL>try:<EOL><INDENT>yield path<EOL><DEDENT>finally:<EOL><INDENT>os.chdir(cwd)<EOL>if not exists and cleanup:<EOL><INDENT>shutil.rmtree(path)<EOL><DEDENT><DEDENT>
Change current working directory in a with-context
    :param mkdir: If True, then directory is created if it does not exist
    :param cleanup: If True and no pre-existing directory, the directory is
    cleaned up at the end