You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
755 B
Python

from contextlib import contextmanager
import functools
import logging
import os
import tempfile
def get_logger():
logger = logging.getLogger(__name__)
lvl = os.environ.get("PY_LOG_LVL", "info").upper()
handler = logging.StreamHandler()
formatter = logging.Formatter(logging.BASIC_FORMAT)
handler.setFormatter(formatter)
logger.addHandler(handler)
handler.setLevel(lvl)
logger.setLevel(lvl)
return logger
logger = get_logger()
@contextmanager
def working_dir(directory):
original_working_dir = os.getcwd()
try:
os.chdir(directory)
yield directory
finally:
os.chdir(original_working_dir)
def make_tempdir(identifier):
return tempfile.mkdtemp(prefix="{}_".format(identifier))