adds an extend API for the settings
This commit is contained in:
parent
172a33f842
commit
f0ecbf4914
|
@ -10,8 +10,6 @@ Tiramisu is made of almost three main objects :
|
||||||
- :class:`tiramisu.option.OptionDescription` is the shema, the option's structure
|
- :class:`tiramisu.option.OptionDescription` is the shema, the option's structure
|
||||||
- :class:`tiramisu.config.Config` which is the whole configuration entry point
|
- :class:`tiramisu.config.Config` which is the whole configuration entry point
|
||||||
|
|
||||||
.. image:: config.png
|
|
||||||
|
|
||||||
Accessing the `Option`'s
|
Accessing the `Option`'s
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
|
@ -47,9 +45,13 @@ object is returned, and if no `Option` has been declared in the
|
||||||
|
|
||||||
The `Option` objects (in this case the :class:`~tiramisu.option.BoolOption`),
|
The `Option` objects (in this case the :class:`~tiramisu.option.BoolOption`),
|
||||||
are organized into a tree into nested
|
are organized into a tree into nested
|
||||||
:class:`~tiramisu.option.OptionDescription` objects. Every option has a name,
|
:class:`~tiramisu.option.OptionDescription` objects.
|
||||||
as does every option group. The parts of the full name of the option are
|
|
||||||
separated by dots: e.g. ``cfg.optgroup.optname``.
|
.. image:: config.png
|
||||||
|
|
||||||
|
Every option has a name, as does every option group. The parts
|
||||||
|
of the full name of the option are separated by dots: e.g.
|
||||||
|
``cfg.optgroup.optname``.
|
||||||
|
|
||||||
Let's make the protocol of accessing a `Config`'s attribute explicit
|
Let's make the protocol of accessing a `Config`'s attribute explicit
|
||||||
(because explicit is better than implicit):
|
(because explicit is better than implicit):
|
||||||
|
@ -362,6 +364,10 @@ read/write or read only mode::
|
||||||
>>> c.cfgimpl_get_settings().remove('unknown')
|
>>> c.cfgimpl_get_settings().remove('unknown')
|
||||||
>>> print c.od1.var3
|
>>> print c.od1.var3
|
||||||
value
|
value
|
||||||
|
|
||||||
|
Many properties can be defined at the same time on an option::
|
||||||
|
|
||||||
|
>>> c.cfgimpl_get_settings().extend(['unknown1', 'unknown2'])
|
||||||
|
|
||||||
Properties can also be defined on an option group (that is, on an
|
Properties can also be defined on an option group (that is, on an
|
||||||
:term:`option description`) let's hide a group and try to access to it::
|
:term:`option description`) let's hide a group and try to access to it::
|
||||||
|
|
|
@ -260,6 +260,11 @@ class Property(object):
|
||||||
self._properties = prop
|
self._properties = prop
|
||||||
|
|
||||||
def append(self, propname):
|
def append(self, propname):
|
||||||
|
"""Appends a property named propname
|
||||||
|
|
||||||
|
:param propname: a predefined or user defined property name
|
||||||
|
:type propname: string
|
||||||
|
"""
|
||||||
if self._opt is not None and self._opt._calc_properties is not None \
|
if self._opt is not None and self._opt._calc_properties is not None \
|
||||||
and propname in self._opt._calc_properties:
|
and propname in self._opt._calc_properties:
|
||||||
raise ValueError(_('cannot append {0} property for option {1}: '
|
raise ValueError(_('cannot append {0} property for option {1}: '
|
||||||
|
@ -269,12 +274,28 @@ class Property(object):
|
||||||
self._setting._setproperties(self._properties, self._opt, self._path)
|
self._setting._setproperties(self._properties, self._opt, self._path)
|
||||||
|
|
||||||
def remove(self, propname):
|
def remove(self, propname):
|
||||||
|
"""Removes a property named propname
|
||||||
|
|
||||||
|
:param propname: a predefined or user defined property name
|
||||||
|
:type propname: string
|
||||||
|
"""
|
||||||
if propname in self._properties:
|
if propname in self._properties:
|
||||||
self._properties.remove(propname)
|
self._properties.remove(propname)
|
||||||
self._setting._setproperties(self._properties, self._opt,
|
self._setting._setproperties(self._properties, self._opt,
|
||||||
self._path)
|
self._path)
|
||||||
|
def extend(self, propnames):
|
||||||
|
"""Extends properties to the existing properties
|
||||||
|
|
||||||
|
:param propnames: an iterable made of property names
|
||||||
|
:type propnames: iterable of string
|
||||||
|
"""
|
||||||
|
for propname in propname:
|
||||||
|
self.append(propname)
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
|
"""resets the properties (does not **clear** the properties,
|
||||||
|
default properties are still present)
|
||||||
|
"""
|
||||||
self._setting.reset(_path=self._path)
|
self._setting.reset(_path=self._path)
|
||||||
|
|
||||||
def __contains__(self, propname):
|
def __contains__(self, propname):
|
||||||
|
|
Loading…
Reference in New Issue