Example #1
0
def init(ctx, project_root, override, mkdir, level, formatter, log_path):
    """
    Entry point.

    Command to set up a logme config file with master logger configuration

    """
    conf_content = get_color_tpl()
    master_logging_config = get_tpl('logme',
                                    level=level,
                                    formatter=formatter,
                                    filename=log_path)
    conf_content.update(master_logging_config)

    config = ConfigParser.from_dict(conf_content)

    abs_path = Path(project_root).resolve()
    conf_location = abs_path.joinpath('logme.ini')

    if not abs_path.exists():
        if not mkdir:
            raise NotADirectoryError(
                f"{abs_path.parent.resolve() / project_root} does not exist. If you'd "
                f"like to make the directory, please use '-mk' flag.")
        else:
            abs_path.mkdir(parents=True, exist_ok=True)

    if conf_location.exists() and not override:
        raise LogmeError(f"logme.ini already exists at {conf_location}")

    with conf_location.open('w') as conf:
        config.write(conf)
Example #2
0
def test_color_config_none_exist(tmpdir):
    """
    Ensure color config returns None if none existent
    """
    logme_file = tmpdir.join('logme.ini')

    logger_conifg = get_logger_config(__file__)
    config_dict = {'logme': logger_conifg}

    config = ConfigParser.from_dict(config_dict)

    with open(logme_file, 'w') as file:
        config.write(file)

    color_config = get_color_config(logme_file)

    assert color_config is None
Example #3
0
def add(ctx, project_root, name, level, formatter, log_path):
    """
    Command for adding a logger configuration in a logme.ini file. Assuming logme.ini exists
    """
    with ensure_conf_exist(project_root) as logme_conf:

        # check if section already exist
        validate_conf(name, logme_conf)

        conf_content = get_tpl(name,
                               level=level,
                               formatter=formatter,
                               filename=log_path)
        config = ConfigParser.from_dict(conf_content)

        with logme_conf.open('a') as conf:
            config.write(conf)
Example #4
0
def upgrade_to_latest(config_path: Union[str, Path]):
    """
    upgrade the existing logme.ini file to latest version
    *Will write to existing file*

    :param config_path: logme.ini file
    """
    # config = read_config(config_path)
    config_dict = ConfigParser.from_files(config_path).to_dict()

    config_dict_updated = {}

    _upgrade_with_color_config(config_dict, config_dict_updated)

    for k, v in config_dict.items():
        if k not in NONLOGGER_CONFIGS:
            updated = _upgrade_logging_config_section(v)

            config_dict_updated[k] = updated

    new_conf = ConfigParser.from_dict(config_dict_updated)

    with open(config_path, 'w') as file:
        new_conf.write(file)
Example #5
0
    def test_init_from_dict(self):
        config = ConfigParser.from_dict(data.config_dict)

        assert set(config.sections()) == {
            'my_config', 'Fish_Profiles', 'date_format'
        }