sync mm2 hack script back from puppet, this is ridiculous authored by anarcat's avatar anarcat
...@@ -703,8 +703,23 @@ The above assumes a `tpa.mm2_mm3_migration_cleanup` module in the ...@@ -703,8 +703,23 @@ The above assumes a `tpa.mm2_mm3_migration_cleanup` module in the
Python path, currently deployed in Puppet. Here's a backup copy: Python path, currently deployed in Puppet. Here's a backup copy:
```python ```python
#!/usr/bin/python2
"""Check and cleanup a Mailman 2 mailing list before migration to Mailman 3"""
from __future__ import print_function from __future__ import print_function
import cPickle
import logging
import os.path
from Mailman import Pending
from Mailman import mm_cfg
logging.basicConfig(level="INFO")
def check_bounce_info(mlist): def check_bounce_info(mlist):
print(mlist.bounce_info) print(mlist.bounce_info)
...@@ -724,6 +739,63 @@ def list_pending_reqs_owners(mlist): ...@@ -724,6 +739,63 @@ def list_pending_reqs_owners(mlist):
def flush_digest_mbox(mlist): def flush_digest_mbox(mlist):
mlist.send_digest_now() mlist.send_digest_now()
# stolen from fabric_tpa.ui
def yes_no(prompt):
"""ask a yes/no question, defaulting to yes. Return False on no, True on yes"""
while True:
res = raw_input(prompt + "\a [Y/n] ").lower()
if res and res not in "yn":
print("invalid response, must be one of y or n")
continue
if not res or res != "n":
return True
break
return False
def pending(mlist):
"""crude commandline interface to the mailman2 moderation system
Part of this is inspired from:
https://esaurito.net/blog/posts/2010/04/approve_mailman/
"""
full_path = mlist.fullpath()
with open(os.path.join(full_path, "pending.pck")) as fp:
db = cPickle.load(fp)
logging.info("%d requests pending:", len(db))
for cookie,req in db.items():
logging.info("cookie %s is %r", cookie, req)
try:
op = req[0]
data = req[1:]
except KeyError:
logging.warning("skipping whatever the fuck this is: %r", req)
continue
except ValueError:
logging.warning("skipping op-less data: %r", req)
continue
except TypeError:
logging.warning("ignoring message type: %s", req)
continue
if op == Pending.HELD_MESSAGE:
id = data[0]
msg_path = "/var/lib/mailman/data/heldmsg-%s-%s.pck" % (mlist.internal_name(), id)
logging.info("loading email %s", msg_path)
try:
with open(msg_path) as fp:
msg_db = cPickle.load(fp)
except IOError as e:
logging.warning("skipping message %d: %s", id, e)
print(msg_db)
if yes_no("approve?"):
mlist.HandleRequest(id, mm_cfg.APPROVE)
logging.info("approved")
else:
logging.info("skipped")
else:
logging.warning("not sure what to do with message op %s" % op)
``` ```
It also assumes a `mm3_tweaks` on the Mailman 3 server, also in It also assumes a `mm3_tweaks` on the Mailman 3 server, also in
... ...
......