Index: py/utils/misc.py |
diff --git a/py/utils/misc.py b/py/utils/misc.py |
index a61527e4213813074448ff741df3aec9f73c30bc..80d398e8eb32adeb6dc073c0430b1ba93172248e 100644 |
--- a/py/utils/misc.py |
+++ b/py/utils/misc.py |
@@ -67,14 +67,16 @@ def GetAbsPath(relative_path): |
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 log the directory changes. |
rmistry
2014/06/23 14:08:15
nit: log -> print. log may mean you are using the
borenet
2014/06/23 14:16:40
Done.
|
""" |
self._destination = directory |
self._origin = None |
+ self._verbose = verbose |
def __enter__(self): |
"""Change to the destination directory. |
@@ -82,12 +84,14 @@ class ChDir(object): |
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) |