Commit 530eade8 authored by Nick Groenen's avatar Nick Groenen

Give all backends storage by default

This removes the custom storage from the Telegram backend and makes it
available by default to all backends.
parent 972df47b
......@@ -3,11 +3,7 @@ import sys
from errbot.backends.base import RoomError, Identifier, MUCIdentifier, ONLINE
from errbot.errBot import ErrBot
from errbot.main import CORE_STORAGE
from errbot.rendering import text
from errbot.specific_plugin_manager import SpecificPluginManager
from errbot.storage import StoreMixin
from errbot.storage.base import StoragePluginBase
# Can't use __name__ because of Yapsy
......@@ -113,7 +109,7 @@ class TelegramMUCOccupant(MUCIdentifier, TelegramIdentifier):
room = TelegramIdentifier.id
class TelegramBackend(ErrBot, StoreMixin):
class TelegramBackend(ErrBot):
def __init__(self, config):
super().__init__(config)
config.MESSAGE_SIZE_LIMIT = TELEGRAM_MESSAGE_SIZE_LIMIT
......@@ -131,18 +127,6 @@ class TelegramBackend(ErrBot, StoreMixin):
self.bot_instance = None # Will be set in serve_once
self.md_converter = text()
# Initialize internal storage for the backend itself, which is
# needed for the bot to keep track of the getUpdates() offset.
# It is important for this storage to be local, not some shared DB
# otherwise two different instances will get conflicting offsets.
spm = SpecificPluginManager(config, 'storage', StoragePluginBase, CORE_STORAGE)
storage_plugin = spm.get_plugin_by_name('Shelf')
self.open_storage(storage_plugin, 'TelegramBackend')
def shutdown(self):
self.close_storage()
super().shutdown()
def serve_once(self):
log.info("Initializing connection")
try:
......
......@@ -19,15 +19,13 @@ import inspect
import logging
import traceback
from errbot.repo_manager import BotRepoManager
from .bundled.threadpool import ThreadPool, WorkRequest
from .backends.base import Backend
from .utils import (split_string_after,
get_class_that_defined_method, compat_str)
from .bundled.threadpool import ThreadPool, WorkRequest
from .streaming import Tee
from .plugin_manager import BotPluginManager
from .templating import tenv
from .utils import (split_string_after,
get_class_that_defined_method, compat_str)
from .storage import StoreMixin
log = logging.getLogger(__name__)
......@@ -62,7 +60,7 @@ def bot_config_defaults(config):
# noinspection PyAbstractClass
class ErrBot(Backend):
class ErrBot(Backend, StoreMixin):
""" ErrBot is the layer of Err that takes care of the plugin management and dispatching
"""
__errdoc__ = """ Commands related to the bot administration """
......@@ -102,6 +100,15 @@ class ErrBot(Backend):
# the storage_plugin is needed by the plugins
self.storage_plugin = storage_plugin
def initialize_backend_storage(self):
"""
Initialize storage for the backend to use.
"""
log.debug("Initializing backend storage")
assert self.plugin_manager is not None
assert self.storage_plugin is not None
self.open_storage(self.storage_plugin, '%s_backend' % self.mode)
@property
def all_commands(self):
"""Return both commands and re_commands together."""
......@@ -609,4 +616,5 @@ class ErrBot(Backend):
for command in self.all_commands.values())
def shutdown(self):
self.close_storage()
self.plugin_manager.shutdown()
......@@ -81,6 +81,7 @@ def setup_bot(backend_name, logger, config, restore=None):
bot.attach_storage_plugin(storage_plugin)
bot.attach_repo_manager(repo_manager)
bot.attach_plugin_manager(botpm)
bot.initialize_backend_storage()
except Exception:
log.exception("Unable to load or configure the backend.")
exit(-1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment