Context manager to ensure in the cwd directory.

def from_dir(cwd):
    "Context manager to ensure in the cwd directory."
    import os
    curdir = os.getcwd()
    try:
        os.chdir(cwd)
        yield
    finally:
        os.chdir(curdir)