import cherrypy
import inspect
import logging
-from ipsilon.util.data import AdminStore
+from ipsilon.util.data import AdminStore, Store
from ipsilon.util.log import Log
class PluginLoader(Log):
- def __init__(self, baseobj, facility, plugin_type):
+ def __init__(self, baseobj, facility, plugin_type, uses_store=True):
self._pathname, _ = os.path.split(inspect.getfile(baseobj))
self.facility = facility
self._plugin_type = plugin_type
self.available = dict()
self.enabled = list()
- self.__data = None
+ self.__data = False
+ self.uses_store = uses_store
# Defer initialization or instantiating the store will fail at load
# time when used with Installer plugins as the cherrypy config context
# is created after all Installer plugins are loaded.
@property
def _data(self):
+ if not self.uses_store:
+ raise Exception('Tried to get plugin data while ' +
+ 'uses_store=False (%s)' % self.facility)
if not self.__data:
self.__data = AdminStore()
return self.__data
def get_plugin_data(self):
self.available = self.get_plugins()
- self.refresh_enabled()
+ if self.uses_store:
+ self.refresh_enabled()
def save_enabled(self, enabled):
if enabled:
return
self.refresh_plugin_config()
- self.on_enable()
+ is_upgrade = Store._is_upgrade # pylint: disable=protected-access
+ try:
+ Store._is_upgrade = True # pylint: disable=protected-access
+ self.on_enable()
+ self._data.create_plugin_data_table(self.name)
+ for store in self.used_datastores():
+ store.upgrade_database()
+ finally:
+ Store._is_upgrade = is_upgrade # pylint: disable=protected-access
self.is_enabled = True
self.debug('Plugin enabled: %s' % self.name)
self.is_enabled = False
self.debug('Plugin disabled: %s' % self.name)
+ def used_datastores(self):
+ return []
+
def import_config(self, config):
self._config = config