Allow deferred initialization of providers
[cascardo/ipsilon.git] / ipsilon / providers / common.py
index b1eab1a..6bcfef8 100755 (executable)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from ipsilon.util.log import Log
 from ipsilon.util.plugin import PluginLoader, PluginObject
 from ipsilon.util.plugin import PluginInstaller
 from ipsilon.util.page import Page
 import cherrypy
 
 
 from ipsilon.util.plugin import PluginLoader, PluginObject
 from ipsilon.util.plugin import PluginInstaller
 from ipsilon.util.page import Page
 import cherrypy
 
 
-class ProviderException(Exception):
+class ProviderException(Exception, Log):
 
     def __init__(self, message):
         super(ProviderException, self).__init__(message)
 
     def __init__(self, message):
         super(ProviderException, self).__init__(message)
@@ -32,10 +33,6 @@ class ProviderException(Exception):
     def __str__(self):
         return repr(self.message)
 
     def __str__(self):
         return repr(self.message)
 
-    def _debug(self, fact):
-        if cherrypy.config.get('debug', False):
-            cherrypy.log('%s: %s' % (self.__class__.__name__, fact))
-
 
 class ProviderBase(PluginObject):
 
 
 class ProviderBase(PluginObject):
 
@@ -44,11 +41,11 @@ class ProviderBase(PluginObject):
         self.name = name
         self.path = path
         self.tree = None
         self.name = name
         self.path = path
         self.tree = None
-        self.admin = None
 
 
-    def _debug(self, fact):
-        if cherrypy.config.get('debug', False):
-            cherrypy.log(fact)
+    def on_enable(self):
+        # this one does nothing
+        # derived classes can override with custom behavior
+        return
 
     def get_tree(self, site):
         raise NotImplementedError
 
     def get_tree(self, site):
         raise NotImplementedError
@@ -90,6 +87,8 @@ class ProviderBase(PluginObject):
 
         self.set_config_value('enabled', '1')
         self.save_plugin_config(FACILITY)
 
         self.set_config_value('enabled', '1')
         self.save_plugin_config(FACILITY)
+
+        self.on_enable()
         self._debug('IdP Provider enabled: %s' % self.name)
 
     def disable(self, site):
         self._debug('IdP Provider enabled: %s' % self.name)
 
     def disable(self, site):
@@ -136,7 +135,7 @@ class ProviderPageBase(Page):
 FACILITY = 'provider_config'
 
 
 FACILITY = 'provider_config'
 
 
-class LoadProviders(object):
+class LoadProviders(Log):
 
     def __init__(self, root, site):
         loader = PluginLoader(LoadProviders, FACILITY, 'IdpProvider')
 
     def __init__(self, root, site):
         loader = PluginLoader(LoadProviders, FACILITY, 'IdpProvider')
@@ -151,10 +150,6 @@ class LoadProviders(object):
             plugin = providers['available'][item]
             plugin.register(site)
 
             plugin = providers['available'][item]
             plugin.register(site)
 
-    def _debug(self, fact):
-        if cherrypy.config.get('debug', False):
-            cherrypy.log(fact)
-
 
 class ProvidersInstall(object):
 
 
 class ProvidersInstall(object):