summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/Utils.py6
-rw-r--r--src/mailman/config/config.py6
-rw-r--r--src/mailman/config/schema.cfg6
-rw-r--r--src/mailman/utilities/i18n.py35
-rw-r--r--src/mailman/utilities/tests/test_templates.py107
5 files changed, 157 insertions, 3 deletions
diff --git a/src/mailman/Utils.py b/src/mailman/Utils.py
index a58ed1d24..a26025fa3 100644
--- a/src/mailman/Utils.py
+++ b/src/mailman/Utils.py
@@ -210,9 +210,9 @@ def findtext(templatefile, raw_dict=None, raw=False, lang=None, mlist=None):
searchdirs = []
if mlist is not None:
searchdirs.append(mlist.data_path)
- searchdirs.append(os.path.join(TEMPLATE_DIR, mlist.host_name))
- searchdirs.append(os.path.join(TEMPLATE_DIR, 'site'))
- searchdirs.append(TEMPLATE_DIR)
+ searchdirs.append(os.path.join(config.TEMPLATE_DIR, mlist.host_name))
+ searchdirs.append(os.path.join(config.TEMPLATE_DIR, 'site'))
+ searchdirs.append(config.TEMPLATE_DIR)
# Start scanning
fp = None
try:
diff --git a/src/mailman/config/config.py b/src/mailman/config/config.py
index 4cfb6b5a5..636b9ef9e 100644
--- a/src/mailman/config/config.py
+++ b/src/mailman/config/config.py
@@ -34,6 +34,8 @@ from string import Template
from zope.component import getUtility
from zope.interface import Interface, implements
+import mailman.templates
+
from mailman import version
from mailman.interfaces.languages import ILanguageManager
from mailman.styles.manager import StyleManager
@@ -176,6 +178,10 @@ class Configuration:
pipermail_public_dir = category.pipermail_public_dir,
queue_dir = category.queue_dir,
var_dir = var_dir,
+ template_dir = (
+ os.path.dirname(mailman.templates.__file__)
+ if category.template_dir == ':source:'
+ else category.template_dir),
# Files.
creator_pw_file = category.creator_pw_file,
lock_file = category.lock_file,
diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg
index f789d28f9..09f575459 100644
--- a/src/mailman/config/schema.cfg
+++ b/src/mailman/config/schema.cfg
@@ -103,6 +103,12 @@ pipermail_public_dir: $var_dir/archives/public
# Directory for private Pipermail archiver artifacts.
pipermail_private_dir: $var_dir/archives/private
#
+# Where Mailman looks for its templates. This can either be a file system
+# path or the special symbol ':source:' to locate them within the source tree
+# (specifically, inside the mailman.templates package directory).
+#
+template_dir: :source:
+#
# There are also a number of paths to specific file locations that can be
# defined. For these, the directory containing the file must already exist,
# or be one of the directories created by Mailman as per above.
diff --git a/src/mailman/utilities/i18n.py b/src/mailman/utilities/i18n.py
new file mode 100644
index 000000000..45262997b
--- /dev/null
+++ b/src/mailman/utilities/i18n.py
@@ -0,0 +1,35 @@
+# Copyright (C) 2011 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/>.
+
+"""i18n template search and interpolation."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'find',
+ 'make',
+ ]
+
+
+
+def find():
+ pass
+
+
+def make():
+ pass
diff --git a/src/mailman/utilities/tests/test_templates.py b/src/mailman/utilities/tests/test_templates.py
new file mode 100644
index 000000000..446595108
--- /dev/null
+++ b/src/mailman/utilities/tests/test_templates.py
@@ -0,0 +1,107 @@
+# Copyright (C) 2011 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/>.
+
+"""Testing i18n template search and interpolation."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'test_suite',
+ ]
+
+
+import os
+import shutil
+import tempfile
+import unittest
+
+from zope.component import getUtility
+
+from mailman.app.lifecycle import create_list
+from mailman.config import config
+from mailman.interfaces.languages import ILanguageManager
+from mailman.testing.layers import ConfigLayer
+#from mailman.utilities.i18n import find, make
+
+from mailman.Utils import findtext
+
+
+
+class TestFind(unittest.TestCase):
+ layer = ConfigLayer
+
+ def setUp(self):
+ self.template_dir = tempfile.mkdtemp()
+ config.push('template config', """\
+ [paths.testing]
+ template_dir: {0}
+ """.format(self.template_dir))
+ # The following MUST happen AFTER the push() above since pushing a new
+ # config also clears out the language manager.
+ getUtility(ILanguageManager).add('xx', 'utf-8', 'Xlandia')
+ self.mlist = create_list('test@example.com')
+ self.mlist.preferred_language = 'xx'
+ # Populate global tempdir with a few fake templates.
+ self.xxdir = os.path.join(self.template_dir, 'xx')
+ os.mkdir(self.xxdir)
+ with open(os.path.join(self.xxdir, 'global.txt'), 'w') as fp:
+ print >> fp, 'Global template'
+ self.sitedir = os.path.join(self.template_dir, 'site', 'xx')
+ os.makedirs(self.sitedir)
+ with open(os.path.join(self.sitedir, 'site.txt'), 'w') as fp:
+ print >> fp, 'Site template'
+ self.domaindir = os.path.join(self.template_dir, 'example.com', 'xx')
+ os.makedirs(self.domaindir)
+ with open(os.path.join(self.domaindir, 'domain.txt'), 'w') as fp:
+ print >> fp, 'Domain template'
+ self.listdir = os.path.join(self.mlist.data_path, 'xx')
+ os.makedirs(self.listdir)
+ with open(os.path.join(self.listdir, 'list.txt'), 'w') as fp:
+ print >> fp, 'List template'
+
+ def tearDown(self):
+ config.pop('template config')
+ shutil.rmtree(self.template_dir)
+ shutil.rmtree(self.listdir)
+
+ def test_find_global_template(self):
+ text, filename = findtext('global.txt', lang='xx')
+ self.assertEqual(text, 'Global template\n')
+ self.assertEqual(filename, os.path.join(self.xxdir, 'global.txt'))
+
+ def test_find_site_template(self):
+ text, filename = findtext('site.txt', lang='xx')
+ self.assertEqual(text, 'Site template\n')
+ self.assertEqual(filename, os.path.join(self.sitedir, 'site.txt'))
+
+ def test_find_domain_template(self):
+ text, filename = findtext('domain.txt', mlist=self.mlist)
+ self.assertEqual(text, 'Domain template\n')
+ self.assertEqual(filename, os.path.join(self.domaindir, 'domain.txt'))
+
+ def test_find_list_template(self):
+ text, filename = findtext('list.txt', mlist=self.mlist)
+ self.assertEqual(text, 'List template\n')
+ self.assertEqual(filename, os.path.join(self.listdir, 'list.txt'))
+
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestFind))
+ return suite