mirror of
https://github.com/fergalmoran/picard.git
synced 2026-03-25 22:55:15 +00:00
Make log.contents() a generator
This commit is contained in:
@@ -119,17 +119,15 @@ class TailLogger(QtCore.QObject):
|
||||
|
||||
def contents(self, prev=-1):
|
||||
with self._queue_lock:
|
||||
# If log queue is empty, return
|
||||
if not self._log_queue:
|
||||
return []
|
||||
offset, length = _calculate_bounds(prev, self._log_queue[0].pos, self._log_queue[-1].pos, len(self._log_queue))
|
||||
if self._log_queue:
|
||||
offset, length = _calculate_bounds(prev, self._log_queue[0].pos, self._log_queue[-1].pos, len(self._log_queue))
|
||||
|
||||
if offset >= 0:
|
||||
return (self._log_queue[i] for i in range(offset, length))
|
||||
# If offset < 0, there is a discontinuity in the queue positions
|
||||
# Use a slower approach to get the new content.
|
||||
else:
|
||||
return (x for x in self._log_queue if x.pos > prev)
|
||||
if offset >= 0:
|
||||
yield from (self._log_queue[i] for i in range(offset, length))
|
||||
# If offset < 0, there is a discontinuity in the queue positions
|
||||
# Use a slower approach to get the new content.
|
||||
else:
|
||||
yield from (x for x in self._log_queue if x.pos > prev)
|
||||
|
||||
def clear(self):
|
||||
with self._queue_lock:
|
||||
|
||||
Reference in New Issue
Block a user