summaryrefslogtreecommitdiff
path: root/Mailman/bin/make_instance.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/bin/make_instance.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/bin/make_instance.py')
-rw-r--r--Mailman/bin/make_instance.py98
1 files changed, 69 insertions, 29 deletions
diff --git a/Mailman/bin/make_instance.py b/Mailman/bin/make_instance.py
index 435b0863a..14eed24ce 100644
--- a/Mailman/bin/make_instance.py
+++ b/Mailman/bin/make_instance.py
@@ -21,23 +21,21 @@ import os
import grp
import pwd
import sys
+import errno
+import shutil
import optparse
import setuptools
from string import Template
-import Mailman
-from Mailman.Version import MAILMAN_VERSION
+import Mailman.data
-# Until an instance is actually created, this module won't be importable
-# because the Defaults.py module won't have been created yet.
-try:
- from Mailman.i18n import _
-except ImportError:
- def _(s): return s
+from Mailman import Defaults
+from Mailman.Version import MAILMAN_VERSION
+from Mailman.i18n import _
__i18n_templates__ = True
SPACE = ' '
-DEFAULT_RUNTIME_DIR = '/var/mailman'
+DATA_DIR = os.path.dirname(Mailman.data.__file__)
@@ -49,11 +47,17 @@ def parseargs():
Create a Mailman instance by generating all the necessary basic configuration
support and intervening directories.
"""))
- parser.add_option('-r', '--runtime-dir',
- type='string', default=DEFAULT_RUNTIME_DIR, help=_("""\
+ parser.add_option('-d', '--var-dir',
+ type='string', default=Defaults.DEFAULT_VAR_DIRECTORY,
+ help=_("""\
The top-level runtime data directory. All supporting runtime data will be
placed in subdirectories of this directory. It will be created if necessary,
although this might require superuser privileges."""))
+ parser.add_option('-f', '--force',
+ default=False, action='store_true', help=_("""\
+Force overwriting of mailman.cfg file with new values. Ordinarily, Mailman
+will never overwrite this file because it would cause you to lose your
+configuration data."""))
parser.add_option('-p', '--permchecks',
default=False, action='store_true', help=_("""\
Perform permission checks on the runtime directory."""))
@@ -65,9 +69,13 @@ current user is used."""))
type='string', default=None, help=_("""\
The group id or name to use for the runtime environment. If not specified, the
current group is used."""))
- parser.add_option('-l', '--language',
- default=[], type='string', action='append', help=_("""\
-Enable the given language. Use 'all' to enable all supported languages."""))
+ parser.add_option('-l', '--languages',
+ default=Defaults.DEFAULT_SERVER_LANGUAGE, type='string',
+ help=_("""\
+Space separated list of language codes to enable. Use -L to print all
+available language codes and the name of the associated native language.
+Default is to enable just English. Use the special code 'all' to enable all
+available languages."""))
opts, args = parser.parse_args()
if args:
unexpected = SPACE.join(args)
@@ -76,13 +84,9 @@ Enable the given language. Use 'all' to enable all supported languages."""))
-def instantiate(user=None, group=None, runtime_dir=None):
- # Create the Defaults.py file using substitutions.
- in_file_path = os.path.join(os.path.dirname(Mailman.__file__),
- 'Defaults.py.in')
- out_file_path = os.path.splitext(in_file_path)[0]
- with open(in_file_path) as fp:
- raw = Template(fp.read())
+def instantiate(var_dir, user, group, languages, force):
+ # XXX This needs to be converted to use package resources.
+ etc_dir = os.path.join(var_dir, 'etc')
# Figure out which user name and group name to use.
if user is None:
uid = os.getuid()
@@ -112,20 +116,56 @@ def instantiate(user=None, group=None, runtime_dir=None):
group_name = grp.getgrgid(gid).gr_name
except KeyError:
parser.print_error(_('Unknown group: $group'))
- # Process the .in file and write it to Defaults.py.
- processed = raw.safe_substitute(runtime_dir=runtime_dir,
- user_name=user_name,
- group_name=group_name)
- with open(out_file_path, 'w') as fp:
- fp.write(processed)
+ # Make the runtime dir if it doesn't yet exist.
+ try:
+ omask = os.umask(0)
+ try:
+ os.makedirs(etc_dir, 02775)
+ finally:
+ os.umask(omask)
+ except OSError, e:
+ # Ignore the exceptions if the directory already exists
+ if e.errno <> errno.EEXIST:
+ raise
+ os.chown(etc_dir, uid, gid)
+ # Create an etc/mailman.cfg file which contains just a few configuration
+ # variables about the run-time environment that can't be calculated.
+ # Don't overwrite mailman.cfg unless the -f flag was given.
+ in_file_path = os.path.join(DATA_DIR, 'mailman.cfg.in')
+ out_file_path = os.path.join(etc_dir, 'mailman.cfg')
+ if os.path.exists(out_file_path) and not force:
+ # The logging subsystem isn't up yet, so just print this to stderr.
+ print >> sys.stderr, 'File exists:', out_file_path
+ print >> sys.stderr, 'Use --force to override.'
+ else:
+ with open(in_file_path) as fp:
+ raw = Template(fp.read())
+ processed = raw.safe_substitute(var_dir=var_dir,
+ user_id=uid,
+ user_name=user_name,
+ group_name=group_name,
+ group_id=gid,
+ languages=SPACE.join(languages),
+ )
+ with open(out_file_path, 'w') as fp:
+ fp.write(processed)
# XXX Do --permchecks
- # XXX Do --language
def main():
parser, opts, args = parseargs()
- instantiate(opts.user, opts.group, opts.runtime_dir)
+ available_languages = set(Defaults.LANGUAGE_DICT)
+ enable_languages = set(opts.languages.split())
+ if 'all' in enable_languages:
+ languages = available_languages
+ else:
+ unknown_language = enable_languages - available_languages
+ if unknown_language:
+ print >> sys.stderr, 'Ignoring unknown language codes:', \
+ SPACE.join(unknown_language)
+ languages = available_languages & enable_languages
+ instantiate(opts.var_dir, opts.user, opts.group, languages, opts.force)