~unity-2d-team/unity-2d/Shell-MultiMonitor

« back to all changes in this revision

Viewing changes to grackle/model.py

  • Committer: William Grant
  • Date: 2012-01-23 00:15:41 UTC
  • Revision ID: william.grant@canonical.com-20120123001541-opi3ememu13hg9jy
Use real UTC timestamps in the archive_message TimeUUIDs. pycassa's end up including the local timezone offset :/

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import email.parser
20
20
from email.utils import parsedate_tz
21
21
import logging
 
22
import time
22
23
import uuid
23
24
 
24
25
import pycassa
78
79
    return date, message_dict
79
80
 
80
81
 
 
82
def _utc_datetime(dt):
 
83
    return dt.astimezone(dateutil.tz.tzutc())
 
84
 
 
85
 
 
86
def _utc_timestamp(dt):
 
87
    return time.mktime(_utc_datetime(dt).timetuple()) - time.timezone
 
88
 
 
89
 
81
90
class CassandraConnection(object):
82
91
 
83
92
    def __init__(self, keyspace, host):
102
111
        self.messages.insert(message_uuid, message_dict)
103
112
        self.archive_messages.insert(
104
113
            archive_uuid,
105
 
            {message_date.astimezone(dateutil.tz.tzutc()): message_uuid})
 
114
            {_utc_timestamp(message_date): message_uuid})
106
115
        logging.debug(
107
116
            'Imported %s into %s'
108
117
            % (message_dict.get('message-id', None), archive_uuid))