Refactor the data store a bit
[cascardo/ipsilon.git] / ipsilon / util / plugin.py
index 045cc75..903f548 100755 (executable)
@@ -21,16 +21,13 @@ import os
 import imp
 import cherrypy
 import inspect
-from ipsilon.util.data import Store
+from ipsilon.util.data import AdminStore
+from ipsilon.util.log import Log
 
 
 class Plugins(object):
 
-    def __init__(self, path=None):
-        if path is None:
-            self._path = os.getcwd()
-        else:
-            self._path = path
+    def __init__(self):
         self._providers_tree = None
 
     def _load_class(self, tree, class_type, file_name):
@@ -40,7 +37,7 @@ class Plugins(object):
         try:
             if ext.lower() == '.py':
                 mod = imp.load_source(name, file_name)
-            #elif ext.lower() == '.pyc':
+            # elif ext.lower() == '.pyc':
             #    mod = imp.load_compiled(name, file_name)
             else:
                 return
@@ -75,15 +72,19 @@ class Plugins(object):
 class PluginLoader(object):
 
     def __init__(self, baseobj, facility, plugin_type):
-        (whitelist, config) = Store().get_plugins_config(facility)
+        config = AdminStore().load_options(facility)
+        cherrypy.log('LOAD: %s\n' % repr(config))
+        whitelist = []
+        if 'global' in config:
+            sec = config['global']
+            if 'order' in sec:
+                whitelist = sec['order'].split(',')
         if cherrypy.config.get('debug', False):
             cherrypy.log('[%s] %s: %s' % (facility, whitelist, config))
-        if whitelist is None:
-            whitelist = []
         if config is None:
             config = dict()
 
-        p = Plugins(path=cherrypy.config['base.dir'])
+        p = Plugins()
         (pathname, dummy) = os.path.split(inspect.getfile(baseobj))
         self._plugins = {
             'config': config,
@@ -96,13 +97,23 @@ class PluginLoader(object):
         return self._plugins
 
 
-class PluginObject(object):
+class PluginInstaller(object):
+    def __init__(self, baseobj):
+        (pathname, dummy) = os.path.split(inspect.getfile(baseobj))
+        self._pathname = pathname
+
+    def get_plugins(self):
+        p = Plugins()
+        return p.get_plugins(self._pathname, 'Installer')
+
+
+class PluginObject(Log):
 
     def __init__(self):
         self.name = None
         self._config = None
         self._options = None
-        self._data = Store()
+        self._data = AdminStore()
 
     def get_config_desc(self):
         """ The configuration description is a dictionary that provides
@@ -138,9 +149,29 @@ class PluginObject(object):
             self._config = dict()
         self._config[option] = value
 
+    def get_plugin_config(self, facility):
+        return self._data.load_options(facility, self.name)
+
+    def save_plugin_config(self, facility, config=None):
+        if config is None:
+            config = self._config
+        self._data.save_options(facility, self.name, config)
+
     def get_data(self, idval=None, name=None, value=None):
         return self._data.get_data(self.name, idval=idval, name=name,
                                    value=value)
 
     def save_data(self, data):
         self._data.save_data(self.name, data)
+
+    def new_datum(self, datum):
+        self._data.new_datum(self.name, datum)
+
+    def del_datum(self, idval):
+        self._data.del_datum(self.name, idval)
+
+    def wipe_config_values(self, facility):
+        self._data.delete_options(facility, self.name, None)
+
+    def wipe_data(self):
+        self._data.wipe_data(self.name)