summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarry Warsaw2010-05-06 13:39:11 -0400
committerBarry Warsaw2010-05-06 13:39:11 -0400
commit4e2003c2bd43822eeddc03cefd163f4f9311c4bb (patch)
treef855eacda52a8ff3e19a8cf107068abd5a40d384 /src
parent522da600c2bb04ef9a02351234ec1f95b68c7baa (diff)
downloadmailman-4e2003c2bd43822eeddc03cefd163f4f9311c4bb.tar.gz
mailman-4e2003c2bd43822eeddc03cefd163f4f9311c4bb.tar.zst
mailman-4e2003c2bd43822eeddc03cefd163f4f9311c4bb.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/commands/cli_import.py56
-rw-r--r--src/mailman/commands/docs/import.txt2
-rw-r--r--src/mailman/utilities/importer.py82
3 files changed, 86 insertions, 54 deletions
diff --git a/src/mailman/commands/cli_import.py b/src/mailman/commands/cli_import.py
index b9183fb82..75a119a77 100644
--- a/src/mailman/commands/cli_import.py
+++ b/src/mailman/commands/cli_import.py
@@ -27,39 +27,15 @@ __all__ = [
import sys
import cPickle
-import datetime
from zope.component import getUtility
from zope.interface import implements
from mailman.config import config
from mailman.core.i18n import _
-from mailman.interfaces.action import Action
-from mailman.interfaces.autorespond import ResponseAction
from mailman.interfaces.command import ICLISubCommand
-from mailman.interfaces.digests import DigestFrequency
from mailman.interfaces.listmanager import IListManager
-from mailman.interfaces.mailinglist import Personalization, ReplyToMunging
-from mailman.interfaces.nntp import NewsModeration
-
-
-
-def seconds_to_delta(value):
- return datetime.timedelta(seconds=value)
-
-
-TYPES = dict(
- autorespond_owner=ResponseAction,
- autorespond_postings=ResponseAction,
- autorespond_requests=ResponseAction,
- bounce_info_stale_after=seconds_to_delta,
- bounce_you_are_disabled_warnings_interval=seconds_to_delta,
- digest_volume_frequency=DigestFrequency,
- member_moderation_action=Action,
- news_moderation=NewsModeration,
- personalize=Personalization,
- reply_goes_to_list=ReplyToMunging,
- )
+from mailman.utilities.importer import import_config_pck
@@ -118,34 +94,6 @@ class Import21:
'Ignoring non-dictionary: {0!r}').format(
config_dict)
continue
- import_config(mlist, config_dict, args)
+ import_config_pck(mlist, config_dict, args)
# Commit the changes to the database.
config.db.commit()
-
-
-
-def import_config(mlist, config_dict, args):
- """Apply a configuration dictionary to a mailing list.
-
- :param mlist: The mailing list.
- :type mlist: IMailingList
- :param config_dict: The Mailman 2.1 configuration dictionary.
- :type config_dict: dict
- :param args: Command line arguments.
- """
- for key, value in config_dict.items():
- # Handle the simple case where the key is an attribute of the
- # IMailingList and the types are the same (modulo 8-bit/unicode
- # strings).
- if hasattr(mlist, key):
- if isinstance(value, str):
- value = unicode(value, 'ascii')
- # Some types require conversion.
- converter = TYPES.get(key)
- if converter is not None:
- value = converter(value)
- try:
- setattr(mlist, key, value)
- except TypeError as error:
- print >> sys.stderr, 'Type conversion error:', key
- raise
diff --git a/src/mailman/commands/docs/import.txt b/src/mailman/commands/docs/import.txt
index 61db46c37..f1ab072ec 100644
--- a/src/mailman/commands/docs/import.txt
+++ b/src/mailman/commands/docs/import.txt
@@ -50,3 +50,5 @@ import, the mailing list's 'real name' has changed.
>>> command.process(FakeArgs)
>>> print mlist.real_name
Test
+
+See `../../utilities/docs/importer.txt` for more details.
diff --git a/src/mailman/utilities/importer.py b/src/mailman/utilities/importer.py
new file mode 100644
index 000000000..0d80f7f38
--- /dev/null
+++ b/src/mailman/utilities/importer.py
@@ -0,0 +1,82 @@
+# Copyright (C) 2010 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman 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 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 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
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Importer routines."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'import_config_pck',
+ ]
+
+
+import cPickle
+import datetime
+
+from mailman.interfaces.action import Action
+from mailman.interfaces.autorespond import ResponseAction
+from mailman.interfaces.digests import DigestFrequency
+from mailman.interfaces.mailinglist import Personalization, ReplyToMunging
+from mailman.interfaces.nntp import NewsModeration
+
+
+
+def seconds_to_delta(value):
+ return datetime.timedelta(seconds=value)
+
+
+TYPES = dict(
+ autorespond_owner=ResponseAction,
+ autorespond_postings=ResponseAction,
+ autorespond_requests=ResponseAction,
+ bounce_info_stale_after=seconds_to_delta,
+ bounce_you_are_disabled_warnings_interval=seconds_to_delta,
+ digest_volume_frequency=DigestFrequency,
+ member_moderation_action=Action,
+ news_moderation=NewsModeration,
+ personalize=Personalization,
+ reply_goes_to_list=ReplyToMunging,
+ )
+
+
+
+def import_config_pck(mlist, config_dict, args):
+ """Apply a config.pck configuration dictionary to a mailing list.
+
+ :param mlist: The mailing list.
+ :type mlist: IMailingList
+ :param config_dict: The Mailman 2.1 configuration dictionary.
+ :type config_dict: dict
+ :param args: Command line arguments.
+ """
+ for key, value in config_dict.items():
+ # Handle the simple case where the key is an attribute of the
+ # IMailingList and the types are the same (modulo 8-bit/unicode
+ # strings).
+ if hasattr(mlist, key):
+ if isinstance(value, str):
+ value = unicode(value, 'ascii')
+ # Some types require conversion.
+ converter = TYPES.get(key)
+ if converter is not None:
+ value = converter(value)
+ try:
+ setattr(mlist, key, value)
+ except TypeError as error:
+ print >> sys.stderr, 'Type conversion error:', key
+ raise