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
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)
def parser(): yield external_configparser.get_parser()