summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pykolab/plugin/__init__.py0
-rw-r--r--pykolab/plugins/__init__.py (renamed from pykolab/plugins.py)66
-rw-r--r--pykolab/plugins/defaultfolders/__init__.py (renamed from pykolab/plugin/defaultfolders/__init__.py)38
-rw-r--r--pykolab/plugins/dynamicquota/__init__.py (renamed from pykolab/plugin/dynamicquota/__init__.py)0
-rw-r--r--pykolab/plugins/recipientpolicy/__init__.py (renamed from pykolab/plugin/recipientpolicy/__init__.py)39
5 files changed, 80 insertions, 63 deletions
diff --git a/pykolab/plugin/__init__.py b/pykolab/plugin/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/pykolab/plugin/__init__.py
+++ /dev/null
diff --git a/pykolab/plugins.py b/pykolab/plugins/__init__.py
index 991a1e6..116b777 100644
--- a/pykolab/plugins.py
+++ b/pykolab/plugins/__init__.py
@@ -19,26 +19,36 @@
import logging
import os
+import pdb
import pykolab
import sys
-import pdb
+import traceback
+
+if False:
+ import pykolab.plugins.defaultfolders
+ import pykolab.plugins.dynamicquota
+ import pykolab.plugins.recipientpolicy
# Translation
from pykolab.translate import _
-import pykolab.plugin
-
class KolabPlugins:
- """Detects, loads and interfaces with plugins for Kolab"""
+ """
+ Detects, loads and interfaces with plugins for different
+ Kolab components.
+ """
def __init__(self, init=False, conf=None):
"""
- Searches the plugin directory for plugins, and loads them into a list.
+ Searches the plugin directory for plugins, and loads
+ them into a list.
"""
self.conf = conf
+ self.log = logging.getLogger('pykolab.plugins')
+
self.plugins = {}
- for plugin_path in [ '/usr/share/pykolab/plugin/', './pykolab/plugin/' ]:
+ for plugin_path in [ '/usr/share/pykolab/plugins', './pykolab/plugins' ]:
if os.path.isdir(plugin_path):
for plugin in os.listdir(plugin_path):
if os.path.isdir('%s/%s/' %(plugin_path,plugin,)):
@@ -47,34 +57,50 @@ class KolabPlugins:
self.check_plugins(init=init)
def check_plugins(self, init=False):
- """Checks all plugins in self.plugins and sets the values to
- True (loadable) or False (not enabled, not installed or not loadable)"""
+ """
+ Checks all plugins in self.plugins and sets the values to
+ True (loadable) or False -- not enabled, not installed or
+ not loadable.
+ """
for plugin in self.plugins:
try:
- exec("from pykolab.plugin.%s import Kolab%s" %(plugin,plugin.capitalize()))
+ exec("from pykolab.plugins import %s" %(plugin))
self.plugins[plugin] = True
self.load_plugins(plugins=[plugin], init=init)
except ImportError, e:
if not init: print >> sys.stderr, _("ImportError for plugin %s: %s") % (plugin,e)
+ traceback.print_exc()
self.plugins[plugin] = False
except RuntimeError, e:
if not init: print >> sys.stderr, _("RuntimeError for plugin %s: %s") % (plugin,e)
+ traceback.print_exc()
self.plugins[plugin] = False
except Exception, e:
if not init: print >> sys.stderr, _("Plugin %s failed to load (%s: %s)") % (plugin, e.__class__, e)
+ traceback.print_exc()
+ except:
+ traceback.print_exc()
def load_plugins(self, plugins=[], init=False):
- """Loads plugins specified by a list of plugins or loads them all"""
+ """
+ Loads plugins specified by a list of plugins or loads them all
+ """
if len(plugins) < 1:
plugins = self.plugins.keys()
for plugin in plugins:
if self.plugins[plugin]:
- exec("self.%s = pykolab.plugin.%s.Kolab%s(conf=self.conf)" % (plugin,plugin,plugin.capitalize()))
+ try:
+ exec("self.%s = %s.Kolab%s(conf=self.conf)" % (plugin,plugin,plugin.capitalize()))
+ except:
+ # TODO: A little better verbosity please!
+ traceback.print_exc()
def set_defaults(self, defaults, plugins=[]):
- """Test for a function set_defaults() in all available and loaded plugins and execute plugin.set_defaults()"""
+ """
+ Test for a function set_defaults() in all available and loaded plugins and execute plugin.set_defaults()
+ """
if len(plugins) < 1:
plugins = self.plugins.keys()
@@ -101,7 +127,9 @@ class KolabPlugins:
print >> sys.stderr, _("Not setting defaults for plugin %s: No function 'set_defaults()'") % plugin
def set_runtime(self, runtime, plugins=[]):
- """Set runtime variables from plugins, like 'i_did_all_this'"""
+ """
+ Set runtime variables from plugins, like 'i_did_all_this'
+ """
if len(plugins) < 1:
plugins = self.plugins.keys()
@@ -120,7 +148,9 @@ class KolabPlugins:
print >> sys.stderr, _("Not setting runtime for plugin %s: No function 'set_runtime()'") % plugin
def add_options(self, parser, plugins=[]):
- """Add options specified in a plugin to parser. Takes a list of plugin names or does them all"""
+ """
+ Add options specified in a plugin to parser. Takes a list of plugin names or does them all
+ """
if len(plugins) < 1:
plugins = self.plugins.keys()
@@ -142,7 +172,9 @@ class KolabPlugins:
print >> sys.stderr, _("Not adding options for plugin %s: No function 'add_options()'") % plugin
def check_options(self, conf, plugins=[]):
- """Executes plugin.check_plugins() for all enabled plugins or the list of plugin names specified."""
+ """
+ Executes plugin.check_plugins() for all enabled plugins or the list of plugin names specified.
+ """
if len(plugins) < 1:
plugins = self.plugins.keys()
@@ -162,7 +194,9 @@ class KolabPlugins:
print >> sys.stderr, _("Not checking options for plugin %s: No function 'check_options()'") % plugin
def plugin_check_setting(self, func, option, val, plugins=[]):
- """Checks one setting specified by 'option' against the 'val' it is passed by all plugins or by the list of plugins specified"""
+ """
+ Checks one setting specified by 'option' against the 'val' it is passed by all plugins or by the list of plugins specified
+ """
if len(plugins) < 1:
plugins = self.plugins.keys()
diff --git a/pykolab/plugin/defaultfolders/__init__.py b/pykolab/plugins/defaultfolders/__init__.py
index 550be2d..426b293 100644
--- a/pykolab/plugin/defaultfolders/__init__.py
+++ b/pykolab/plugins/defaultfolders/__init__.py
@@ -17,6 +17,10 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
+__all__ = [
+ 'KolabDefaultfolders'
+ ]
+
class KolabDefaultfolders(object):
"""
Example plugin to create a set of default folders.
@@ -33,36 +37,8 @@ class KolabDefaultfolders(object):
- user folder
"""
- (folder) = args
-
- folders_to_create = {}
-
- folders_to_create["Calendar"] = {
- "annotations": {
- "/vendor/kolab/folder-test": "true",
- "/vendor/kolab/folder-type": "event.default"
- }
- }
-
- folders_to_create["Calendar/Personlich"] = {
- "annotations": {
- "/vendor/kolab/folder-test": "true",
- "/vendor/kolab/folder-type": "event"
- }
- }
-
- folders_to_create["Contacts"] = {
- "annotations": {
- "/vendor/kolab/folder-test": "true",
- "/vendor/kolab/folder-type": "contact.default"
- }
- }
+ (folder, additional_folders) = args
- folders_to_create["Dagboek"] = {
- "annotations": {
- "/vendor/kolab/folder-test": "true",
- "/vendor/kolab/folder-type": "journal.default"
- }
- }
+ exec("additional_folders = %s" %(additional_folders))
- return folders_to_create \ No newline at end of file
+ return additional_folders
diff --git a/pykolab/plugin/dynamicquota/__init__.py b/pykolab/plugins/dynamicquota/__init__.py
index c91ebfc..c91ebfc 100644
--- a/pykolab/plugin/dynamicquota/__init__.py
+++ b/pykolab/plugins/dynamicquota/__init__.py
diff --git a/pykolab/plugin/recipientpolicy/__init__.py b/pykolab/plugins/recipientpolicy/__init__.py
index 3aa7c2a..fbf0179 100644
--- a/pykolab/plugin/recipientpolicy/__init__.py
+++ b/pykolab/plugins/recipientpolicy/__init__.py
@@ -35,46 +35,53 @@ class KolabRecipientpolicy(object):
## Your actions go here. For example:
#return (mail, alternative_mail)
- def set_user_attrs_mail(self, kw={}, args=()):
+ def set_primary_mail(self, kw={}, args=()):
"""
The arguments passed to the 'set_user_attrs_mail' hook:
- current user attributes
"""
- (user_attrs) = args
+
+ (user_attrs, primary_domain, secondary_domains) = args
user_attrs = utils.normalize(user_attrs)
+ if not user_attrs.has_key('domain'):
+ user_attrs['domain'] = primary_domain
+ elif not user_attrs['domain'] == primary_domain:
+ user_attrs['domain'] = primary_domain
+
try:
- mail = self.conf.get_raw('recipient_policy', 'primary_email') % user_attrs
- return mail
+ mail = kw['primary_mail'] % user_attrs
+ return mail.lower()
except KeyError, e:
self.conf.log.warning(_("Attribute substitution for 'mail' failed in Recipient Policy"))
- return "user@example.org"
+ return user_attrs['mail'].lower()
- def set_user_attrs_alternative_mail(self, kw={}, args=()):
+ def set_secondary_mail(self, kw={}, args=()):
"""
The arguments passed to the 'set_user_attrs_alternative_mail' hook:
- current user attributes
"""
- (user_attrs) = args
+ (user_attrs, primary_domain, secondary_domains) = args
user_attrs = utils.normalize(user_attrs)
- other_email_routines = self.conf.get_raw('recipient_policy', 'other_email')
+ user_attrs['standard_domain'] = primary_domain
- exec("other_email_routines = %s" % other_email_routines)
+ exec("alternative_mail_routines = %s" % kw['secondary_mail'])
alternative_mail = []
- for routine in other_email_routines.keys():
- try:
- exec("retval = '%s'.%s" % (routine,other_email_routines[routine] % user_attrs))
- except KeyError, e:
- self.conf.log.warning(_("Attribute substitution for 'mail' failed in Recipient Policy"))
- retval = "user@example.org"
- alternative_mail.append(retval)
+ for routine in alternative_mail_routines.keys():
+ for _domain in [ primary_domain ] + secondary_domains:
+ user_attrs['domain'] = _domain
+ try:
+ exec("retval = '%s'.%s" % (routine,alternative_mail_routines[routine] % user_attrs))
+ except KeyError, e:
+ self.conf.log.warning(_("Attribute substitution for 'alternative_mail' failed in Recipient Policy"))
+ alternative_mail.append(retval)
return alternative_mail