# Path: core/conf/logconfig.py
# LOG_FORMAT = '%(asctime)s %(name)s[%(process)d] %(levelname)s %(message)s'
# LOG_LEVELS = {
#     'info': logging.INFO,
#     'warning': logging.WARNING,
#     'error': logging.ERROR,
#     'debug': logging.DEBUG,
# }
# HIDDEN_ALL = ['warnings', 'stdout', 'stderr', 'running']
# HIDDEN_KEEP_STDERR = ['warnings', 'stdout', 'running']
# def set_logging(lvl='info'):


import ast
from os.path import join
from six import string_types
from core.conf.logconfig import logger
def read_config(path, sep=' = '):
    """
    This helper function reads a simple configuration file with the following format:

     max_range = 50.0
     repeat    = 1
     blocks    = []
     goal      = ""
     ...

    :param path: path to the configuration file
    :param sep: separator between the key and the value
    :return: dictionary with the whole configuration
    """
    config = {}
    try:
        with open(join(path, 'simulation.conf')) as f:
            for line in f.readlines():
                if line.strip().startswith('#'):
                    continue
                try:
                    k, v = [x.strip() for x in line.split(sep)]
                except ValueError:
                    continue
                try:
                    v = ast.literal_eval(v)
                except ValueError:
                    pass
                config[k] = v
    except OSError:

# Path: core/conf/logconfig.py
# LOG_FORMAT = '%(asctime)s %(name)s[%(process)d] %(levelname)s %(message)s'
# LOG_LEVELS = {
#     'info': logging.INFO,
#     'warning': logging.WARNING,
#     'error': logging.ERROR,
#     'debug': logging.DEBUG,
# }
# HIDDEN_ALL = ['warnings', 'stdout', 'stderr', 'running']
# HIDDEN_KEEP_STDERR = ['warnings', 'stdout', 'running']
# def set_logging(lvl='info'):


# Path: core/utils/helpers.py
import ast
from os.path import join
from six import string_types
from core.conf.logconfig import logger

def read_config(path, sep=' = '):
    """
    This helper function reads a simple configuration file with the following format:

     max_range = 50.0
     repeat    = 1
     blocks    = []
     goal      = ""
     ...

    :param path: path to the configuration file
    :param sep: separator between the key and the value
    :return: dictionary with the whole configuration
    """
    config = {}
    try:
        with open(join(path, 'simulation.conf')) as f:
            for line in f.readlines():
                if line.strip().startswith('#'):
                    continue
                try:
                    k, v = [x.strip() for x in line.split(sep)]
                except ValueError:
                    continue
                try:
                    v = ast.literal_eval(v)
                except ValueError:
                    pass
                config[k] = v
    except OSError:

        logger.error("Configuration file 'simulation.conf' does not exist !")