diff --git a/.gitignore b/.gitignore index cbbb925b8c..1a70ca118c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ *~ /zephyrdb /all_messages_log.* +/event_log/* /server.log *.sw[po] diff --git a/humbug/settings.py b/humbug/settings.py index 59d72397c2..2bc1a5a582 100644 --- a/humbug/settings.py +++ b/humbug/settings.py @@ -263,7 +263,7 @@ DEFAULT_FROM_EMAIL = "Humbug " LOGIN_REDIRECT_URL='/' -MESSAGE_LOG="all_messages_log." + platform.node() +EVENT_LOG_DIR = 'event_log' # Polling timeout for get_updates, in milliseconds. # We configure this here so that the client test suite can override it. diff --git a/humbug/test_settings.py b/humbug/test_settings.py index 01ec49292e..a1d59e1fad 100644 --- a/humbug/test_settings.py +++ b/humbug/test_settings.py @@ -19,7 +19,7 @@ POLL_TIMEOUT = 1000 ENABLE_NOTIFICATIONS = False # Don't use the real message log for tests -MESSAGE_LOG = "/tmp/test-message-log" +EVENT_LOG_DIR = '/tmp/humbug-test-event-log' # Print our emails rather than sending them EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' diff --git a/zephyr/lib/actions.py b/zephyr/lib/actions.py index b0591331e3..8d47d566cc 100644 --- a/zephyr/lib/actions.py +++ b/zephyr/lib/actions.py @@ -21,13 +21,25 @@ import re import requests import hashlib import base64 +import datetime +import os +import platform +from os import path # Store an event in the log for re-importing messages def log_event(event): if "timestamp" not in event: event["timestamp"] = time.time() - with lockfile(settings.MESSAGE_LOG + '.lock'): - with open(settings.MESSAGE_LOG, 'a') as log: + + if not path.exists(settings.EVENT_LOG_DIR): + os.mkdir(settings.EVENT_LOG_DIR) + + template = path.join(settings.EVENT_LOG_DIR, + '%s.' + platform.node() + + datetime.datetime.now().strftime('.%Y-%m-%d')) + + with lockfile(template % ('lock',)): + with open(template % ('events',), 'a') as log: log.write(simplejson.dumps(event) + '\n') # create_user_hack is the same as Django's User.objects.create_user, diff --git a/zephyr/management/commands/populate_db.py b/zephyr/management/commands/populate_db.py index 79a162e3b0..e5738149d9 100644 --- a/zephyr/management/commands/populate_db.py +++ b/zephyr/management/commands/populate_db.py @@ -20,8 +20,10 @@ from zephyr.models import MAX_MESSAGE_LENGTH import simplejson import datetime import random +import glob import sys import os +from os import path from optparse import make_option settings.TORNADO_SERVER = None @@ -352,9 +354,11 @@ def restore_saved_messages(): else: raise ValueError('Bad message type') - with file(settings.MESSAGE_LOG, "r") as message_log: - for line in message_log.readlines(): - process_line(line) + event_glob = path.join(settings.EVENT_LOG_DIR, 'events.*') + for filename in sorted(glob.glob(event_glob)): + with file(filename, "r") as message_log: + for line in message_log.readlines(): + process_line(line) stream_recipients = {} user_recipients = {}