Add a script to delete a mailing list from HyperKitty
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
This commit is contained in:
parent
380366d5ea
commit
0bca6042c3
2 changed files with 57 additions and 0 deletions
56
roles/mailman/files/hyperkitty-delete-list.py
Executable file
56
roles/mailman/files/hyperkitty-delete-list.py
Executable file
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env python2
|
||||
|
||||
"""
|
||||
Delete lists from HyperKitty
|
||||
|
||||
Author: Aurelien Bompard <abompard@fedoraproject.org>
|
||||
"""
|
||||
|
||||
from __future__ import (
|
||||
absolute_import, print_function, unicode_literals, division)
|
||||
|
||||
import os
|
||||
import logging
|
||||
import readline
|
||||
import sys
|
||||
from argparse import ArgumentParser
|
||||
|
||||
sys.path.insert(0, "/srv/webui/config")
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
|
||||
from django import setup
|
||||
|
||||
from hyperkitty.models import MailingList
|
||||
|
||||
|
||||
def delete_list(address):
|
||||
try:
|
||||
ml = MailingList.objects.get(name=address)
|
||||
except MailingList.DoesNotExist:
|
||||
print("Could not find a list with address \"{}\".".format(address))
|
||||
return
|
||||
print("The mailing-list \"{}\" ({}) will be entirely deleted.".format(ml.name, ml.list_id))
|
||||
print("It contains {} threads and {} emails.".format(ml.threads.count(), ml.emails.count()))
|
||||
prompt = "Are you sure? [y/N] ".format(ml.name, ml.list_id)
|
||||
response = raw_input(prompt)
|
||||
if response != "y":
|
||||
print("Not deleted.")
|
||||
return
|
||||
ml.delete()
|
||||
print("Mailing-list successfully deleted.")
|
||||
|
||||
def parse_args():
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("list_address", nargs="+", help="The mailing-list address")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
setup()
|
||||
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
||||
for address in args.list_address:
|
||||
delete_list(address)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -512,6 +512,7 @@
|
|||
- import-mm2.py
|
||||
- periodic.py
|
||||
- mailman-sar.py
|
||||
- hyperkitty-delete-list.py
|
||||
|
||||
- name: install the templatized scripts
|
||||
template: src={{ item }}.j2 dest="{{ mailman_webui_basedir }}/bin/{{ item }}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue