# 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
    cooja_user_properties = join(expanduser('~'), '.cooja.user.properties')
    # if it does not exist, create it from 'src' folder's template
    if not exists(cooja_user_properties):
        with open('src/cooja-user-properties') as tf:
            with open(cooja_user_properties, 'w') as nf:
                nf.write(tf.read())
        logger.debug(" > Cooja user properties created")
        return
    # if it exists, append plugin's reference inside
    with open(cooja_user_properties) as f:
        source = f.read()
    buffer, plugin_appended = [], False
    for line in source.split('\n'):
        if line.startswith('DEFAULT_PROJECTDIRS='):
            if '[APPS_DIR]/visualizer_screenshot' in line:
                return
            else:
                plugin_appended = True
                line += ';[APPS_DIR]/visualizer_screenshot'
        buffer.append(line)
    # if the line with the correct constant name was not found, create it from 'src' folder's template
    if not plugin_appended:
        with open('src/cooja-user-properties') as f:
            for line in f.readlines():
                if 'DEFAULT_PROJECTDIRS=' in line:
                    buffer.append(line)
                    break
    # then write the modified .cooja.user.properties
    with open(cooja_user_properties, '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

    cooja_user_properties = join(expanduser('~'), '.cooja.user.properties')
    # if it does not exist, create it from 'src' folder's template
    if not exists(cooja_user_properties):
        with open('src/cooja-user-properties') as tf:
            with open(cooja_user_properties, 'w') as nf:
                nf.write(tf.read())
        logger.debug(" > Cooja user properties created")
        return
    # if it exists, append plugin's reference inside
    with open(cooja_user_properties) as f:
        source = f.read()
    buffer, plugin_appended = [], False
    for line in source.split('\n'):
        if line.startswith('DEFAULT_PROJECTDIRS='):
            if '[APPS_DIR]/visualizer_screenshot' in line:
                return
            else:
                plugin_appended = True
                line += ';[APPS_DIR]/visualizer_screenshot'
        buffer.append(line)
    # if the line with the correct constant name was not found, create it from 'src' folder's template
    if not plugin_appended:
        with open('src/cooja-user-properties') as f:
            for line in f.readlines():
                if 'DEFAULT_PROJECTDIRS=' in line:
                    buffer.append(line)
                    break
    # then write the modified .cooja.user.properties
    with open(cooja_user_properties, 'w') as f:
        f.write('\n'.join(buffer))

    logger.debug(" > Cooja user properties modified")