summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorbwarsaw2001-05-10 22:38:40 +0000
committerbwarsaw2001-05-10 22:38:40 +0000
commit76f25eb9223417d34026e9ca39937969027cd52a (patch)
treeffc69813904bc99e5edc7943569904b816ddfb9b /bin
parent00e48144b4fcb1ed7ebb2d153ee415913856279e (diff)
downloadmailman-76f25eb9223417d34026e9ca39937969027cd52a.tar.gz
mailman-76f25eb9223417d34026e9ca39937969027cd52a.tar.zst
mailman-76f25eb9223417d34026e9ca39937969027cd52a.zip
A script to regenerate both the data/aliases.db hash file and the
plain text data/aliases file for the Postfix MTA, using the known list of mailing lists. This overwrites the existing file contents and should be used if they get out of sync.
Diffstat (limited to 'bin')
-rw-r--r--bin/genaliases83
1 files changed, 83 insertions, 0 deletions
diff --git a/bin/genaliases b/bin/genaliases
new file mode 100644
index 000000000..a57c078bf
--- /dev/null
+++ b/bin/genaliases
@@ -0,0 +1,83 @@
+#! /usr/bin/env python
+#
+# Copyright (C) 2001 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+"""Regenerate Postfix's data/aliases and data/aliases.db files from scratch.
+
+Usage:
+
+ genaliases [options]
+
+Options:
+
+ --help/-h
+ Print this message and exit.
+"""
+
+import sys
+import getopt
+import dbhash
+
+import paths # path hacking
+from Mailman import Utils
+from Mailman import MailList
+from Mailman.MTA import Postfix
+from Mailman.i18n import _
+
+
+
+def usage(code, msg=''):
+ print >> sys.stderr, _(__doc__)
+ if msg:
+ print >> sys.stderr, msg
+ sys.exit(code)
+
+
+
+def main():
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], 'h', ['help'])
+ except getopt.error, msg:
+ usage(1, msg)
+
+ for opt, arg in opts:
+ if opt in ('-h', '--help'):
+ usage(0)
+
+ if args:
+ usage(1)
+
+ # Open the text file and dbhash files, truncating any data already there.
+ # We need to acquire a lock so nobody tries to update the files while
+ # we're doing it.
+ lock = Postfix.makelock()
+ lock.lock()
+ try:
+ db = dbhash.open(Postfix.DBFILE, 'n')
+ fp = open(Postfix.TEXTFILE, 'w')
+ for listname in Utils.list_names():
+ mlist = MailList.MailList(listname, lock=0)
+ Postfix.addlist(mlist, db, fp)
+ db.sync()
+ fp.close()
+ finally:
+ lock.unlock(unconditionally=1)
+
+
+
+if __name__ == '__main__':
+ main()