Commit e903e119 authored by Guillaume Binet's avatar Guillaume Binet

fixed backup + missing features on storages.

parent 2081529b
......@@ -262,7 +262,7 @@ class TestBackend(ErrBot):
log.debug("Trigger disconnect callback")
self.disconnect_callback()
log.debug("Trigger shutdown")
self.plugin_manager.shutdown()
self.shutdown()
def connect(self):
return
......
......@@ -16,7 +16,7 @@ class Backup(BotPlugin):
f.write('## This file is not executable on its own. use err.py -r FILE to restore your bot.\n\n')
f.write('log.info("Restoring core configs.")\n')
for key in self._bot.plugin_manager: # don't mimic that in real plugins, this is core only.
f.write('bot.plugin_manager["'+key+'"] = ' + repr(self._bot[key]) + '\n')
f.write('bot.plugin_manager["'+key+'"] = ' + repr(self._bot.plugin_manager[key]) + '\n')
f.write('log.info("Installing plugins.")\n')
f.write('if "repos" in bot.plugin_manager:\n')
......@@ -27,13 +27,13 @@ class Backup(BotPlugin):
f.write('log.info("Restoring plugins data.")\n')
for plug in self._bot.getAllPlugins():
for plug in self._bot.plugin_manager.getAllPlugins():
pobj = plug.plugin_object
if pobj.shelf:
if pobj.store:
f.write('pobj = bot.plugin_manager.get_plugin_by_name("' + plug.name + '").plugin_object\n')
f.write('pobj.init_storage()\n')
for key in pobj.shelf:
for key in pobj:
f.write('pobj["'+key+'"] = ' + repr(pobj[key]) + '\n')
f.write('pobj.close_storage()\n')
......
......@@ -43,9 +43,10 @@ class Health(BotPlugin):
def status_plugins(self, mess, args):
""" shows the plugin status
"""
all_blacklisted = self._bot.plugin_manager.get_blacklisted_plugin()
all_loaded = self._bot.plugin_manager.get_all_active_plugin_names()
all_attempted = sorted([p.name for p in self._bot.plugin_manager.all_candidates])
pm = self._bot.plugin_manager
all_blacklisted = pm.get_blacklisted_plugin()
all_loaded = pm.get_all_active_plugin_names()
all_attempted = sorted([p.name for p in pm.all_candidates])
plugins_statuses = []
for name in all_attempted:
if name in all_blacklisted:
......@@ -55,9 +56,8 @@ class Health(BotPlugin):
plugins_statuses.append(('BD', name))
elif name in all_loaded:
plugins_statuses.append(('A', name))
elif self._bot.plugin_manager.get_plugin_obj_by_name(
name) is not None and self._bot.plugin_manager.get_plugin_obj_by_name(
name).get_configuration_template() is not None and self._bot.plugin_manager.get_plugin_configuration(
elif pm.get_plugin_obj_by_name(name) is not None \
and pm.get_plugin_obj_by_name(name).get_configuration_template() is not None and pm.get_plugin_configuration(
name) is None:
plugins_statuses.append(('C', name))
else:
......
......@@ -602,3 +602,6 @@ class ErrBot(Backend):
def get_command_classes(self):
return (get_class_that_defined_method(command)
for command in self.all_commands.values())
def shutdown(self):
self.plugin_manager.shutdown()
\ No newline at end of file
......@@ -61,7 +61,7 @@ class StoreMixin(MutableMapping):
return self.store.len()
def __iter__(self):
for i in self.store.iter():
for i in self.store.keys():
yield i
def __contains__(self, x):
......
from abc import abstractmethod
from typing import Mapping, Any
from typing import Any, Tuple, Iterable
class StorageBase(object):
......@@ -46,6 +46,14 @@ class StorageBase(object):
"""
pass
@abstractmethod
def keys(self) -> Iterable[str]:
"""
:return: an iterator on all the entries
"""
pass
@abstractmethod
def close(self) -> None:
"""
......
......@@ -27,6 +27,9 @@ class MemoryStorage(StorageBase):
def len(self):
return len(self.root)
def keys(self):
return self.root.keys()
def close(self) -> None:
ROOTS[self.namespace] = self.root
......
......@@ -27,17 +27,19 @@ class ShelfStorage(StorageBase):
def len(self):
return len(self.shelf)
def keys(self):
return self.keys()
def close(self) -> None:
self.shelf.close()
self.shelf = None
log.debug('Closed shelf of %s' % self.__class__.__name__)
class ShelfStoragePlugin(StoragePluginBase):
def __init__(self, bot_config):
super().__init__(bot_config)
if 'basedir' not in self._storage_config:
self._storage_config['basedir'] = d
self._storage_config['basedir'] = bot_config.BOT_DATA_DIR
def open(self, namespace: str) -> StorageBase:
config = self._storage_config
......
......@@ -147,11 +147,14 @@ class TestCommands(FullStackTest):
self.assertIn('errbotio/err-helloworld', open(filename).read())
# Now try to clean the bot and restore
for p in self.bot.plugin_manager.get_all_active_plugin_objects():
p.close_storage()
plugins_dir = path.join(self.bot.bot_config.BOT_DATA_DIR, 'plugins')
self.bot.plugin_manager['repos'] = {}
self.bot.plugin_manager['configs'] = {}
rmtree(plugins_dir)
mkdir(plugins_dir)
self.bot['repos'] = {}
self.bot['configs'] = {}
# emulates the restore environment
log = logging.getLogger(__name__) # noqa
......
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