2
# Copyright 2008 Canonical Ltd. All rights reserved.
10
# pylint: disable-msg=W0403
13
from canonical.config import config
14
from canonical.launchpad.scripts.base import LaunchpadScript
17
class MailingListSyncScript(LaunchpadScript):
21
Sync the mailing list data structures with the database. This is
22
necessary for example when the production database is copied to staging.
24
XXX For now, we /know/ that production has no databases, so this script
25
takes the cheap way out by deleting all lists except the site list.
28
loglevel = logging.INFO
29
description = 'Sync the Mailman data structures with the database.'
32
self.usage = textwrap.dedent(self.__doc__)
33
super(MailingListSyncScript, self).__init__('scripts.mlist_sync')
35
def add_my_options(self):
36
self.parser.add_option('-n', '--dry-run',
37
default=False, action='store_true', help="""\
38
Show the lists that would be deleted, but do not delete them.""")
41
"""See `LaunchpadScript`."""
42
if len(self.args) != 0:
43
self.parser.error('Too many arguments')
45
# Set up access to the Mailman package and import the defaults.
46
mailman_path = config.mailman.build.prefix
47
mailman_bin = os.path.join(mailman_path, 'bin')
48
sys.path.append(mailman_path)
49
from Mailman import mm_cfg
50
from Mailman import Utils
52
deletable_lists = set(Utils.list_names())
53
deletable_lists.remove(mm_cfg.MAILMAN_SITE_LIST)
54
if len(deletable_lists) == 0:
55
print 'Nothing to do.'
58
if self.options.dry_run:
59
print 'Lists that would be deleted:'
60
for list_name in sorted(deletable_lists):
64
# Deleting lists is done with the rmlist script, which unfortunately
65
# is not importable in Mailman 2.1. Because we also want to
66
# completely delete the archives, we'll just shell out to rmlist.
68
for list_name in sorted(deletable_lists):
69
print 'Removing all traces of mailing list:', list_name
70
retcode = subprocess.call(
71
('./rmlist', '-a', list_name),
74
print >> sys.stderr, 'Could not delete list:', list_name
75
# For now, keep going.
80
if __name__ == '__main__':
81
script = MailingListSyncScript()