Skip to content

Yaml

Control YAML configuration module.

YamlConfig

Manage YAML configuration files.

__init__(self, **kwargs) special

Initialize YAML configuration module.

Source code in compendium/filetypes/yaml.py
26
27
28
29
30
def __init__(self, **kwargs: Any) -> None:
    '''Initialize YAML configuration module.'''
    logging.info('Inializing YamlConfig')
    self.encoding = kwargs.get('encoding', 'utf-8')
    self.kind = kwargs.get('kind', None)

dump_config(self, content, filepath)

Save settings to YAML configuration.

Source code in compendium/filetypes/yaml.py
57
58
59
60
61
62
63
64
65
66
67
68
def dump_config(self, content: Dict[str, Any], filepath: str) -> None:
    '''Save settings to YAML configuration.'''
    try:
        with open(filepath, 'w') as f:
            yaml = self.__yaml_parser(self.kind or 'rt')
            yaml.dump(content, f)
    except IOError as err:
        if err.errno == errno.EACCES:
            logging.error(
                'You do not have permission to write to this file'
            )
            raise

filetypes() staticmethod

Return support YAML filetypes.

Source code in compendium/filetypes/yaml.py
39
40
41
42
@staticmethod
def filetypes() -> Tuple[str, ...]:
    '''Return support YAML filetypes.'''
    return ('yaml', 'yml')

load_config(self, filepath)

Load settings from YAML configuration.

Source code in compendium/filetypes/yaml.py
44
45
46
47
48
49
50
51
52
53
54
55
def load_config(self, filepath: str) -> Dict[str, Any]:
    '''Load settings from YAML configuration.'''
    logging.info(
        "loading YAML configuration file {}".format(filepath)
    )
    if os.path.isfile(filepath):
        with open(filepath, 'r', encoding=self.encoding) as f:
            yaml = self.__yaml_parser(self.kind or 'safe')
            content = yaml.load(f)
    else:
        content = {}
    return content