From: Stephen Finucane Date: Wed, 15 Apr 2015 15:44:23 +0000 (+0100) Subject: bin/parsearchive: Add rudimentary archive parsing X-Git-Tag: v1.1.0~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6151c2f8a219893969d66397da13c299d2135904;p=thirdparty%2Fpatchwork.git bin/parsearchive: Add rudimentary archive parsing Add simple parsing of mbox archive files, as downloaded from a Mailman instance. Currently this does not report errors or provide statistics of any form. Signed-off-by: Stephen Finucane --- diff --git a/patchwork/bin/parsearchive.py b/patchwork/bin/parsearchive.py new file mode 100755 index 00000000..94d898a9 --- /dev/null +++ b/patchwork/bin/parsearchive.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# +# Patchwork - automated patch tracking system +# Copyright (C) 2015 Intel Corporation +# +# This file is part of the Patchwork package. +# +# Patchwork 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. +# +# Patchwork 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 Patchwork; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +"""Utility to parse an mbox archive file.""" + +import argparse +import logging +import mailbox + +import django + +import parsemail + +VERBOSITY_LEVELS = { + 'debug': logging.DEBUG, + 'info': logging.INFO, + 'warning': logging.WARNING, + 'error': logging.ERROR, + 'critical': logging.CRITICAL +} + + +def parse_mbox(path, list_id): + mbox = mailbox.mbox(path) + for msg in mbox: + parsemail.parse_mail(msg, list_id) + + +def main(): + django.setup() + parser = argparse.ArgumentParser(description=__doc__) + + def list_logging_levels(): + """Give a summary of all available logging levels.""" + return sorted(VERBOSITY_LEVELS.keys(), + key=lambda x: VERBOSITY_LEVELS[x]) + + parser.add_argument('inpath', help='input mbox filename') + + group = parser.add_argument_group('Mail parsing configuration') + group.add_argument('--list-id', help='mailing list ID. If not supplied ' + 'this will be extracted from the mail headers.') + group.add_argument('--verbosity', choices=list_logging_levels(), + help='debug level', default=logging.INFO) + + args = vars(parser.parse_args()) + + logging.basicConfig(level=args['verbosity']) + + parse_mbox(args['inpath'], args['list_id']) + +if __name__ == '__main__': + main()