Author: dmeyer
Date: Sat Oct 13 07:38:27 2007
New Revision: 2854

Log:
Rework plugin code so that plugins can have a config
object that will be added to the global config.


Modified:
   trunk/beacon/bin/beacon-daemon
   trunk/beacon/src/server/__init__.py
   trunk/beacon/src/server/config.cxml
   trunk/beacon/src/server/hwmon/server.py
   trunk/beacon/src/server/parser.py
   trunk/beacon/src/server/plugins/__init__.py
   trunk/beacon/src/server/server.py

Modified: trunk/beacon/bin/beacon-daemon
==============================================================================
--- trunk/beacon/bin/beacon-daemon      (original)
+++ trunk/beacon/bin/beacon-daemon      Sat Oct 13 07:38:27 2007
@@ -182,6 +182,12 @@
 
 
 import kaa.beacon.server
+import kaa.beacon.server.plugins
+
+# get plugins config
+plugin_config = kaa.beacon.server.plugins.get_config()
+if plugin_config is not None:
+    kaa.beacon.server.config.add_variable('plugins', plugin_config)
 
 # fork thumbnailer / hwmon
 pid = os.fork()

Modified: trunk/beacon/src/server/__init__.py
==============================================================================
--- trunk/beacon/src/server/__init__.py (original)
+++ trunk/beacon/src/server/__init__.py Sat Oct 13 07:38:27 2007
@@ -29,6 +29,7 @@
 #
 # -----------------------------------------------------------------------------
 
+from config import config
 
 def BeaconServer(database):
     import server

Modified: trunk/beacon/src/server/config.cxml
==============================================================================
--- trunk/beacon/src/server/config.cxml (original)
+++ trunk/beacon/src/server/config.cxml Sat Oct 13 07:38:27 2007
@@ -40,11 +40,4 @@
         </desc>
     </var>
 
-    <dict name="plugins">
-        <desc>Dict of plugins to enable (True/False)</desc>
-        <var default="False">
-            <desc>Enable plugin</desc>
-        </var>
-    </dict>
-
 </config>

Modified: trunk/beacon/src/server/hwmon/server.py
==============================================================================
--- trunk/beacon/src/server/hwmon/server.py     (original)
+++ trunk/beacon/src/server/hwmon/server.py     Sat Oct 13 07:38:27 2007
@@ -55,7 +55,7 @@
     cdrom = None
 
 # load server config
-from kaa.beacon.server.config import config
+from kaa.beacon.server import config
 
 # get logging object
 log = logging.getLogger('beacon.hwmon')

Modified: trunk/beacon/src/server/parser.py
==============================================================================
--- trunk/beacon/src/server/parser.py   (original)
+++ trunk/beacon/src/server/parser.py   Sat Oct 13 07:38:27 2007
@@ -63,19 +63,6 @@
     kaa.metadata.MEDIA_DIRECTORY: 'dir'
 }
 
-def load_plugins(server, db):
-    """
-    Load external plugins. Called by server on creating. The db object
-    is from kaa.beacon, not kaa.db.
-    """
-    plugindir = os.path.join(os.path.dirname(__file__), 'plugins')
-    for plugin in os.listdir(plugindir):
-        if not plugin.endswith('.py') or plugin == '__init__.py':
-            continue
-        exec('import plugins.%s as plugin' % plugin[:-3])
-        plugin.plugin_init(server, db, register)
-
-
 def register(ext, function):
     """
     Register a plugin to the parser. This function gets called by the

Modified: trunk/beacon/src/server/plugins/__init__.py
==============================================================================
--- trunk/beacon/src/server/plugins/__init__.py (original)
+++ trunk/beacon/src/server/plugins/__init__.py Sat Oct 13 07:38:27 2007
@@ -0,0 +1,71 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# plugins - Plugin interface for Beacon
+# -----------------------------------------------------------------------------
+# $Id$
+#
+# A beacon plugin is a python file located in this plugin directory
+# and needs a plugin_init function with the two paramater server and
+# database. The plugin can connect to the server ipc object, register a
+# callback to the parser or do something completly different. The module
+# may also provide a kaa.config object that will be added to the beacon
+# server config.
+#
+# -----------------------------------------------------------------------------
+# kaa.beacon.server - A virtual filesystem with metadata
+# Copyright (C) 2006-2007 Dirk Meyer
+#
+# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
+# Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
+#
+# Please see the file AUTHORS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------------
+
+import os
+import kaa.config
+
+plugindir = os.path.dirname(__file__)
+
+def get_config():
+    """
+    Return the plugin config object.
+    """
+    config = None
+    for plugin in os.listdir(plugindir):
+        if not plugin.endswith('.py') or plugin == '__init__.py':
+            continue
+        plugin_name = plugin[:-3]
+        exec('import %s as plugin' % plugin_name)
+        if hasattr(plugin, 'config'):
+            if config == None:
+                config = kaa.config.Group([])
+            config.add_variable(plugin_name, plugin.config)
+    return config
+
+
+def load(server, db):
+    """
+    Load external plugins. Called by server on creating. The db object
+    is from kaa.beacon, not kaa.db.
+    """
+    for plugin in os.listdir(plugindir):
+        if not plugin.endswith('.py') or plugin == '__init__.py':
+            continue
+        plugin_name = plugin[:-3]
+        exec('import %s as plugin' % plugin_name)
+        plugin.plugin_init(server, db)

Modified: trunk/beacon/src/server/server.py
==============================================================================
--- trunk/beacon/src/server/server.py   (original)
+++ trunk/beacon/src/server/server.py   Sat Oct 13 07:38:27 2007
@@ -50,6 +50,7 @@
 from monitor import Monitor
 from crawl import Crawler
 from config import config
+import plugins
 
 # get logging object
 log = logging.getLogger('beacon.server')
@@ -134,9 +135,6 @@
         # list of current clients
         self._clients = []
 
-        # load parser plugins
-        parser.load_plugins(self, self._db)
-
         config.set_filename(os.path.join(dbdir, "config"))
         config.load()
         # We need to save at this point because we may have new
@@ -162,6 +160,9 @@
         self.item_controller = Controller(self, self._db, rootfs)
         self._db.commit()
 
+        # load plugins
+        plugins.load(self, self._db)
+
         for dir in config.monitors:
             self.monitor_dir(os.path.expandvars(os.path.expanduser(dir)))
 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to