summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander2014-07-15 10:42:24 +0000
committerMagnus Hagander2014-07-15 10:42:24 +0000
commit4ef258394dbd79aebf63f3981700c6b305190bf5 (patch)
tree32b68ad961ccd2ee4cf8b1a34c7f38883c132488
parent998c9c275d477cd506e9fce9ea95364e3e6e2d7b (diff)
Add script to regularly update mail threads from the archives
-rwxr-xr-xtools/commitfest/update_archive_threads.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/commitfest/update_archive_threads.py b/tools/commitfest/update_archive_threads.py
new file mode 100755
index 0000000..a8d5876
--- /dev/null
+++ b/tools/commitfest/update_archive_threads.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+#
+# Update all attached mail threads from the archives.
+#
+# XXX: at some point we probably need to limit this so we don't hit all of them,
+# at least not all of them all the time...
+#
+
+import os
+import sys
+
+# Set up for accessing django
+from django.core.management import setup_environ
+sys.path.append(os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), '../../pgcommitfest'))
+import settings
+setup_environ(settings)
+
+from django.db import connection
+
+from commitfest.models import MailThread
+from commitfest.ajax import _archivesAPI, parse_and_add_attachments
+
+if __name__ == "__main__":
+ for thread in MailThread.objects.filter(patches__commitfests__status__in=(1,2,3)).distinct():
+ print "Attempt to update thread %s" % thread.messageid
+ r = sorted(_archivesAPI('/message-id.json/%s' % thread.messageid), key=lambda x: x['date'])
+ if thread.latestmsgid != r[-1]['msgid']:
+ # There is now a newer mail in the thread!
+ print "Thread %s updated" % thread.messageid
+ thread.latestmsgid = r[-1]['msgid']
+ thread.latestmessage = r[-1]['date']
+ thread.latestauthor = r[-1]['from']
+ thread.latestsubject = r[-1]['subj']
+ thread.save()
+ parse_and_add_attachments(r, thread)
+ # Potentially update the last mail date - if there wasn't already a mail on each patch
+ # from a *different* thread that had an earlier date.
+ for p in thread.patches.filter(lastmail__lt=thread.latestmessage):
+ p.lastmail = thread.latestmessage
+ p.save()
+
+ connection.close()