diff --git a/doc/api.txt b/doc/api.txt index 1498f14..7fb526f 100644 --- a/doc/api.txt +++ b/doc/api.txt @@ -11,4 +11,5 @@ Auto generated library's API tiramisu.value tiramisu.autolib tiramisu.error + tiramisu.storage diff --git a/doc/consistency.txt b/doc/consistency.txt index 4b268ed..9de8748 100644 --- a/doc/consistency.txt +++ b/doc/consistency.txt @@ -57,7 +57,7 @@ A requirement is a list of dictionaries that have fairly this form:: 'transitive':True, 'same_action': True}] Actually a transformation is made to this dictionary during the validation of -this requires at the :class:`~option.Option()`'s init. The dictionairy becomes +this requires at the :class:`~option.Option()`'s init. The dictionary becomes a tuple, wich is passed to the :meth:`~setting.Settings.apply_requires()` method. Take a look at the code to fully understand the exact meaning of the requirements: @@ -103,7 +103,6 @@ hidden any more:: ['hidden'] >>> print c.od1.var1 Traceback (most recent call last): - [...] tiramisu.error.PropertiesOptionError: trying to access to an option named: var1 with properties ['hidden'] >>> c.od1.var2 = u'oui' @@ -123,7 +122,6 @@ document.):: >>> c.od1.var2 = u'non' >>> print c.od2.var4 Traceback (most recent call last): - [...] tiramisu.error.PropertiesOptionError: trying to access to an option named: od2 with properties ['hidden'] >>> c.od1.var2 = u'oui' >>> print c.od2.var4 @@ -144,21 +142,20 @@ Requirements can be accumulated for different or identical properties (inverted or not):: >>> a = UnicodeOption('var3', '', u'value', requires=[{'option':od1.var2, - 'expected':'non', 'action':'hidden'}, {'option':od1.var1, 'expected':'oui', - 'action':'hidden'}]) + ... 'expected':'non', 'action':'hidden'}, {'option':od1.var1, 'expected':'oui', + ... 'action':'hidden'}]) >>> a = UnicodeOption('var3', '', u'value', requires=[{'option':od1.var2, - 'expected':'non', 'action':'hidden'}, {'option':od1.var1, 'excepted':'oui', - 'action':'disabled', 'inverse':True}]) + ... 'expected':'non', 'action':'hidden'}, {'option':od1.var1, 'excepted':'oui', + ... 'action':'disabled', 'inverse':True}]) But it is not possible to have inverted requirements on the same property. Here is an impossible situation:: >>> a = UnicodeOption('var3', '', u'value', requires=[{'option':od1.var2, - 'expected':'non', 'action':'hidden'}, {'option':od1.var1, 'expected':'oui', - 'hidden', True}]) + ... 'expected':'non', 'action':'hidden'}, {'option':od1.var1, 'expected':'oui', + ... 'hidden', True}]) Traceback (most recent call last): - [...] ValueError: inconsistency in action types for option: var3 action: hidden Validation upon a whole configuration object @@ -184,11 +181,8 @@ Let's define validator (wich is a normal python function):: Here is an option wich uses this validator:: >>> var1 = UnicodeOption('var1', '', u'oui', validator=valid_a, validator_args={'letter': 'o'}) - >>> >>> od1 = OptionDescription('od1', '', [var1]) - >>> >>> rootod = OptionDescription('rootod', '', [od1]) - >>> >>> c = Config(rootod) >>> c.read_write() @@ -196,11 +190,10 @@ The validation is applied at the modification time:: >>> c.od1.var1 = u'non' Traceback (most recent call last): - [...] ValueError: invalid value non for option var1 >>> c.od1.var1 = u'oh non' - Il est possible de désactiver la validation : +You can disabled this validation:: >>> c.cfgimpl_get_settings().remove('validator') >>> c.od1.var1 = u'non' diff --git a/doc/index.txt b/doc/index.txt index 21cf692..c073d99 100644 --- a/doc/index.txt +++ b/doc/index.txt @@ -33,6 +33,7 @@ controlling options explanations getting-started config + storage option status consistency diff --git a/doc/storage.png b/doc/storage.png new file mode 100644 index 0000000..9bef2b3 Binary files /dev/null and b/doc/storage.png differ diff --git a/doc/storage.svg b/doc/storage.svg new file mode 100644 index 0000000..d710cbc --- /dev/null +++ b/doc/storage.svg @@ -0,0 +1,265 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + Config + + + + + Values + + + + Settings + + + + + + + + + + + + Storage + + + Option + + + + diff --git a/doc/storage.txt b/doc/storage.txt new file mode 100644 index 0000000..8ff5d93 --- /dev/null +++ b/doc/storage.txt @@ -0,0 +1,52 @@ +Storage +======= + +Config's informations are, by default, volatiles. This means, all values and +settings changes will be lost. + +The storage is the system Tiramisu uses to communicate with various DB. +You can specified a persistent storage. + +.. image:: storage.png + +.. automodule:: tiramisu.storage + +.. automethod:: tiramisu.storage.set_storage + +Dictionary +~~~~~~~~~~ + +.. automodule:: tiramisu.storage.dictionary + +Dictionary settings: + +.. automethod:: tiramisu.storage.dictionary.storage.Setting + +Sqlite3 +~~~~~~~ + +.. automodule:: tiramisu.storage.sqlite3 + +Sqlite3 settings: + +.. automethod:: tiramisu.storage.sqlite3.storage.Setting + +Example +~~~~~~~ + +>>> from tiramisu.option import StrOption, OptionDescription +>>> from tiramisu.config import Config +>>> from tiramisu.storage import set_storage +>>> set_storage('sqlite3', dir_database='/tmp/tiramisu') +>>> s = StrOption('str', '') +>>> o = OptionDescription('od', '', [s]) +>>> c1 = Config(o, persistent=True, session_id='xxxx') +>>> c1.str +>>> c1.str = 'yes' +>>> c1.str +'yes' +>>> del(c1) +>>> c2 = Config(o, persistent=True, session_id='xxxx') +>>> c2.str +'yes' + diff --git a/tiramisu/storage/__init__.py b/tiramisu/storage/__init__.py index 562aad5..147d8a8 100644 --- a/tiramisu/storage/__init__.py +++ b/tiramisu/storage/__init__.py @@ -19,11 +19,9 @@ # the whole pypy projet is under MIT licence # ____________________________________________________________ -"""Storage connections, executions and managements. - -Storage is basic components used to set Config informations in DB. -The primary "entry point" class into this package is the StorageType and it's -public configurator ``set_storage()``. +"""Storage is basic components used to set Config informations in DB. +The primary "entry point" class is the StorageType and it's public +configurator ``set_storage()``. """ @@ -43,6 +41,8 @@ class StorageType(object): def set(self, name): if self.storage_type is not None: + if self.storage_type == name: + return raise ConfigError(_('storage_type is already set, cannot rebind it')) self.storage_type = name diff --git a/tiramisu/storage/dictionary/__init__.py b/tiramisu/storage/dictionary/__init__.py index a53e505..dadce23 100644 --- a/tiramisu/storage/dictionary/__init__.py +++ b/tiramisu/storage/dictionary/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -"default plugin for storage: set it in a simple dictionary" # Copyright (C) 2013 Team tiramisu (see AUTHORS for all contributors) # # This program is free software; you can redistribute it and/or modify @@ -17,8 +16,16 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # ____________________________________________________________ +"""Default plugin for storage. All informations are store in a simple +dictionary in memory. + +You cannot have persistente informations with this kind of storage. + +The advantage of this solution is that you can easily create a Config and +use it. But if something goes wrong, you will lost your modifications. +""" from .value import Values from .setting import Settings -from .storage import Storage, list_sessions, delete_session +from .storage import Setting, Storage, list_sessions, delete_session -__all__ = (Values, Settings, Storage, list_sessions, delete_session) +__all__ = (Setting, Values, Settings, Storage, list_sessions, delete_session) diff --git a/tiramisu/storage/dictionary/storage.py b/tiramisu/storage/dictionary/storage.py index 5442c5d..6e15c1b 100644 --- a/tiramisu/storage/dictionary/storage.py +++ b/tiramisu/storage/dictionary/storage.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -"default plugin for storage: set it in a simple dictionary" # Copyright (C) 2013 Team tiramisu (see AUTHORS for all contributors) # # This program is free software; you can redistribute it and/or modify @@ -22,6 +21,8 @@ from tiramisu.error import ConfigError class Setting(object): + """Dictionary storage has no particular setting. + """ pass diff --git a/tiramisu/storage/sqlite3/__init__.py b/tiramisu/storage/sqlite3/__init__.py index adcdfdc..dc6c14b 100644 --- a/tiramisu/storage/sqlite3/__init__.py +++ b/tiramisu/storage/sqlite3/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -"set storage in sqlite3" # Copyright (C) 2013 Team tiramisu (see AUTHORS for all contributors) # # This program is free software; you can redistribute it and/or modify @@ -17,8 +16,14 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # ____________________________________________________________ +"""Sqlite3 plugin for storage. This storage is not made to be used in productive +environment. It was developing as proof of concept. + +You should not configure differents Configs with same session_id. + +""" from .value import Values from .setting import Settings -from .storage import Storage, list_sessions, delete_session +from .storage import Setting, Storage, list_sessions, delete_session -__all__ = (Values, Settings, Storage, list_sessions, delete_session) +__all__ = (Setting, Values, Settings, Storage, list_sessions, delete_session) diff --git a/tiramisu/storage/sqlite3/storage.py b/tiramisu/storage/sqlite3/storage.py index ed5abd9..2ab8e08 100644 --- a/tiramisu/storage/sqlite3/storage.py +++ b/tiramisu/storage/sqlite3/storage.py @@ -25,6 +25,9 @@ from glob import glob class Setting(object): + """:param extension: database file extension (by default: db) + :param dir_database: root database directory (by default: /tmp) + """ extension = 'db' dir_database = '/tmp'