#! /usr/bin/env python # # Copyright (C) 2011 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. """Dump Pipermail archive database files. Usage: %(PROGRAM)s [options] listname period Where: --verbose / -v Print the contents of the -article database entries instead of just listing them. --help / -h Print this message and exit. listname is the name of the list whos archive database files are to be dumped. period is the name of the archive volume whose database files are to be dumped. The form of this depends on the volume frequency as follows: archive_volume_frequency period form example Monthly (default) yyyy-Month 2011-January Yearly yyyy 2011 Quarterly yyyyq 20111 Weekly Week-of-Mon-yyyymmdd Week-of-Mon-20110103 Daily yyyymmdd 20110103 Each period in a list's archive has five database files in the archives/private/listname/database/ directory with names of the form period-type where period is as above and type is one of date, author, subject, thread or article. The first four contain the Message-IDs of the messages in that period in the order of that type. The article database also contains one entry per message, but with additional information about the message in the archive. This program simply prints the number of messages in this database, the time stamp of the first message, a list of the Message-IDs in each of the first four databases and either a list of or with the verbose option, the contents of the entries in the article database. """ import os import sys import getopt import pprint import cPickle import paths from Mailman import mm_cfg from Mailman import Errors from Mailman.i18n import _ from Mailman.MailList import MailList from Mailman.Archiver import HyperDatabase 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(): verbose = False try: opts, args = getopt.getopt(sys.argv[1:], 'vh', ['verbose', 'help']) except getopt.error, msg: usage(1, msg) for opt, arg in opts: if opt in ('-v', '--verbose'): verbose = True if opt in ('-h', '--help'): usage(0) if len(args) <> 2: usage(1, _('Exactly two arguments required')) listname = args[0] period = args[1] try: mlist = MailList(listname, lock=False) except Errors.MMListError: usage(2, _('No such list: %(listname)s')) basedir = os.path.join(mm_cfg.PRIVATE_ARCHIVE_FILE_DIR, mlist.internal_name()) if not os.path.isfile(os.path.join(basedir, 'database', period + '-date')): usage(2, _('%(period)s is not in the archive.')) pp = pprint.PrettyPrinter(indent=4) try: ad = HyperDatabase.HyperDatabase(basedir, mlist) fd = ad.firstdate(period) print _('First date = %(fd)s') na = ad.numArticles(period) print _('Number of articles = %(na)s') for i in ('date', 'author', 'subject', 'thread', 'article'): print '\n\n %s' % i x = ad.first(period, i) while x: if i == 'article': x = cPickle.loads(x) if verbose: pp.pprint(x.__dict__) print else: print x else: print x x = ad.next(period, i) finally: ad.close() if __name__ == '__main__': main()