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']