diff options
| author | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2008-10-05 02:13:58 -0400 |
|---|---|---|
| committer | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2008-10-05 02:13:58 -0400 |
| commit | d8471caa6b855a41aef8109108627f60f97c8f15 (patch) | |
| tree | b2ea700594a48370011f959d5bb789b6e8aba45c /base | |
| parent | 0abf50482d83242e4c94545ffb2e66d3ff8ab6cc (diff) | |
| download | fedora-devshell-d8471caa6b855a41aef8109108627f60f97c8f15.tar.gz fedora-devshell-d8471caa6b855a41aef8109108627f60f97c8f15.tar.xz fedora-devshell-d8471caa6b855a41aef8109108627f60f97c8f15.zip | |
Unifying how modules get at information like state, and which dir they work on
Diffstat (limited to 'base')
| -rw-r--r-- | base/util.py | 26 |
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 |
