summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contexts.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/contexts.py b/contexts.py
index a1ade00..d88abfb 100644
--- a/contexts.py
+++ b/contexts.py
@@ -11,6 +11,7 @@ import sys
if sys.version_info < (2, 5):
raise ImportError("python >= 2.5 is required to import logilab.common.contexts")
+import os
import tempfile
import shutil
@@ -24,4 +25,17 @@ class tempdir(object):
# rmtree in all cases
shutil.rmtree(self.path)
return traceback is None
-
+
+
+class pushd(object):
+ def __init__(self, directory):
+ self.directory = directory
+
+ def __enter__(self):
+ self.cwd = os.getcwd()
+ os.chdir(self.directory)
+ return self.directory
+
+ def __exit__(self, exctype, value, traceback):
+ os.chdir(self.cwd)
+