summaryrefslogtreecommitdiff
path: root/Mailman/bin/genaliases.py
diff options
context:
space:
mode:
authorbwarsaw2006-09-25 00:01:06 +0000
committerbwarsaw2006-09-25 00:01:06 +0000
commit8157935353a960cd03a72e403e8638b016c8e9a1 (patch)
tree00e219530cab575a9d2ec76ee9c90523d14a5275 /Mailman/bin/genaliases.py
parent99a4f0ef16e6dfddafbd396896afb97821528f16 (diff)
downloadmailman-8157935353a960cd03a72e403e8638b016c8e9a1.tar.gz
mailman-8157935353a960cd03a72e403e8638b016c8e9a1.tar.zst
mailman-8157935353a960cd03a72e403e8638b016c8e9a1.zip
Convert genaliases to mmshell, optparse, and configuration.config
bin/withlist: If there's no '@' in the listname, append the DEFAULT_EMAIL_HOST so we always get a fully qualified list name. bin/mmsitepass: plumb through -C/--config switch and be sure to call config.load(). Convert Mailman/MTA/Postfix.py to configuration.config, and update MTA/Manual. In mailman/Cgi/create, we can't convert straight from a string to a bool, because bool('0') is True. We need to go through int first. MailList.InitTempVars(): The logic here looked weird because we could get 'name' = None and that would break. Assume name is never None.
Diffstat (limited to 'Mailman/bin/genaliases.py')
-rw-r--r--Mailman/bin/genaliases.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/Mailman/bin/genaliases.py b/Mailman/bin/genaliases.py
new file mode 100644
index 000000000..379b4bd94
--- /dev/null
+++ b/Mailman/bin/genaliases.py
@@ -0,0 +1,94 @@
+#! @PYTHON@
+#
+# Copyright (C) 2001-2006 by the Free Software Foundation, Inc.
+#
+# This program 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 2
+# of the License, or (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
+
+import os
+import sys
+import optparse
+
+from Mailman import MailList
+from Mailman import Utils
+from Mailman import Version
+from Mailman.configuration import config
+from Mailman.i18n import _
+
+__i18n_templates__ = True
+
+
+
+def parseargs():
+ parser = optparse.OptionParser(version=Version.MAILMAN_VERSION,
+ usage=_("""\
+%prog [options]
+
+Regenerate the Mailman specific MTA aliases from scratch. The actual output
+depends on the value of the 'MTA' variable in your etc/mailman.cfg file."""))
+ parser.add_option('-q', '--quiet',
+ default=False, action='store_true', help=_("""\
+Some MTA output can include more verbose help text. Use this to tone down the
+verbosity."""))
+ parser.add_option('-C', '--config',
+ help=_('Alternative configuration file to use'))
+ opts, args = parser.parse_args()
+ if args:
+ parser.print_help()
+ print >> sys.stderr, _('Unexpected arguments')
+ sys.exit(1)
+ return parser, opts, args
+
+
+
+def main():
+ parser, opts, args = parseargs()
+ config.load(opts.config)
+
+ # Import the MTA specific module
+ modulename = 'Mailman.MTA.' + config.MTA
+ __import__(modulename)
+ MTA = sys.modules[modulename]
+
+ # We need to acquire a lock so nobody tries to update the files while
+ # we're doing it.
+ lock = MTA.makelock()
+ lock.lock()
+ # Group lists by virtual hostname
+ mlists = {}
+ for listname in Utils.list_names():
+ mlist = MailList.MailList(listname, lock=False)
+ mlists.setdefault(mlist.host_name, []).append(mlist)
+ # Make sure the files are created rw-rw-xxx; it should be okay to be world
+ # readable.
+ omask = os.umask(002)
+ try:
+ MTA.clear()
+ if not mlists:
+ MTA.create(None, nolock=True, quiet=opts.quiet)
+ else:
+ for hostname, vlists in mlists.items():
+ for mlist in vlists:
+ MTA.create(mlist, nolock=True, quiet=opts.quiet)
+ # Be verbose for only the first printed list
+ quiet = True
+ finally:
+ os.umask(omask)
+ lock.unlock(unconditionally=True)
+
+
+
+if __name__ == '__main__':
+ main()