| """Utilities for dealing with the operating system.""" |
| from __future__ import absolute_import |
| import contextlib |
| import logging |
| import os |
| |
| @contextlib.contextmanager |
| def change_cwd(path): |
| old_path = os.path.abspath('.') |
| os.chdir(path) |
| logging.debug( |
| "Changed directory from %s to %s", old_path, os.path.abspath('.')) |
| yield |
| os.chdir(old_path) |
| logging.debug("Changed directory back to %s", old_path) |
| |
| |
| def find_files(root, filename): |
| matching_paths = [] |
| for base, _, files in os.walk(root): |
| if filename in files: |
| matching_paths.append(os.path.join(base, filename)) |
| return matching_paths |
| |