can change storage with set_storage, storage's name is store in storage object and storage is create with get_storage

This commit is contained in:
2013-08-25 20:49:24 +02:00
parent 36ed6f874f
commit dcb12dac02
5 changed files with 26 additions and 21 deletions

View File

@ -34,7 +34,7 @@ ro_append = ('frozen', 'disabled', 'validator', 'everything_frozen',
rw_remove = ('permissive', 'everything_frozen', 'mandatory')
rw_append = ('frozen', 'disabled', 'validator', 'hidden')
default_properties = ('expire', 'validator')
storage_type = 'dictionary'
storage_type = 'sqlite3'
class _const:
@ -184,6 +184,22 @@ class Property(object):
return str(list(self._properties))
def set_storage(name):
global storage_type
storage_type = name
def get_storage(context, config_id, is_persistent):
def gen_id(config):
return str(id(config)) + str(time())
if config_id is None:
config_id = gen_id(context)
import_lib = 'tiramisu.storage.{0}.storage'.format(storage_type)
return __import__(import_lib, globals(), locals(), ['Storage'],
-1).Storage(config_id, is_persistent)
#____________________________________________________________
class Settings(object):
"``Config()``'s configuration options"
@ -202,7 +218,7 @@ class Settings(object):
# generic owner
self._owner = owners.user
self.context = context
import_lib = 'tiramisu.storage.{0}.setting'.format(storage_type)
import_lib = 'tiramisu.storage.{0}.setting'.format(storage.storage)
self._p_ = __import__(import_lib, globals(), locals(), ['Settings'],
-1).Settings(storage)