# 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_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)
    os.makedirs(our_cache_dir, mode=0o775, exist_ok=True)
    return our_cache_dir


def get_log_file_path():

# 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_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)
    os.makedirs(our_cache_dir, mode=0o775, exist_ok=True)
    return our_cache_dir


def get_log_file_path():

    return os.path.join(setup_dirs(), LOG_FILE_NAME)