summaryrefslogtreecommitdiffstats
path: root/base/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'base/util.py')
-rw-r--r--base/util.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/base/util.py b/base/util.py
new file mode 100644
index 0000000..ec0a47b
--- /dev/null
+++ b/base/util.py
@@ -0,0 +1,26 @@
+from __future__ import with_statement
+
+from contextlib import contextmanager
+from os import chdir, getcwd
+from shutil import copyfileobj
+
+from base import log
+
+@contextmanager
+def pwd(dir):
+ old_dir = getcwd()
+ log.debug('changing dir to %s' % dir)
+ chdir(dir)
+ yield
+ log.debug('changing dir to %s' % old_dir)
+ chdir(old_dir)
+
+def copy(src, dst):
+ # we're using copyfileobj so later we can do this from a URL
+ src = file(src, 'rb')
+ dst = file(dst, 'wb')
+ copyfileobj(src, dst)
+ src.close()
+ dst.close()
+
+__all__ = ['pwd', 'copy'] \ No newline at end of file