# Path: sen/constants.py
# PROJECT_NAME = "sen"
# 
# LOG_FILE_NAME = "sen.debug.log"


import os
import logging
import functools
import traceback
import time
from datetime import datetime
from docker.errors import APIError
from sen.constants import PROJECT_NAME, LOG_FILE_NAME


def log_last_traceback():
    logger.error(traceback.format_exc())


def log_traceback(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        logger.info("function %s is about to be started", func)
        try:
            response = func(*args, **kwargs)
        except Exception:
            log_last_traceback()
        else:
            logger.info("function %s finished", func)
            # TODO: how long it took?
            return response
    return wrapper


def setup_dirs():
    """Make required directories to hold logfile.

    :returns: str
    """
    try:
        top_dir = os.path.abspath(os.path.expanduser(os.environ["XDG_CACHE_HOME"]))
    except KeyError:
        top_dir = os.path.abspath(os.path.expanduser("~/.cache"))

# Path: sen/constants.py
# PROJECT_NAME = "sen"
# 
# LOG_FILE_NAME = "sen.debug.log"


# Path: sen/util.py
import os
import logging
import functools
import traceback
import time
from datetime import datetime
from docker.errors import APIError
from sen.constants import PROJECT_NAME, LOG_FILE_NAME



def log_last_traceback():
    logger.error(traceback.format_exc())


def log_traceback(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        logger.info("function %s is about to be started", func)
        try:
            response = func(*args, **kwargs)
        except Exception:
            log_last_traceback()
        else:
            logger.info("function %s finished", func)
            # TODO: how long it took?
            return response
    return wrapper


def setup_dirs():
    """Make required directories to hold logfile.

    :returns: str
    """
    try:
        top_dir = os.path.abspath(os.path.expanduser(os.environ["XDG_CACHE_HOME"]))
    except KeyError:
        top_dir = os.path.abspath(os.path.expanduser("~/.cache"))

    our_cache_dir = os.path.join(top_dir, PROJECT_NAME)