summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander2015-02-04 16:06:25 +0000
committerMagnus Hagander2015-02-04 16:06:25 +0000
commit381c3d0ed2ccebd3444d84f9219f7ee981cfe374 (patch)
tree5dd0a8a08bfaf7ac78394ac537fd2d8e192f8663
parent619798df41c3749c1ae712f7d4c6afda8d7fd2e8 (diff)
Use proper logging from cronjobs
This makes it reasonable to redirect it to a file (it now has timestamps), and also adds the -debug parameter to get more logging when actually testing something out
-rwxr-xr-xtools/commitfest/check_patches_in_archives.py18
-rwxr-xr-xtools/commitfest/update_archive_threads.py13
2 files changed, 28 insertions, 3 deletions
diff --git a/tools/commitfest/check_patches_in_archives.py b/tools/commitfest/check_patches_in_archives.py
index 2429e27..ddbcb0a 100755
--- a/tools/commitfest/check_patches_in_archives.py
+++ b/tools/commitfest/check_patches_in_archives.py
@@ -12,6 +12,7 @@ import sys
import socket
import httplib
import magic
+import logging
# Set up for accessing django
from django.core.management import setup_environ
@@ -24,10 +25,18 @@ from django.db import connection
from commitfest.models import MailThreadAttachment
if __name__ == "__main__":
+ debug = "--debug" in sys.argv
+
+ # Logging always done to stdout, but we can turn on/off how much
+ logging.basicConfig(format='%(asctime)s %(levelname)s: %(msg)s',
+ level=debug and logging.DEBUG or logging.INFO)
+
socket.setdefaulttimeout(settings.ARCHIVES_TIMEOUT)
mag = magic.open(magic.MIME)
mag.load()
-
+
+ logging.debug("Updating attachment metadata from archives")
+
# Try to fetch/scan all attachments that haven't already been scanned.
# If they have already been scanned, we don't bother.
# We will hit the archives without delay when doing this, but that
@@ -35,6 +44,8 @@ if __name__ == "__main__":
# downloading a lot...
for a in MailThreadAttachment.objects.filter(ispatch=None):
url = "/message-id/attachment/%s/attach" % a.attachmentid
+ logging.debug("Checking attachment %s" % a.attachmentid)
+
h = httplib.HTTPConnection(settings.ARCHIVES_SERVER,
settings.ARCHIVES_PORT,
True,
@@ -44,7 +55,7 @@ if __name__ == "__main__":
})
resp = h.getresponse()
if resp.status != 200:
- print "Failed to get %s: %s" % (url, resp.status)
+ logging.error("Failed to get %s: %s" % (url, resp.status))
continue
contents = resp.read()
@@ -53,6 +64,7 @@ if __name__ == "__main__":
# Attempt to identify the file using magic information
mtype = mag.buffer(contents)
+ logging.debug("Detected MIME type is %s" % mtype)
# We don't support gzipped or tar:ed patches or anything like
# that at this point - just plain patches.
@@ -60,6 +72,8 @@ if __name__ == "__main__":
a.ispatch = True
else:
a.ispatch = False
+ logging.info("Attachment %s is patch: %s" % (a.id, a.ispatch))
a.save()
connection.close()
+ logging.debug("Done.")
diff --git a/tools/commitfest/update_archive_threads.py b/tools/commitfest/update_archive_threads.py
index ace46f4..bc42085 100755
--- a/tools/commitfest/update_archive_threads.py
+++ b/tools/commitfest/update_archive_threads.py
@@ -8,6 +8,7 @@
import os
import sys
+import logging
# Set up for accessing django
from django.core.management import setup_environ
@@ -21,11 +22,19 @@ from commitfest.models import MailThread
from commitfest.ajax import _archivesAPI, parse_and_add_attachments
if __name__ == "__main__":
+ debug = "--debug" in sys.argv
+
+ # Logging always done to stdout, but we can turn on/off how much
+ logging.basicConfig(format='%(asctime)s %(levelname)s: %(msg)s',
+ level=debug and logging.DEBUG or logging.INFO)
+
+ logging.debug("Checking for updated mail threads in the archives")
for thread in MailThread.objects.filter(patches__commitfests__status__in=(1,2,3)).distinct():
+ logging.debug("Checking %s in the archives" % 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
+ logging.info("Thread %s updated" % thread.messageid)
thread.latestmsgid = r[-1]['msgid']
thread.latestmessage = r[-1]['date']
thread.latestauthor = r[-1]['from']
@@ -35,7 +44,9 @@ if __name__ == "__main__":
# 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):
+ logging.debug("Last mail time updated for %s" % thread.messageid)
p.lastmail = thread.latestmessage
p.save()
connection.close()
+ logging.debug("Done.")