diff options
Diffstat (limited to 'Mailman/bin')
| -rw-r--r-- | Mailman/bin/make_instance.py | 98 | ||||
| -rw-r--r-- | Mailman/bin/newlist.py | 2 | ||||
| -rw-r--r-- | Mailman/bin/rmlist.py | 2 | ||||
| -rw-r--r-- | Mailman/bin/testall.py | 20 | ||||
| -rw-r--r-- | Mailman/bin/withlist.py | 4 |
5 files changed, 86 insertions, 40 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) diff --git a/Mailman/bin/newlist.py b/Mailman/bin/newlist.py index 5ac2dc5a6..1bbe818ff 100644 --- a/Mailman/bin/newlist.py +++ b/Mailman/bin/newlist.py @@ -104,7 +104,7 @@ def main(): if opts.language is None: opts.language = config.DEFAULT_SERVER_LANGUAGE # Is the language known? - if opts.language not in config.LC_DESCRIPTIONS: + if opts.language not in config.languages.enabled_codes: parser.print_help() print >> sys.stderr, _('Unknown language: $opts.language') sys.exit(1) diff --git a/Mailman/bin/rmlist.py b/Mailman/bin/rmlist.py index 26dbd1df7..fcc47b3f0 100644 --- a/Mailman/bin/rmlist.py +++ b/Mailman/bin/rmlist.py @@ -83,7 +83,7 @@ def delete_list(listname, mlist=None, archives=True, quiet=False): ]) for dirtmpl, msg in removeables: - path = os.path.join(config.VAR_PREFIX, dirtmpl) + path = os.path.join(config.VAR_DIR, dirtmpl) remove_it(listname, path, msg, quiet) diff --git a/Mailman/bin/testall.py b/Mailman/bin/testall.py index 005808cfe..a5c9d02e6 100644 --- a/Mailman/bin/testall.py +++ b/Mailman/bin/testall.py @@ -167,7 +167,7 @@ def main(): # Set up the testing configuration file both for this process, and for all # sub-processes testing will spawn (e.g. the qrunners). # - # Calculate a temporary VAR_PREFIX directory so that run-time artifacts of + # Calculate a temporary VAR_DIR directory so that run-time artifacts of # the tests won't tread on the installation's data. This also makes it # easier to clean up after the tests are done, and insures isolation of # test suite runs. @@ -177,14 +177,24 @@ def main(): os.close(fd) shutil.copyfile(cfg_in, cfg_out) - var_prefix = tempfile.mkdtemp() + var_dir = tempfile.mkdtemp() if opts.verbosity > 2: - print 'VAR_PREFIX :', var_prefix + print 'VAR_DIR :', var_dir print 'config file:', cfg_out + user_id = os.getuid() + user_name = pwd.getpwuid(user_id).pw_name + group_id = os.getgid() + group_name = grp.getgrgid(group_id).gr_name + try: with open(cfg_out, 'a') as fp: - print >> fp, 'VAR_PREFIX = "%s"' % var_prefix + print >> fp, 'VAR_DIR = "%s"' % var_dir + print >> fp, 'MAILMAN_USER = "%s"' % user_name + print >> fp, 'MAILMAN_UID = %d' % user_id + print >> fp, 'MAILMAN_GROUP = "%s"' % group_name + print >> fp, 'MAILMAN_GID = %d' % group_id + print >> fp, "LANGUAGES = 'en'" initialize_1(cfg_out, propagate_logs=opts.stderr) mailman_uid = pwd.getpwnam(config.MAILMAN_USER).pw_uid @@ -216,7 +226,7 @@ def main(): results = runner.run(suite(args)) finally: os.remove(cfg_out) - shutil.rmtree(var_prefix) + shutil.rmtree(var_dir) # Turn off coverage and print a report if opts.coverage: diff --git a/Mailman/bin/withlist.py b/Mailman/bin/withlist.py index ac1ab0aac..5e4655100 100644 --- a/Mailman/bin/withlist.py +++ b/Mailman/bin/withlist.py @@ -190,10 +190,6 @@ def main(): VERBOSE = not opts.quiet LOCK = opts.lock - # Append our bin directory to sys.path so that any withlist scripts living - # their can be simply imported. - sys.path.append(config.BIN_DIR) - # The default for interact is true unless -r was given if opts.interactive is None: if not opts.run: |
