linecook.config package¶
Submodules¶
linecook.config.core module¶
-
class
linecook.config.core.LineCookConfig(config_dicts)¶ Bases:
objectConfiguration for
linecookparsed from known configuration files.-
transforms¶ Named transforms available for recipes.
Type: dict
-
recipes¶ Named recipes, which are simply text transforms, or sequences of transforms, that are applied to each line of text.
Type: dict
See
load_configfor a description of known configuration files, and hierarchical configuration works.-
-
linecook.config.core.load_config()¶ Return
LineCookConfigreduced from all known configuration files.The following configuration files are loaded, in order:
linecook.config.core~/.linecook/config.py./.linecook/config.py
Each file should define a dictionary named
LINECOOK_CONFIGcontaining keys such astransformsandrecipes.Files loaded later (lower on the list) override values loaded earlier. Note that the overriding happens at the second level of dictionaries. For example, if
~/.linecook/config.pyis defined as:from linecook.transforms.core import color_text LINECOOK_CONFIG = { 'transforms': { 'warn_color': color_text(' WARN ', color='yellow'), 'error_color': color_text(' ERROR ', on_color='on_red'), }, 'recipes': { 'logs': ['warn_color', 'error_color'], 'default': ['warn_color', 'error_color'], }, }
And then,
./.linecook/config.pyis defined as:from linecook.transforms.core import filter_line LINECOOK_CONFIG = { 'recipes': { 'default': [filter_line(' DEBUG '), 'error_color'] }, }
The loaded result would roughly translate to:
LINECOOK_CONFIG = { 'transforms': { 'warn_color': color_text(' WARN ', color='yellow'), 'error_color': color_text(' ERROR ', on_color='on_red'), }, 'recipes': { 'logs': ['warn_color', 'error_color'], 'default': [filter_line(' DEBUG '), 'error_color'] }, }
You’ll notice that
recipesdoesn’t match therecipesin the second config file: Instead, the second file only overrode the'default'value in the first config file, but preseved the'logs'value.
linecook.config.parsers module¶
-
linecook.config.parsers.collect_recipes(config_dicts, transforms_registry)¶ Return recipe dictionary from a list of configuration dictionaries.
Parameters: - config_dicts (list(dict)) – Unparsed configuration dictionaries. For each dictionary, only use the ‘recipes’ value, which itself is a dictionary, where the keys are recipe names and values are lists of transform functions or transform names.
- transforms_registry (dict) – Dictionary containing named transform
functions. See also
collect_tranforms, which build this registry.
-
linecook.config.parsers.collect_tranforms(config_dicts)¶ Return transform dictionary from a list of configuration dictionaries.
Parameters: config_dicts (list(dict)) – Unparsed configuration dictionaries. For each dictionary, this applies parsers registered with register_transform_parserthat convert configuration data into named transform functions.
-
linecook.config.parsers.get_value_from_each(key, dict_list)¶ Return list of values for
keyin a list of dictionaries.
-
linecook.config.parsers.parse_colorizers(colorizers_dict_seq)¶ Return dictionary of transforms based on
colorizersin config_dict.This converts
colorizersfield in a configuration dict into color transforms. For example, take the following configuration:'colorizers': { 'warn_color': { 'match_pattern': ' WARN ', 'on_color': 'on_yellow', }, },
That configuration is parsed to return the transform:
from linecook.transforms.core import color_text color_text(' WARN ', on_color='on_yellow')
-
linecook.config.parsers.parse_transforms(transforms_dict_seq)¶ Return dictionary of transforms based on
transformsin config_dict.All this really does is merge the transforms defined in multiple configuration dictionaries.
-
linecook.config.parsers.register_transform_parser(config_type)¶ Add parser to registry of known linecook config parsers.
Parameters: config_type (str) – The config type that is parsed by this decorated function The resulting output will be stored in the parsed config under this name. A config parser takes a sequence representing updated the an object containing the parsed data.
You can register the a parser with the same name multiple times, which will simply override older instances.
-
linecook.config.parsers.resolve_recipe(recipe, transforms_registry)¶