]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
parsearchive: Support maildirs
authorStephen Finucane <stephen@that.guru>
Sun, 9 Apr 2017 17:14:03 +0000 (18:14 +0100)
committerStephen Finucane <stephen@that.guru>
Sat, 15 Apr 2017 00:40:57 +0000 (01:40 +0100)
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 <stephen@that.guru>
Suggested-by: Daniel Axtens <dja@axtens.net>
patchwork/bin/parsemail-batch.sh
patchwork/management/commands/parsearchive.py

index d42712ed099507c10cee0539b7696a47ca78a478..3d3725c6f792a6ff182d7d29a26fdac68057a4d0 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 #
 # Patchwork - automated patch tracking system
-# Copyright (C) 2008 Jeremy Kerr <jk@ozlabs.org>
+# Copyright (C) 2017 Stephen Finucane <stephen@that.guru>
 #
 # This file is part of the Patchwork package.
 #
 # 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 <dir> [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 "$@"
index 40b2cc02a00e11b078d5130a66eb8d0f685b7fd0..a3c8360186c885d35da8e94c14c4fcbfde306299 100644 (file)
@@ -69,7 +69,12 @@ class Command(BaseCommand):
             self.stdout.write('Invalid path: %s' % path)
             sys.exit(1)
 
-        mbox = mailbox.mbox(path)
+        # assume if <infile> 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)