2012-07-13 09:40:48 +02:00
|
|
|
.. default-role:: literal
|
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
Local statuses and global setting
|
|
|
|
=====================================
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2012-10-05 16:00:07 +02:00
|
|
|
Available configuration statuses
|
2012-07-13 09:40:48 +02:00
|
|
|
----------------------------------
|
|
|
|
|
2013-08-20 16:38:06 +02:00
|
|
|
.. currentmodule:: tiramisu
|
|
|
|
|
|
|
|
The configuration's status lives in an :class:`setting.Setting()` object.
|
2012-11-19 16:48:47 +01:00
|
|
|
This configuration status corresponds to specific attributes or bunch of
|
2012-11-20 17:14:58 +01:00
|
|
|
attributes that can be accessed together with some `setting.Setting`
|
2012-11-19 16:48:47 +01:00
|
|
|
method:
|
2012-07-13 09:40:48 +02:00
|
|
|
|
|
|
|
**read write status**
|
|
|
|
|
|
|
|
The configuration can be accessed by `__get__` and `__set__`
|
|
|
|
properties, except for the `hidden` configuration options but, yes, it is
|
|
|
|
possible to modify a disabled option.
|
|
|
|
|
2013-08-20 17:30:24 +02:00
|
|
|
To enable read-write status, call
|
|
|
|
:class:`~config.CommonConfig.read_write()` on the config.
|
2012-10-05 16:00:07 +02:00
|
|
|
|
2012-07-13 09:40:48 +02:00
|
|
|
**read only status**
|
|
|
|
|
2012-10-05 16:00:07 +02:00
|
|
|
The whole configuration is `frozen`, that is modifiying a value is
|
|
|
|
forbidden. We can access to a configuration option only with the
|
2012-07-13 09:40:48 +02:00
|
|
|
`__getattr__` property.
|
2012-10-05 16:00:07 +02:00
|
|
|
|
2012-07-13 09:40:48 +02:00
|
|
|
The configuration has not an access to the hidden options
|
2012-10-05 16:00:07 +02:00
|
|
|
but can read the disabled options.
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-08-20 17:30:24 +02:00
|
|
|
To enable read only status, call :class:`~config.SubConfig.read_only()` on
|
|
|
|
the config.
|
2012-07-13 09:40:48 +02:00
|
|
|
|
|
|
|
.. csv-table:: **Configuration's statuses summary**
|
|
|
|
:header: " ", "Hidden", "Disabled", "Mandatory"
|
|
|
|
|
|
|
|
"read only status", `False`, `True`, `True`
|
|
|
|
"read-write status", `True`, `False`, `False`
|
|
|
|
|
2012-08-13 16:06:02 +02:00
|
|
|
.. _`frozenconfig`:
|
|
|
|
|
2012-07-13 09:40:48 +02:00
|
|
|
Freezing a configuration
|
|
|
|
---------------------------
|
|
|
|
|
2013-08-20 16:38:06 +02:00
|
|
|
.. todo:: freeze at configuration level
|
|
|
|
|
2012-11-20 17:14:58 +01:00
|
|
|
At the configuration level, `setting.Setting.freeze` freezes
|
2012-08-13 16:06:02 +02:00
|
|
|
the whole configuration options.
|
|
|
|
|
2012-10-05 16:00:07 +02:00
|
|
|
.. _`frozen`:
|
2012-08-13 16:06:02 +02:00
|
|
|
|
2013-08-20 16:38:06 +02:00
|
|
|
It is possible to *freeze* a single :class:`option.Option()` object with
|
|
|
|
:meth:`config.SubConfig.cfgimpl_get_settings()`. If you try to modify a frozen
|
|
|
|
:option, it raises a `TypeError: trying to change a frozen option object`.
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-08-20 16:38:06 +02:00
|
|
|
To find out if an option `myoption` is frozen, just make an assertion on the
|
|
|
|
settings like that::
|
|
|
|
|
|
|
|
'frozen' in cfg.cfgimpl_get_settings()[myoption]
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-08-20 16:38:06 +02:00
|
|
|
Moreover, frozen option can return their default values if
|
|
|
|
`option.Option.force_default()` is called on this option.
|
2012-07-13 09:40:48 +02:00
|
|
|
|
|
|
|
Restricted access to an `Option()`
|
|
|
|
-----------------------------------
|
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
.. currentmodule:: tiramisu.setting
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
.. autoclass:: Property
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
The `properties` attribute is in charge of the access rules' option's value.
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
Configuration options access statuses are defined at configuration level
|
|
|
|
that corresponds to the `option.Option()`'s `properties` attribute,
|
|
|
|
for example: hidden, disabled.
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
Use the pythonic way to know if a property is there::
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
'hidden' in c.cfgimpl_get_settings()
|
|
|
|
'frozen' in c.cfgimpl_get_settings()[opt]
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
To access to the global settings::
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
cfg.cfgimpl_get_settings()
|
|
|
|
cfg.cfgimpl_get_settings()[option1]
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
to add, or suppress a global property::
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
cfg.cfgimpl_get_settings()[option1].append('hidden')
|
|
|
|
cfg.cfgimpl_get_settings()[option1].remove('hidden')
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
to activate, deactivate properties::
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
cfg.cfgimpl_get_settings().append('hidden')
|
|
|
|
cfg.cfgimpl_get_settings().remove('hidden')
|
2012-07-13 09:40:48 +02:00
|
|
|
|
|
|
|
Value owners
|
|
|
|
-------------
|
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
|
2013-08-20 16:38:06 +02:00
|
|
|
Every configuration option has a **owner**. When the option is instanciated,
|
|
|
|
the owner is :obj:`setting.owners.default` because a default value has been set
|
|
|
|
(including `None`, wich means that no value has been set yet).
|
2013-05-21 18:42:56 +02:00
|
|
|
|
2013-08-20 16:38:06 +02:00
|
|
|
.. method:: config.CommonConfig.getowner()
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-08-20 16:38:06 +02:00
|
|
|
This method can retrieve an Option's owner.
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-08-20 16:38:06 +02:00
|
|
|
- At the instance of the `Config` object, the value owner is
|
|
|
|
:obj:`setting.owners.default` because
|
|
|
|
the default values are set at the instance of the configuration option
|
|
|
|
object,
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2013-08-20 16:38:06 +02:00
|
|
|
- at the modification of an option, the owner is `owners.default`, (which is
|
|
|
|
:obj:`owners.user`)
|
|
|
|
|
2012-08-14 11:12:30 +02:00
|
|
|
Special behaviors for an option
|
|
|
|
---------------------------------
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2012-10-05 16:00:07 +02:00
|
|
|
**mandatory**
|
|
|
|
|
|
|
|
A mandatory option shall return a value. If a value, or a default value
|
|
|
|
has not been set, a error is raised.
|
|
|
|
|
|
|
|
**has a callback**
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2012-10-05 16:00:07 +02:00
|
|
|
This means that it is a calculated value and therefore automatically
|
2012-08-14 11:12:30 +02:00
|
|
|
protected it cannot be modified by attribute access.
|
2012-10-05 16:00:07 +02:00
|
|
|
|
2013-05-21 18:42:56 +02:00
|
|
|
**force_store_value**
|
2012-07-13 09:40:48 +02:00
|
|
|
|
|
|
|
if the configuration option has a default value, the default is
|
2012-08-14 11:12:30 +02:00
|
|
|
returned, otherwise the value is calculated.
|
|
|
|
|
2012-11-20 17:14:58 +01:00
|
|
|
Its inner state is represented by `option.Option.force_default()`
|
2012-07-13 09:40:48 +02:00
|
|
|
|
2012-10-05 16:00:07 +02:00
|
|
|
Configuration options have default values that are stored in the
|
|
|
|
`Option()` object itself. Default values, the `default`, can be set in
|
2012-07-13 09:40:48 +02:00
|
|
|
various ways.
|
|
|
|
|
2012-10-05 16:00:07 +02:00
|
|
|
If a default value is modified by overriding it, not only the value of
|
|
|
|
the option resets to the default that is proposed, but the owner is
|
2013-05-21 18:42:56 +02:00
|
|
|
modified too, it is reseted to `owners.default`.
|