mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
SwiftBuildSupport: move WorkingDirectory class to the module so that it
is reusable Swift SVN r24268
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user