Manage settings loaded from confiugrations using dpath.
__init__(self, filepath=None, **kwargs)
special
Initialize single configuration file.
Source code in compendium/loader.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
def __init__(self, filepath: Optional[str] = None, **kwargs: Any) -> None:
'''Initialize single configuration file.'''
self.filepath: Optional[str] = filepath
self.filename: str = kwargs.pop('filename', 'config.toml')
self.filetype: str = kwargs.pop(
'filetype', self.get_filetype(self.filename)
)
self.writable: bool = bool(kwargs.pop('writable', False))
self.autosave: bool = bool(
kwargs.pop('autosave', True if self.writable else False)
)
if 'separator' in kwargs:
self.separator: str = kwargs.pop('separator')
super().__init__(**kwargs)
|
dump(self, filepath=None)
Save settings to configuraiton.
Source code in compendium/loader.py
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
def dump(self, filepath: Optional[str] = None) -> None:
'''Save settings to configuraiton.'''
if self.writable:
filepath = filepath or self.filepath
if filepath:
# Use discovered module to save configuration
logging.info("Saving configuration: '{}'".format(filepath))
Class = self.__get_class(
self.get_filetype(filepath) or self.filetype
)
if Class:
# TODO: refactor to use respective dict from chainmap
c = Class()
c.dump_config(self.data, filepath)
else:
raise exceptions.CompendiumDriverError(
"Skipping: No class found for: '{}'".format(filepath)
)
else:
raise exceptions.CompendiumConfigFileError(
'Error: no config file provided'
)
else:
raise exceptions.CompendiumConfigFileError(
'Error: file is not writable'
)
|
load(self, filepath=None)
Load settings from configuration file.
Source code in compendium/loader.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
def load(self, filepath: Optional[str] = None) -> None:
'''Load settings from configuration file.'''
filepath = filepath or self.filepath
if filepath:
# Use discovered module to load configuration.
if os.path.exists(filepath):
logging.info("Retrieving configuration: '{}'".format(filepath))
Class = self.__get_class(
self.get_filetype(filepath) or self.filetype
)
if Class:
c = Class()
self.update(c.load_config(filepath=filepath))
else:
raise exceptions.CompendiumDriverError(
"Error: No class found for: '{}'".format(filepath)
)
else:
raise exceptions.CompendiumConfigFileError(
"Skipping: No configuration found at: '{}'".format(
filepath
)
)
else:
raise exceptions.CompendiumConfigFileError(
'Error: no config file provided'
)
|
modules()
staticmethod
Lookup modules inheriting FiletypesBase.
Source code in compendium/loader.py
|
@staticmethod
def modules() -> Tuple[Any, ...]:
'''Lookup modules inheriting FiletypesBase.'''
return tuple([m for m in FiletypesBase.__subclasses__()])
|