start works on storage
This commit is contained in:
parent
194c82faad
commit
299e51e806
5 changed files with 44 additions and 21 deletions
|
@ -19,9 +19,9 @@ def test_list():
|
|||
o = OptionDescription('od', '', [b])
|
||||
c = Config(o, session_id='test_non_persistent')
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
assert 'test_non_persistent' in list_sessions()
|
||||
assert 'test_non_persistent' in list_sessions('config')
|
||||
del(c)
|
||||
assert 'test_non_persistent' not in list_sessions()
|
||||
assert 'test_non_persistent' not in list_sessions('config')
|
||||
|
||||
|
||||
def test_create_persistent():
|
||||
|
@ -43,7 +43,7 @@ def test_list_sessions_persistent():
|
|||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
assert 'test_persistent' in list_sessions()
|
||||
assert 'test_persistent' in list_sessions('config')
|
||||
|
||||
|
||||
def test_delete_session_persistent():
|
||||
|
@ -55,9 +55,9 @@ def test_delete_session_persistent():
|
|||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
assert 'test_persistent' in list_sessions()
|
||||
assert 'test_persistent' in list_sessions('config')
|
||||
delete_session('test_persistent')
|
||||
assert 'test_persistent' not in list_sessions()
|
||||
assert 'test_persistent' not in list_sessions('config')
|
||||
|
||||
|
||||
def test_create_persistent_retrieve():
|
||||
|
@ -77,7 +77,7 @@ def test_create_persistent_retrieve():
|
|||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
assert c.b is True
|
||||
assert 'test_persistent' in list_sessions()
|
||||
assert 'test_persistent' in list_sessions('config')
|
||||
delete_session('test_persistent')
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
|
|
|
@ -545,11 +545,11 @@ class _CommonConfig(SubConfig):
|
|||
for key, value in state.items():
|
||||
if key not in ['_storage', '_impl_setting']:
|
||||
setattr(self, key, value)
|
||||
set_storage(**state['_impl_setting'])
|
||||
set_storage('config', **state['_impl_setting'])
|
||||
self._impl_context = weakref.ref(self)
|
||||
self._impl_settings.context = weakref.ref(self)
|
||||
self._impl_values.context = weakref.ref(self)
|
||||
storage = get_storage(test=self._impl_test, **state['_storage'])
|
||||
storage = get_storage('config', test=self._impl_test, **state['_storage'])
|
||||
self._impl_values._impl_setstate(storage)
|
||||
self._impl_settings._impl_setstate(storage)
|
||||
self._impl_meta = None
|
||||
|
|
|
@ -31,10 +31,13 @@ from tiramisu.error import ConfigError, ConflictError, ValueWarning
|
|||
from tiramisu.setting import groups, multitypes
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu.autolib import carry_out_calculation
|
||||
from tiramisu.storage import get_storages_option
|
||||
|
||||
#FIXME : need storage...
|
||||
from tiramisu.storage.dictionary.option import StorageBase, StorageOptionDescription
|
||||
#from tiramisu.storage.dictionary.option import StorageBase, StorageOptionDescription
|
||||
#from tiramisu.storage.sqlalchemy.option import StorageBase, StorageOptionDescription
|
||||
StorageBase, StorageOptionDescription = get_storages_option()
|
||||
|
||||
|
||||
name_regexp = re.compile(r'^\d+')
|
||||
forbidden_names = ('iter_all', 'iter_group', 'find', 'find_first',
|
||||
|
|
|
@ -55,9 +55,8 @@ class StorageType(object):
|
|||
def get(self):
|
||||
if self.storage_type is None:
|
||||
self.storage_type = self.default_storage
|
||||
storage = self.storage_type
|
||||
if self.mod is None:
|
||||
modulepath = 'tiramisu.storage.{0}'.format(storage)
|
||||
modulepath = 'tiramisu.storage.{0}'.format(self.storage_type)
|
||||
mod = __import__(modulepath)
|
||||
for token in modulepath.split(".")[1:]:
|
||||
mod = getattr(mod, token)
|
||||
|
@ -66,9 +65,10 @@ class StorageType(object):
|
|||
|
||||
|
||||
storage_type = StorageType()
|
||||
storage_option_type = StorageType()
|
||||
|
||||
|
||||
def set_storage(name, **kwargs):
|
||||
def set_storage(type_, name, **kwargs):
|
||||
"""Change storage's configuration
|
||||
|
||||
:params name: is the storage name. If storage is already set, cannot
|
||||
|
@ -76,8 +76,12 @@ def set_storage(name, **kwargs):
|
|||
|
||||
Other attributes are differents according to the selected storage's name
|
||||
"""
|
||||
storage_type.set(name)
|
||||
setting = storage_type.get().setting
|
||||
if type_ == 'option':
|
||||
storage_option_type.set(name)
|
||||
setting = storage_option_type.get().setting
|
||||
else:
|
||||
storage_type.set(name)
|
||||
setting = storage_type.get().setting
|
||||
for option, value in kwargs.items():
|
||||
try:
|
||||
getattr(setting, option)
|
||||
|
@ -96,10 +100,13 @@ def _impl_getstate_setting():
|
|||
return state
|
||||
|
||||
|
||||
def get_storage(session_id, persistent, test):
|
||||
def get_storage(type_, session_id, persistent, test):
|
||||
"""all used when __setstate__ a Config
|
||||
"""
|
||||
return storage_type.get().Storage(session_id, persistent, test)
|
||||
if type_ == 'option':
|
||||
return storage_option_type.get().Storage(session_id, persistent, test)
|
||||
else:
|
||||
return storage_type.get().Storage(session_id, persistent, test)
|
||||
|
||||
|
||||
def get_storages(context, session_id, persistent):
|
||||
|
@ -113,18 +120,29 @@ def get_storages(context, session_id, persistent):
|
|||
return imp.Settings(storage), imp.Values(storage)
|
||||
|
||||
|
||||
def list_sessions():
|
||||
def get_storages_option():
|
||||
imp = storage_option_type.get()
|
||||
return imp.Base, imp.OptionDescription
|
||||
|
||||
|
||||
def list_sessions(type_):
|
||||
"""List all available session (persistent or not persistent)
|
||||
"""
|
||||
return storage_type.get().list_sessions()
|
||||
if type_ == 'option':
|
||||
return storage_option_type.get().list_sessions()
|
||||
else:
|
||||
return storage_type.get().list_sessions()
|
||||
|
||||
|
||||
def delete_session(session_id):
|
||||
def delete_session(type_, session_id):
|
||||
"""Delete a selected session, be careful, you can deleted a session
|
||||
use by an other instance
|
||||
:params session_id: id of session to delete
|
||||
"""
|
||||
return storage_type.get().delete_session(session_id)
|
||||
if type_ == 'option':
|
||||
return storage_option_type.get().delete_session(session_id)
|
||||
else:
|
||||
return storage_type.get().delete_session(session_id)
|
||||
|
||||
|
||||
__all__ = (set_storage, list_sessions, delete_session)
|
||||
|
|
|
@ -27,5 +27,7 @@ use it. But if something goes wrong, you will lost your modifications.
|
|||
from .value import Values
|
||||
from .setting import Settings
|
||||
from .storage import setting, Storage, list_sessions, delete_session
|
||||
from .option import Base, OptionDescription
|
||||
|
||||
__all__ = (setting, Values, Settings, Storage, list_sessions, delete_session)
|
||||
__all__ = (setting, Values, Settings, Storage, list_sessions, delete_session,
|
||||
Base, OptionDescription)
|
||||
|
|
Loading…
Reference in a new issue