#! /usr/bin/env python # # Copyright (C) 2016 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. """List various information about lists in the installation which have held posts older than some number of days. Usage: %(PROGRAM)s days Output from this script is for each list with held posts older than days: List: Held older than ddd days: nnn Date of oldest held: yyyy-mm-dd Date of most recent post: yyyy-mm-dd Owner: [owner addresses] Moderator: [moderator addresses] This script must run from Mailman's bin/ directory. """ import sys import time import paths from Mailman import MailList from Mailman.i18n import _ from Mailman.Utils import list_names PROGRAM = sys.argv[0] try: True, False except NameError: True = 1 False = 0 def usage(code, msg=''): if code: fd = sys.stderr else: fd = sys.stdout print >> fd, _(__doc__) if msg: print >> fd, msg sys.exit(code) def main(): if len(sys.argv) != 2: usage(1, 'Exactly 1 integer argument required.') if (sys.argv[1].lower().startswith('-h') or sys.argv[1].lower().startswith('--h')): usage(0) try: days = int(sys.argv[1]) except ValueError: usage(1, 'Exactly 1 integer argument required.') mintime = time.time() - (days * 24 * 3600) names = list_names() names.sort() for name in names: mlist = MailList.MailList(name, lock=True) helds = mlist.GetHeldMessageIds() olds = [] for id in helds: if mlist.GetRecord(id)[0] < mintime: olds.append(mlist.GetRecord(id)[0]) mlist.Unlock() if not olds: continue olds.sort() print 'List: %s' % mlist.real_name print 'Held older than %d days: %d' % (days, len(olds)) print time.strftime( 'Date of oldest held: %Y-%m-%d', time.localtime(olds[0]) ) print time.strftime( 'Date of most recent post: %Y-%m-%d', time.localtime(mlist.last_post_time) ) print 'Owner: %r' % mlist.owner print 'Moderator: %r' % mlist.moderator print if __name__ == '__main__': main()