Allow attach custom storage backend

This commit is contained in:
Sergey Fursov
2013-12-28 14:15:35 +04:00
parent a91a7790c5
commit 3b0328ca1e
6 changed files with 66 additions and 6 deletions

View File

@ -81,6 +81,7 @@ INITIAL_CONFIG = {
"file": "~/.config/radicale/rights"},
"storage": {
"type": "filesystem",
"custom_handler": "",
"filesystem_folder": os.path.expanduser(
"~/.config/radicale/collections"),
"database_url": ""},

View File

@ -23,15 +23,20 @@ This module loads the storage backend, according to the storage
configuration.
"""
import sys
from .. import config, ical
def load():
"""Load list of available storage managers."""
storage_type = config.get("storage", "type")
root_module = __import__(
"storage.%s" % storage_type, globals=globals(), level=2)
module = getattr(root_module, storage_type)
if storage_type == "custom":
storage_module = config.get("storage", "custom_handler")
__import__(storage_module)
module = sys.modules[storage_module]
else:
root_module = __import__(
"storage.%s" % storage_type, globals=globals(), level=2)
module = getattr(root_module, storage_type)
ical.Collection = module.Collection
return module