Mercurial > hgrepos > Python > libs > ConfigMix
comparison doc/introduction.rst @ 139:c87b0dc54e1d
Allow custom configuration filename extensions and custom loaders that can handle custom configuration file syntax styles
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Fri, 06 Apr 2018 22:28:45 +0200 |
| parents | 2f2e819e8d17 |
| children | fc2bd73f9e98 |
comparison
equal
deleted
inserted
replaced
| 138:b883f4ef1967 | 139:c87b0dc54e1d |
|---|---|
| 154 | 154 |
| 155 # Get a -- possibly interpolated -- variable from within the tree | 155 # Get a -- possibly interpolated -- variable from within the tree |
| 156 value2 = config.getvar_s("tree1.tree2.key4") | 156 value2 = config.getvar_s("tree1.tree2.key4") |
| 157 | 157 |
| 158 | 158 |
| 159 The filenames of the configuration files must have the extensions | 159 By default filenames of the configuration files must have the extensions |
| 160 (case-insensitively): | 160 (case-insensitively): |
| 161 | 161 |
| 162 ``.py`` | 162 ``.py`` |
| 163 for Python configuration files | 163 for Python configuration files |
| 164 | 164 |
| 323 | 323 |
| 324 {{PY::implementation|upper}} | 324 {{PY::implementation|upper}} |
| 325 | 325 |
| 326 expands to something like ``CPYTHON`` when using the standard Python | 326 expands to something like ``CPYTHON`` when using the standard Python |
| 327 interpreter written in C. | 327 interpreter written in C. |
| 328 | |
| 329 | |
| 330 Custom filename extensions and custom loaders | |
| 331 --------------------------------------------- | |
| 332 | |
| 333 If you want to have custom configuration file extensions and/or custom loaders | |
| 334 for custom configuration files you have various possibilities: | |
| 335 | |
| 336 Associate an additional new extension (e.g. ".conf") with an | |
| 337 existing configuration file style (e.g. YAML):: | |
| 338 | |
| 339 configmix.set_loader(".conf", configmix.default_loaders[".yml"]) | |
| 340 | |
| 341 Allow only files with extension ".cfg" in INI-style:: | |
| 342 | |
| 343 configmix.clear_loader() | |
| 344 configmix.set_loader(".cfg", configmix.default_loders[".ini"]) | |
| 345 | |
| 346 Just a new configuration file style:: | |
| 347 | |
| 348 def my_custom_loader(filename): | |
| 349 ... | |
| 350 return some_dict_alike | |
| 351 | |
| 352 configmix.clear_loader() | |
| 353 configmix.set_loader(".my.configuration", my_custom_loader) |
