~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:16:32 UTC
  • Revision ID: william.grant@canonical.com-20120123001632-z6dig91md7qu91f6
Date filtering.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    SystemManager,
29
29
    TIME_UUID_TYPE,
30
30
    )
 
31
from pycassa.util import convert_time_to_uuid
31
32
 
32
33
from grackle.cassandra import workaround_1779
33
34
 
87
88
    return time.mktime(_utc_datetime(dt).timetuple()) - time.timezone
88
89
 
89
90
 
 
91
def _utc_timeuuid(dt, lowest_val=True):
 
92
    return convert_time_to_uuid(_utc_timestamp(dt), lowest_val)
 
93
 
 
94
 
 
95
def _cmp_timeuuid(a, b):
 
96
    if a.time != b.time:
 
97
        return cmp(a.time, b.time)
 
98
    return cmp(a, b)
 
99
 
 
100
 
 
101
def _bound_timeuuid(a, b, max=False):
 
102
    if a == '' or _cmp_timeuuid(b, a) == (1 if max else -1):
 
103
        return b
 
104
    return a
 
105
 
 
106
 
90
107
class CassandraConnection(object):
91
108
 
92
109
    def __init__(self, keyspace, host):
136
153
        else:
137
154
            return sequence[1:]
138
155
 
139
 
    def get_messages(self, archive_uuid, order, count, memo, backward=False):
 
156
    def get_messages(self, archive_uuid, order, count, memo, backward=False,
 
157
                     start_date=None, finish_date=None):
140
158
        if order in ("date", "-date"):
141
159
            reversed = order[0] == '-'
142
160
        else:
149
167
        else:
150
168
            start = memo
151
169
            finish = ''
 
170
        if start_date is not None:
 
171
            start = _bound_timeuuid(
 
172
                start, _utc_timeuuid(start_date, lowest_val=False), max=True)
 
173
        if finish_date is not None:
 
174
            finish = _bound_timeuuid(
 
175
                finish, _utc_timeuuid(finish_date, lowest_val=False))
152
176
 
153
177
        # Get up to n+1 messages from the memo: the last item of the
154
178
        # previous batch (because that's where the memo starts) + this