mesaport.Access.support.utils
1import os 2 3class cwd: 4 """ 5 Directory changer. can change the directory using the 'with' context manager, and returns to the previous path 6 after leaving intendation. Example: 7 8 with cwd("some/path/to/go"): # changing dir 9 foo() 10 ... 11 bar() 12 #back to old dir 13 """ 14 def __init__(self, newPath): 15 self.newPath = os.path.expanduser(newPath) 16 17 def __enter__(self): 18 self.savedPath = os.getcwd() 19 os.chdir(self.newPath) 20 21 def __exit__(self, etype, value, traceback): 22 os.chdir(self.savedPath)
class
cwd:
4class cwd: 5 """ 6 Directory changer. can change the directory using the 'with' context manager, and returns to the previous path 7 after leaving intendation. Example: 8 9 with cwd("some/path/to/go"): # changing dir 10 foo() 11 ... 12 bar() 13 #back to old dir 14 """ 15 def __init__(self, newPath): 16 self.newPath = os.path.expanduser(newPath) 17 18 def __enter__(self): 19 self.savedPath = os.getcwd() 20 os.chdir(self.newPath) 21 22 def __exit__(self, etype, value, traceback): 23 os.chdir(self.savedPath)
Directory changer. can change the directory using the 'with' context manager, and returns to the previous path after leaving intendation. Example:
with cwd("some/path/to/go"): # changing dir foo() ... bar()