# 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'):


from copy import deepcopy
from jinja2 import Environment, FileSystemLoader
from math import sqrt
from os import listdir, makedirs, rename
from os.path import basename, dirname, exists, expanduser, isdir, isfile, join, split, splitext
from re import findall, finditer, search, sub, DOTALL, MULTILINE
from six import string_types
from core.common.helpers import *
from core.common.wsngenerator import *
from core.conf.constants import *
from core.conf.logconfig import logger
    from core.common.wsngenerator import __all__
        from core.common.wsngenerator import __all__ as wsn_algos


def list_wsn_gen_algorithms():
    """
    This function gets all WSN generation functions from the WSN generation library.
    """
    return __all__


# ************************************** TEMPLATE AND PARAMETER FUNCTIONS **************************************
def apply_debug_flags(contiki_rpl, debug='NONE'):
    """
    This function replaces debug flags in ContikiRPL files.

    :param contiki_rpl: path to ContikiRPL custom library
    :param debug: the new value to be set for the debug flag
    """
    for filename in DEBUG_FILES:
        replace_in_file(join(contiki_rpl, filename), (r'^#define DEBUG DEBUG_([A-Z]+)$', debug))


def apply_replacements(contiki_rpl, replacements):
    """
    This function replaces lines in specified ContikiRPL files. Each replacement is formatted as follows:
        {"ContikiRPL_filename": ["source_line", "destination_line"]}

    :param contiki_rpl: path to ContikiRPL custom library
    :param replacements: dictionary of replacement entries
    """
    for filename, replacement in replacements.items():

# 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/rpla.py
from copy import deepcopy
from jinja2 import Environment, FileSystemLoader
from math import sqrt
from os import listdir, makedirs, rename
from os.path import basename, dirname, exists, expanduser, isdir, isfile, join, split, splitext
from re import findall, finditer, search, sub, DOTALL, MULTILINE
from six import string_types
from core.common.helpers import *
from core.common.wsngenerator import *
from core.conf.constants import *
from core.conf.logconfig import logger
    from core.common.wsngenerator import __all__
        from core.common.wsngenerator import __all__ as wsn_algos



def list_wsn_gen_algorithms():
    """
    This function gets all WSN generation functions from the WSN generation library.
    """
    return __all__


# ************************************** TEMPLATE AND PARAMETER FUNCTIONS **************************************
def apply_debug_flags(contiki_rpl, debug='NONE'):
    """
    This function replaces debug flags in ContikiRPL files.

    :param contiki_rpl: path to ContikiRPL custom library
    :param debug: the new value to be set for the debug flag
    """
    for filename in DEBUG_FILES:
        replace_in_file(join(contiki_rpl, filename), (r'^#define DEBUG DEBUG_([A-Z]+)$', debug))


def apply_replacements(contiki_rpl, replacements):
    """
    This function replaces lines in specified ContikiRPL files. Each replacement is formatted as follows:
        {"ContikiRPL_filename": ["source_line", "destination_line"]}

    :param contiki_rpl: path to ContikiRPL custom library
    :param replacements: dictionary of replacement entries
    """
    for filename, replacement in replacements.items():

        replace_in_file(join(contiki_rpl, filename), replacement, logger=logger)