Skip to content

Toml

Control toml module.

TomlConfig

Manage toml configurations.

__init__(self, **kwargs) special

Initialize toml module.

Source code in compendium/filetypes/toml.py
19
20
21
22
def __init__(self, **kwargs: Any) -> None:
    '''Initialize toml module.'''
    logging.info('Inializing TomlConfig')
    self.encoding = kwargs.get('encoding', 'utf-8')

dump_config(self, content, filepath)

Save settings to toml configuration.

Source code in compendium/filetypes/toml.py
69
70
71
72
73
74
75
76
77
78
79
80
def dump_config(self, content: Dict[str, Any], filepath: str) -> None:
    '''Save settings to toml configuration.'''
    logging.info('TomlConfig: saving configuration file')
    try:
        with open(filepath, 'w') as f:
            f.write(tomlkit.dumps(content))
    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 supported filetypes.

Source code in compendium/filetypes/toml.py
24
25
26
27
@staticmethod
def filetypes() -> Tuple[str, ...]:
    '''Return supported filetypes.'''
    return ('toml', 'tml')

load_config(self, filepath)

Load settings from toml configuration.

Source code in compendium/filetypes/toml.py
59
60
61
62
63
64
65
66
67
def load_config(self, filepath: str) -> Dict[str, Any]:
    '''Load settings from toml configuration.'''
    logging.info('loading TOML configuration file')
    if os.path.isfile(filepath):
        with open(filepath, 'r', encoding=self.encoding) as f:
            content = self._convert(tomlkit.parse(f.read()))
    else:
        content = {}
    return content