class EventInserter(): BUFFER_SIZE = 1000 _log = None _buffer = None _events_inserted = None def __init__(self): self._log = ZeitgeistDBusInterface() self._buffer = [] self._events_inserted = 0 def insert(self, event): buffer_full = len(self._buffer) >= self.BUFFER_SIZE if buffer_full: self.flush() self._buffer.append(event) return buffer_full def flush(self): if self._buffer: self._log.InsertEvents(self._buffer) self._events_inserted += len(self._buffer) self._buffer = [] def get_insertion_count(self): return self._events_inserted
def insert_events(events): iface = ZeitgeistDBusInterface() print "Inserting %d events..." % len(events) while len(events): iface.InsertEvents(events[:LIMIT]) events = events[LIMIT:] print "." print 'OK.'