示例#1
0
def read(path: str) -> Style:
    """Read style from styles file.

    Args:
        path: Name of the styles file to read
    """
    _logger.debug("Reading style from file '%s'", path)
    parser = external_configparser.get_parser()
    read_log_exception(parser, _logger, path)
    # Retrieve the STYLE section
    try:
        section = parser["STYLE"]
    except KeyError:
        _crash_read(path, "Style files must start with the [STYLE] header")
    # Retrieve base colors
    try:
        colors = [section.pop(f"base{i:02x}") for i in range(16)]
    except KeyError as e:
        _crash_read(path, f"Style is missing requred base color {e}")
    # Create style class with possibly user-defined font
    try:
        style = Style(*colors, font=section.pop("font", DEFAULT_FONT))
    except ValueError as e:
        _crash_read(path, str(e))
    # Override additional options
    for option, value in parser["STYLE"].items():
        _logger.debug("Overriding '%s' with '%s'", option, value)
        try:
            style[option] = value
        except ValueError as e:
            _logger.error(
                "Error parsing style option '%s' = '%s':\n%s", option, value, e
            )
    return style
示例#2
0
def read(path: str) -> None:
    """Read keybindings from path into the keybindings registry."""
    _logger.debug("Reading keybindings from '%s'", path)
    parser = KeyfileParser()
    config.read_log_exception(parser, _logger, path)
    for section in parser.sections():
        try:
            _logger.debug("Reading keybindings from section '%s'", section)
            mode = api.modes.get_by_name(section)
            _read_mode(bindings=parser[section].items(), mode=mode)
        except api.modes.InvalidMode:
            _logger.warning("Ignoring bindings for unknown '%s' mode", section)
    _logger.debug("Read keybindings from '%s'", path)
示例#3
0
def test_sysexit_on_broken_config(mocker, tmp_path, content, message):
    """Ensure SystemExit is correctly raised for various broken config files.

    Args:
        content: Content written to the configuration file which is invalid.
        message: Message printed to help debugging.
    """
    print("Ensuring system exit with", message)
    mock_logger = mocker.Mock()
    parser = configparser.ConfigParser()
    path = tmp_path / "configfile"
    path.write_text(content)
    with pytest.raises(SystemExit, match=str(customtypes.Exit.err_config)):
        config.read_log_exception(parser, mock_logger, str(path))
    mock_logger.critical.assert_called_once()
def read(path: str) -> None:
    """Read config from path into settings."""
    parser = external_configparser.get_parser()
    read_log_exception(parser, _logger, path)
    # Try to update every single setting
    for name, _ in api.settings.items():
        _update_setting(name, parser)
    # Read additional statusbar formatters
    if "STATUSBAR" in parser:
        _add_statusbar_formatters(parser["STATUSBAR"])
    # Read aliases
    if "ALIASES" in parser:
        _add_aliases(parser["ALIASES"])
    # Read plugins
    if "PLUGINS" in parser:
        _read_plugins(parser["PLUGINS"])
    # Read metadata sets
    if "METADATA" in parser:
        _add_metadata(parser["METADATA"])
    _logger.debug("Read configuration from '%s'", path)