Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2145)

Unified Diff: py/utils/misc.py

Issue 349973004: Add verbose option to misc.ChDir (Closed) Base URL: https://skia.googlesource.com/common.git@master
Patch Set: log -> print Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: py/utils/misc.py
diff --git a/py/utils/misc.py b/py/utils/misc.py
index a61527e4213813074448ff741df3aec9f73c30bc..a1bec6a17f1bf8a31cc7e0e5a0f582b3f12b99a1 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 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 @@ 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)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698