Add verbose option to misc.ChDir BUG=skia: R=rmistry@google.com Review URL: https://codereview.chromium.org/349973004
diff --git a/py/utils/misc.py b/py/utils/misc.py index a61527e..a1bec6a 100644 --- a/py/utils/misc.py +++ b/py/utils/misc.py
@@ -67,14 +67,16 @@ class ChDir(object): """Enter and exit the given directory appropriately.""" - def __init__(self, directory): + def __init__(self, directory, verbose=True): """Instantiate the ChDir. Args: directory: string; the directory to enter. + verbose: bool; whether or not to print the directory changes. """ self._destination = directory self._origin = None + self._verbose = verbose def __enter__(self): """Change to the destination directory. @@ -82,12 +84,14 @@ Does not check whether the directory exists. """ self._origin = os.getcwd() - print 'chdir %s' % self._destination + if self._verbose: + print 'chdir %s' % self._destination os.chdir(self._destination) def __exit__(self, *args): """Change back to the original directory.""" - print 'chdir %s' % self._origin + if self._verbose: + print 'chdir %s' % self._origin os.chdir(self._origin)