SwiftBuildSupport: move WorkingDirectory class to the module so that it

is reusable

Swift SVN r24268
This commit is contained in:
Dmitri Hrybenko
2015-01-08 04:47:37 +00:00
parent e889627fb0
commit 5c76bdfd38
2 changed files with 17 additions and 12 deletions

View File

@@ -175,3 +175,20 @@ def get_all_preset_names(preset_file_names):
config = _load_preset_files_impl(preset_file_names)
return [ name[len(_PRESET_PREFIX):] for name in config.sections()
if name.startswith(_PRESET_PREFIX) ]
# A context manager for changing the current working directory.
#
# with WorkingDirectory('/tmp'):
# ... do work in /tmp...
class WorkingDirectory(object):
def __init__(self, new_cwd):
self.new_cwd = new_cwd
def __enter__(self):
self.old_cwd = os.getcwd()
os.chdir(self.new_cwd)
def __exit__(self, type, value, traceback):
os.chdir(self.old_cwd)