[PATCH 4/4] bin/parsearchive: Add rudimentary archive parsing
Stephen Finucane
stephen.finucane at intel.com
Fri Nov 13 14:48:07 AEDT 2015
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 <stephen.finucane at intel.com>
---
patchwork/bin/parsearchive.py | 71 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
create mode 100755 patchwork/bin/parsearchive.py
diff --git a/patchwork/bin/parsearchive.py b/patchwork/bin/parsearchive.py
new file mode 100755
index 0000000..94d898a
--- /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()
--
2.0.0
More information about the Patchwork
mailing list