code: def chdir(new_dir):
      
      cur_dir = os.getcwd()
      _mkdir(new_dir)
      os.chdir(new_dir)
      try:
          yield
      finally:
          os.chdir(cur_dir)
docs: stolen from bcbio.
      Context manager to temporarily change to a new directory.
  
      http://lucentbeing.com/blog/context-managers-and-the-with-statement-in-python/