From 03713f4a0ec061a1c03f4a2eeec9e4d73d7ec96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Stadler?= Date: Wed, 21 Nov 2007 10:47:40 +0200 Subject: [PATCH] Add LogLines class --- debug-viewer/GstDebugViewer/Data.py | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/debug-viewer/GstDebugViewer/Data.py b/debug-viewer/GstDebugViewer/Data.py index ba4c14912a..fa12f564d2 100644 --- a/debug-viewer/GstDebugViewer/Data.py +++ b/debug-viewer/GstDebugViewer/Data.py @@ -300,6 +300,35 @@ class LogLine (list): category, filename, line, function, object_, message,) +class LogLines (object): + + def __init__ (self, fileobj, line_cache): + + self.__fileobj = fileobj + self.__line_cache = line_cache + + def __len__ (self): + + return len (self.__line_cache.offsets) + + def __getitem__ (self, line_index): + + offset = self.__line_cache.offsets[line_index] + self.__fileobj.seek (offset) + line_string = self.__fileobj.readline () + line = LogLine.parse_full (line_string) + msg = line_string[line[-1]:] + line[-1] = msg + return line + + def __iter__ (self): + + l = len (self) + i = 0 + while i < l: + yield self[i] + i += 1 + class LogFile (Producer): def __init__ (self, filename, dispatcher): @@ -338,6 +367,8 @@ class LogFile (Producer): def handle_load_finished (self): + self.lines = LogLines (self.fileobj, self.line_cache) + # Chain up to our consumers: self.have_load_finished ()