summaryrefslogtreecommitdiff
path: root/Mailman/configuration.py
diff options
context:
space:
mode:
authorBarry Warsaw2007-07-16 23:55:49 -0400
committerBarry Warsaw2007-07-16 23:55:49 -0400
commitb8e8aa0386c2ee0fc7e90bf22fbe8fe3f222964a (patch)
tree5893e3908f89d8dd988c7844827d83e60ab6c532 /Mailman/configuration.py
parent327865eaf118f40063366acad9c7d97487e010d6 (diff)
downloadmailman-b8e8aa0386c2ee0fc7e90bf22fbe8fe3f222964a.tar.gz
mailman-b8e8aa0386c2ee0fc7e90bf22fbe8fe3f222964a.tar.zst
mailman-b8e8aa0386c2ee0fc7e90bf22fbe8fe3f222964a.zip
Major surgery to get the setuptools based installation passing all the
existing unit tests. Here's a summary of the changes. - Removed all dependent third party packages, since the setup.py file now claims all package dependencies such that they can be automatically installed from the cheeseshop. - Moved the misc directory into the Mailman package as Mailman/data. Moved templates and messages to Mailman subpackages. - Added an ILanguageManager interface, plus an implementation, so that we don't use Defaults.LC_DESCRIPTIONS directly anymore. Added a doctest for this interface and implementation. Defaults.LANGUAGES is moved into mailman.cfg. Defaults.LANGUAGE_DICT is moved to _DEFAULT_LANGUAGE_DATA, and LC_DESCRIPTIONS is removed. The calculation of the available and enabled languages is moved to the Configuration class, but this will probably still need work. Utils.GetLanguageDescr() and Utils.IsLanguage() are removed. I'd like to remove GetCharSet() eventually too, but there are too many uses of this currently, so I'm deferring it. - Utils.findtext(): Hacks added so that templates can be retrieved from the language catalog. The hack is that the template contents are used to find the translation, but in the one test case where this is actually flexed, the trailing newline in the file contents has to be trimmed. This is probably not right. - No more Defaults.py.in or mm_cfg.py! Defaults.py.in is moved to Defaults.py and is no longer created from a template file. The script called make_instance is added which creates an etc/mailman.cfg file from mailman.cfg.in (previously, mailman.cfg.sample) and /that/ file now has the small number of calculated values. In general, make_instance will not touch mailman.cfg if it exists, unless the --force option is given. CGIEXT is made the empty string by default (i.e. not generated). make_instance grows a --var-dir option. Fleshed out the --languages opton. - Defaults.py grows a DEFAULT_VAR_DIRECTORY variable, which is the default location of the 'var' directory. The Configuration class uses this as one of the directories it searches for its landmark, i.e. etc/mailman.cfg. RUNTIME_DIR is gone, as is VAR_PREFIX. - testall needs to write MAILMAN_USER, MAILMAN_UID, MAILMAN_GROUP, MAILMAN_GID, and LANGUAGES run time variables. - bin/withlist no longer needs to add config.BIN_DIR to sys.path, because in fact that variable doesn't exist any more. - Tweak the French catalog to make a test work. This is needed because of the conversion from %-strings to $-strings. - The setup.py now generates the .mo files before it does its thing. This will have to be fixed, but for now we must generate these files on setup build time instead of installation time. - Removed an unused interface.
Diffstat (limited to 'Mailman/configuration.py')
-rw-r--r--Mailman/configuration.py121
1 files changed, 79 insertions, 42 deletions
diff --git a/Mailman/configuration.py b/Mailman/configuration.py
index a8ecdae84..dbb057a5f 100644
--- a/Mailman/configuration.py
+++ b/Mailman/configuration.py
@@ -18,10 +18,12 @@
"""Configuration file loading and management."""
import os
+import sys
import errno
from Mailman import Defaults
from Mailman import Errors
+from Mailman.languages import LanguageManager
_missing = object()
@@ -46,63 +48,80 @@ class Configuration(object):
def load(self, filename=None):
join = os.path.join
- # Load the configuration from the named file, or if not given, search
- # in the runtime data directory for an etc/mailman.cfg file. If that
- # file is missing, use Mailman/mm_cfg.py for backward compatibility.
- #
- # Whatever you find, create a namespace and execfile that file in it.
- # The values in that namespace are exposed as attributes on this
- # Configuration instance.
- original_filename = filename
- if filename is None:
- filename = join(Defaults.RUNTIME_DIR, 'etc', 'mailman.cfg')
# Set up the execfile namespace
ns = Defaults.__dict__.copy()
# Prune a few things, add a few things
del ns['__file__']
del ns['__name__']
del ns['__doc__']
- ns['add_domain'] = self.add_domain
+ ns['add_domain'] = self.add_domain
ns['add_qrunner'] = self.add_qrunner
ns['del_qrunner'] = self.del_qrunner
+ self._languages = LanguageManager()
+ ns['add_language'] = self._languages.add_language
+ ns['enable_language'] = self._languages.enable_language
+ # Add all known languages, but don't enable them.
+ for code, (desc, charset) in Defaults._DEFAULT_LANGUAGE_DATA.items():
+ self._languages.add_language(code, desc, charset, False)
# Set up the default list of qrunners so that the mailman.cfg file may
# add or delete them.
for name in DEFAULT_QRUNNERS:
self.add_qrunner(name)
- # Attempt our first choice
- path = os.path.abspath(os.path.expanduser(filename))
- print 'path:', path
- try:
- execfile(path, ns, ns)
- self.filename = path
- except EnvironmentError, e:
- if e.errno <> errno.ENOENT or original_filename:
- raise
- # The file didn't exist, so try mm_cfg.py
- from Mailman import mm_cfg
- ns.update(mm_cfg.__dict__)
- self.filename = None
- # Based on values possibly set in mailman.cfg, add additional qrunners
+ # Load the configuration from the named file, or if not given, search
+ # in the runtime data directory for an etc/mailman.cfg file. If there
+ # is an instance.cfg file in the same directory, load that first, then
+ # mailman.cfg.
+ #
+ # Whatever you find, create a namespace and execfile that file in it.
+ # The values in that namespace are exposed as attributes on this
+ # Configuration instance.
+ self.filename = None
+ paths = [
+ # Development directories.
+ join(os.getcwd(), 'etc', 'mailman.cfg'),
+ join(os.getcwd(), 'var', 'etc', 'mailman.cfg'),
+ # Standard installation directories.
+ join('/etc', 'mailman.cfg'),
+ join(Defaults.DEFAULT_VAR_DIRECTORY, 'etc', 'mailman.cfg'),
+ ]
+ if filename is not None:
+ paths.insert(0, filename)
+ for cfg_path in paths:
+ path = os.path.abspath(os.path.expanduser(cfg_path))
+ try:
+ execfile(path, ns, ns)
+ except EnvironmentError, e:
+ if e.errno <> errno.ENOENT:
+ # It's okay if the instance.cfg file does not exist. This
+ # can happen for example in the test suite.
+ raise
+ else:
+ self.filename = cfg_path
+ break
+ if self.filename is None:
+ # The logging subsystem isn't running yet, so use stderr.
+ print >> sys.stderr, 'No runtime configuration file file. Use -C'
+ sys.exit(-1)
+ # Based on values possibly set in mailman.cfg, add additional qrunners.
if ns['USE_MAILDIR']:
self.add_qrunner('Maildir')
if ns['USE_LMTP']:
self.add_qrunner('LMTP')
- # Pull out the defaults
- RUNTIME_DIR = ns['RUNTIME_DIR']
+ # Pull out the defaults.
+ VAR_DIR = ns['VAR_DIR']
# Now that we've loaded all the configuration files we're going to
# load, set up some useful directories.
- self.LIST_DATA_DIR = join(RUNTIME_DIR, 'lists')
- self.LOG_DIR = join(RUNTIME_DIR, 'logs')
- self.LOCK_DIR = lockdir = join(RUNTIME_DIR, 'locks')
- self.DATA_DIR = datadir = join(RUNTIME_DIR, 'data')
- self.ETC_DIR = etcdir = join(RUNTIME_DIR, 'etc')
- self.SPAM_DIR = join(RUNTIME_DIR, 'spam')
- self.EXT_DIR = join(RUNTIME_DIR, 'ext')
- self.PUBLIC_ARCHIVE_FILE_DIR = join(RUNTIME_DIR, 'archives', 'public')
- self.PRIVATE_ARCHIVE_FILE_DIR = join(
- RUNTIME_DIR, 'archives', 'private')
+ self.LIST_DATA_DIR = join(VAR_DIR, 'lists')
+ self.LOG_DIR = join(VAR_DIR, 'logs')
+ self.LOCK_DIR = lockdir = join(VAR_DIR, 'locks')
+ self.DATA_DIR = datadir = join(VAR_DIR, 'data')
+ self.ETC_DIR = etcdir = join(VAR_DIR, 'etc')
+ self.SPAM_DIR = join(VAR_DIR, 'spam')
+ self.EXT_DIR = join(VAR_DIR, 'ext')
+ self.PUBLIC_ARCHIVE_FILE_DIR = join(VAR_DIR, 'archives', 'public')
+ self.PRIVATE_ARCHIVE_FILE_DIR = join(VAR_DIR, 'archives', 'private')
# Directories used by the qrunner subsystem
- self.QUEUE_DIR = qdir = join(RUNTIME_DIR, 'qfiles')
+ self.QUEUE_DIR = qdir = join(VAR_DIR, 'qfiles')
self.INQUEUE_DIR = join(qdir, 'in')
self.OUTQUEUE_DIR = join(qdir, 'out')
self.CMDQUEUE_DIR = join(qdir, 'commands')
@@ -121,15 +140,33 @@ class Configuration(object):
self.CONFIG_FILE = join(etcdir, 'mailman.cfg')
self.LOCK_FILE = join(lockdir, 'master-qrunner')
# Now update our dict so attribute syntax just works
- if 'add_domain' in ns:
- del ns['add_domain']
- if 'add_runner' in ns:
- del ns['add_runner']
+ del ns['add_domain']
+ del ns['add_qrunner']
+ del ns['del_qrunner']
self.__dict__.update(ns)
# Add the default domain if there are no virtual domains currently
# defined.
if not self.domains:
self.add_domain(self.DEFAULT_EMAIL_HOST, self.DEFAULT_URL_HOST)
+ # Enable all specified languages, and promote the language manager to
+ # a public attribute.
+ self.languages = self._languages
+ del self._languages
+ available_languages = set(self._DEFAULT_LANGUAGE_DATA)
+ enabled_languages = set(self.LANGUAGES.split())
+ if 'all' in enabled_languages:
+ languages = available_languages
+ else:
+ unknown_language = enabled_languages - available_languages
+ if unknown_language:
+ print >> sys.stderr, 'Ignoring unknown language codes:', \
+ SPACE.join(unknown_language)
+ languages = available_languages & enabled_languages
+ for code in languages:
+ self.languages.enable_language(code)
+ # Always add and enable the default server language.
+ code = self.DEFAULT_SERVER_LANGUAGE
+ self.languages.enable_language(code)
def add_domain(self, email_host, url_host):
"""Add the definition of a virtual domain.