code: def cd_ctx(directory):
      
      prevdir = os.path.abspath(os.curdir)
      if os.path.isdir(directory):
          os.chdir(directory)
      yield
      os.chdir(prevdir)
docs: Context manager. Stores current dir, then changes to given directory.
      At the end it changes back.
      :param directory:
      :return: