files.py 446 Bytes
Newer Older
1
import logging
2
3
import os
from contextlib import contextmanager
4

5
6
from numpy.lib.format import open_memmap

7

8
9
10
11
12
@contextmanager
def setdir(path):
    try:
        os.makedirs(path, exist_ok=True)
        cwd = os.getcwd()
13
14
        logging.info("Changing directory to %s" % path)
        logging.info("Previously: %s" % cwd)
15
16
17
        os.chdir(path)
        yield
    finally:
18
        logging.info("Restoring directory to %s" % cwd)
19
        os.chdir(cwd)