From: Stephen Finucane Date: Sun, 9 Apr 2017 17:14:03 +0000 (+0100) Subject: parsearchive: Support maildirs X-Git-Tag: v2.0.0-rc1~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=919962620a9986f1fde7cba1b4a13998ccc2b7b7;p=thirdparty%2Fpatchwork.git parsearchive: Support maildirs At present, the 'parsearchive' command only supports parsing of mboxes. Expand this to support maildirs. This allows us to rewrite the 'parsemail-bulk' script to deliver much improved performance. Signed-off-by: Stephen Finucane Suggested-by: Daniel Axtens --- diff --git a/patchwork/bin/parsemail-batch.sh b/patchwork/bin/parsemail-batch.sh index d42712ed..3d3725c6 100755 --- a/patchwork/bin/parsemail-batch.sh +++ b/patchwork/bin/parsemail-batch.sh @@ -1,7 +1,7 @@ #!/bin/sh # # Patchwork - automated patch tracking system -# Copyright (C) 2008 Jeremy Kerr +# Copyright (C) 2017 Stephen Finucane # # This file is part of the Patchwork package. # @@ -20,25 +20,16 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA BIN_DIR=$(dirname "$0") +PATCHWORK_BASE=$(readlink -e "$BIN_DIR/../..") -if [ $# -lt 1 ]; then - echo "usage: $0 [options]" >&2 - exit 1 +if [ -z "$PW_PYTHON" ]; then + PW_PYTHON=python2 fi -mail_dir="$1" - -echo "dir: $mail_dir" - -if [ ! -d "$mail_dir" ]; then - echo "$mail_dir should be a directory"? >&2 - exit 1 +if [ -z "$DJANGO_SETTINGS_MODULE" ]; then + DJANGO_SETTINGS_MODULE=patchwork.settings.production fi -shift - -find "$mail_dir" -maxdepth 1 | -while read -r line; do - echo "$line" - "$BIN_DIR/parsemail.sh" "$@" < "$line" -done +PYTHONPATH="${PATCHWORK_BASE}:${PATCHWORK_BASE}/lib/python:$PYTHONPATH" \ + DJANGO_SETTINGS_MODULE="$DJANGO_SETTINGS_MODULE" \ + "$PW_PYTHON" "$PATCHWORK_BASE/manage.py" parsearchive "$@" diff --git a/patchwork/management/commands/parsearchive.py b/patchwork/management/commands/parsearchive.py index 40b2cc02..a3c83601 100644 --- a/patchwork/management/commands/parsearchive.py +++ b/patchwork/management/commands/parsearchive.py @@ -69,7 +69,12 @@ class Command(BaseCommand): self.stdout.write('Invalid path: %s' % path) sys.exit(1) - mbox = mailbox.mbox(path) + # assume if is a directory, then we're passing a maildir + if os.path.isfile(path): + mbox = mailbox.mbox(path) + else: + mbox = mailbox.Maildir(path) + count = len(mbox) logger.info('Parsing %d mails', count)