From d8471caa6b855a41aef8109108627f60f97c8f15 Mon Sep 17 00:00:00 2001 From: "Yaakov M. Nemoy" Date: Sun, 5 Oct 2008 02:13:58 -0400 Subject: Unifying how modules get at information like state, and which dir they work on --- base/util.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 base/util.py (limited to 'base') 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 -- cgit