# 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 os.path import exists, expanduser, join
from core.conf.logconfig import logger
        source = f.read()
    for line in source.split('\n'):
        if pattern in line:
            return True
    return False


def modify_cooja(cooja_dir):
    """
    This function inserts a block in the IF statement for parsing Cooja's input arguments.
    It searches for the IF statement pattern containing the '-nogui' case and inserts
     an IF block for a new '-hidden' case (aimed to run a simulation with the GUI hidden).

    :param cooja_dir: Cooja's directory
    :return: None
    """
    pattern = 'if (args.length > 0 && args[0].startsWith("-nogui="))'
    cooja_file = join(cooja_dir, 'java', 'org', 'contikios', 'cooja', 'Cooja.java')
    changed = False
    with open(cooja_file) as f:
        source = f.read()
    buffer = []
    for line in source.split('\n'):
        if pattern in line:
            with open('src/Cooja.java.snippet') as f:
                line = line.replace(pattern, '{} else {}'.format(f.read().strip(), pattern))
            changed = True
        buffer.append(line)
    with open(cooja_file, 'w') as f:
        f.write('\n'.join(buffer))

# 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/conf/install.py
from os.path import exists, expanduser, join
from core.conf.logconfig import logger

        source = f.read()
    for line in source.split('\n'):
        if pattern in line:
            return True
    return False


def modify_cooja(cooja_dir):
    """
    This function inserts a block in the IF statement for parsing Cooja's input arguments.
    It searches for the IF statement pattern containing the '-nogui' case and inserts
     an IF block for a new '-hidden' case (aimed to run a simulation with the GUI hidden).

    :param cooja_dir: Cooja's directory
    :return: None
    """
    pattern = 'if (args.length > 0 && args[0].startsWith("-nogui="))'
    cooja_file = join(cooja_dir, 'java', 'org', 'contikios', 'cooja', 'Cooja.java')
    changed = False
    with open(cooja_file) as f:
        source = f.read()
    buffer = []
    for line in source.split('\n'):
        if pattern in line:
            with open('src/Cooja.java.snippet') as f:
                line = line.replace(pattern, '{} else {}'.format(f.read().strip(), pattern))
            changed = True
        buffer.append(line)
    with open(cooja_file, 'w') as f:
        f.write('\n'.join(buffer))

    logger.debug(" > Cooja.java modified" if changed else " > Cooja.java already up-to-date")