Mercurial > hgrepos > Python > libs > ConfigMix
comparison docs/introduction.rst @ 400:727ec2fc8e7e
Docs
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 19 Nov 2021 09:28:49 +0100 |
| parents | 44ef854da70a |
| children | e60b72df15de |
comparison
equal
deleted
inserted
replaced
| 399:b45403d175a0 | 400:727ec2fc8e7e |
|---|---|
| 239 (:py:meth:`.Configuration.getintvar_s`, | 239 (:py:meth:`.Configuration.getintvar_s`, |
| 240 :py:meth:`.Configuration.getboolvar_s`) | 240 :py:meth:`.Configuration.getboolvar_s`) |
| 241 | 241 |
| 242 And with :py:meth:`.Configuration.getfirstvar`, | 242 And with :py:meth:`.Configuration.getfirstvar`, |
| 243 :py:meth:`.Configuration.getfirstvar_s`, | 243 :py:meth:`.Configuration.getfirstvar_s`, |
| 244 :py:meth:`.Configuration.getfirstintvar_s`, | 244 :py:meth:`.Configuration.getfirstintvar_s`, |
| 245 :py:meth:`.Configuration.getfirstboolvar_s` and | 245 :py:meth:`.Configuration.getfirstboolvar_s` and |
| 246 :py:meth:`.Configuration.getfirstfloatvar_s` there exist variants that | 246 :py:meth:`.Configuration.getfirstfloatvar_s` there exist variants that |
| 247 accept a *list* of possible variables names and return the first one | 247 accept a *list* of possible variables names and return the first one |
| 248 that is found. | 248 that is found. |
| 249 | 249 |
| 537 | 537 |
| 538 .. note:: Quoting the ``ref`` namespace name does not work currently when | 538 .. note:: Quoting the ``ref`` namespace name does not work currently when |
| 539 used in variable interpolation syntax. | 539 used in variable interpolation syntax. |
| 540 | 540 |
| 541 | 541 |
| 542 .. _jailed-configuration: | |
| 543 | |
| 544 Jailed Configurations | |
| 545 --------------------- | |
| 546 | |
| 547 With :meth:`configmix.config.Configuration.jailed` you get a `jailed` | |
| 548 (or `restricted`) configuration from a "normal" configuration. | |
| 549 | |
| 550 Restriction is two-fold: | |
| 551 | |
| 552 - The access to configuration variables in `config` is restricted | |
| 553 to the configuration sub-tree that is configured in `path`. | |
| 554 | |
| 555 - Not all access-methods of :class:`Configuration` are implemented | |
| 556 yet. | |
| 557 | |
| 558 This is somewhat analogous to a `chroot` environment for filesystems. | |
| 559 | |
| 560 .. note:: The word "jail" is shamelessly stolen from FreeBSD jails. | |
| 561 | |
| 562 Usage example:: | |
| 563 | |
| 564 import configmix | |
| 565 | |
| 566 config = configmix.load("conf10.py") | |
| 567 value = config.getvar_s("tree1.tree2.key4") | |
| 568 | |
| 569 jailed_config1 = config.jailed(rootpath="tree1.tree2") | |
| 570 jvalue1 = jailed_config1.getvar_s("key4") | |
| 571 | |
| 572 jailed_config2 = config.jailed(root=("tree1", "tree2")) | |
| 573 jvalue2 = jailed_config.getvarl_s("key4") | |
| 574 | |
| 575 assert value == jvalue1 == jvalue2 == "get this as `tree1.tree2.key4'" | |
| 576 | |
| 577 `jvalue1` and `jvalue2` (and `value`) yield the very same value | |
| 578 ``get this as `tree1.tree2.key4'`` from the configuration. | |
| 579 | |
| 580 All access methods in a jailed configuration automatically prepend the | |
| 581 given `root path` in order to get the effective key into the base | |
| 582 configuration. | |
| 583 | |
| 584 | |
| 542 Custom filename extensions and custom loaders | 585 Custom filename extensions and custom loaders |
| 543 --------------------------------------------- | 586 --------------------------------------------- |
| 544 | 587 |
| 545 If you want to have custom configuration file extensions and/or custom loaders | 588 If you want to have custom configuration file extensions and/or custom loaders |
| 546 for custom configuration files you have various possibilities: | 589 for custom configuration files you have various possibilities: |
