2009-08-06 23:54:10 +00:00
|
|
|
# -*- coding: utf-8; mode: python; -*-
|
|
|
|
#
|
|
|
|
# GStreamer Debug Viewer - View and analyze GStreamer debug log files
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 René Stadler <mail@renestadler.de>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License as published by the Free
|
|
|
|
# Software Foundation; either version 3 of the License, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
# more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""GStreamer Debug Viewer GUI module."""
|
|
|
|
|
2012-09-23 14:43:25 +00:00
|
|
|
from array import array
|
2009-08-06 23:54:10 +00:00
|
|
|
from bisect import bisect_left
|
|
|
|
import logging
|
|
|
|
|
2015-10-20 13:21:01 +00:00
|
|
|
from gi.repository import GObject
|
|
|
|
from gi.repository import Gtk
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
from GstDebugViewer import Common, Data
|
|
|
|
|
2015-10-20 13:21:01 +00:00
|
|
|
|
2018-04-14 13:22:11 +00:00
|
|
|
class LogModelBase (Common.GUI.GenericTreeModel, metaclass=Common.GUI.MetaModel):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2015-10-20 13:21:01 +00:00
|
|
|
columns = ("COL_TIME", GObject.TYPE_UINT64,
|
2009-08-06 23:54:10 +00:00
|
|
|
"COL_PID", int,
|
2015-10-20 13:21:01 +00:00
|
|
|
"COL_THREAD", GObject.TYPE_UINT64,
|
2009-08-06 23:54:10 +00:00
|
|
|
"COL_LEVEL", object,
|
|
|
|
"COL_CATEGORY", str,
|
|
|
|
"COL_FILENAME", str,
|
|
|
|
"COL_LINE_NUMBER", int,
|
|
|
|
"COL_FUNCTION", str,
|
|
|
|
"COL_OBJECT", str,
|
|
|
|
"COL_MESSAGE", str,)
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
Common.GUI.GenericTreeModel.__init__(self)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
# self.props.leak_references = False
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.line_offsets = array("I")
|
|
|
|
self.line_levels = [] # FIXME: Not so nice!
|
2009-08-06 23:54:10 +00:00
|
|
|
self.line_cache = {}
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def ensure_cached(self, line_offset):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
raise NotImplementedError("derived classes must override this method")
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def access_offset(self, offset):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
raise NotImplementedError("derived classes must override this method")
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def iter_rows_offset(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
ensure_cached = self.ensure_cached
|
|
|
|
line_cache = self.line_cache
|
|
|
|
line_levels = self.line_levels
|
|
|
|
COL_LEVEL = self.COL_LEVEL
|
2016-10-08 12:49:38 +00:00
|
|
|
COL_MESSAGE = self.COL_MESSAGE
|
|
|
|
access_offset = self.access_offset
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
for i, offset in enumerate(self.line_offsets):
|
|
|
|
ensure_cached(offset)
|
2009-08-06 23:54:10 +00:00
|
|
|
row = line_cache[offset]
|
2016-10-08 12:49:38 +00:00
|
|
|
# adjust special rows
|
|
|
|
row[COL_LEVEL] = line_levels[i]
|
2016-10-09 10:55:59 +00:00
|
|
|
msg_offset = row[COL_MESSAGE]
|
2018-04-14 15:04:22 +00:00
|
|
|
row[COL_MESSAGE] = access_offset(offset + msg_offset)
|
2009-08-06 23:54:10 +00:00
|
|
|
yield (row, offset,)
|
2016-10-09 10:55:59 +00:00
|
|
|
row[COL_MESSAGE] = msg_offset
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def on_get_flags(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2015-10-20 13:21:01 +00:00
|
|
|
flags = Gtk.TreeModelFlags.LIST_ONLY | Gtk.TreeModelFlags.ITERS_PERSIST
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
return flags
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def on_get_n_columns(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
return len(self.column_types)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def on_get_column_type(self, col_id):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
return self.column_types[col_id]
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def on_get_iter(self, path):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
if not path:
|
|
|
|
return
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
if len(path) > 1:
|
2009-08-06 23:54:10 +00:00
|
|
|
# Flat model.
|
|
|
|
return None
|
|
|
|
|
|
|
|
line_index = path[0]
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
if line_index > len(self.line_offsets) - 1:
|
2009-08-06 23:54:10 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
return line_index
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def on_get_path(self, rowref):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
line_index = rowref
|
|
|
|
|
|
|
|
return (line_index,)
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def on_get_value(self, line_index, col_id):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
last_index = len(self.line_offsets) - 1
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
if line_index > last_index:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if col_id == self.COL_LEVEL:
|
|
|
|
return self.line_levels[line_index]
|
|
|
|
|
|
|
|
line_offset = self.line_offsets[line_index]
|
2016-09-28 18:38:55 +00:00
|
|
|
self.ensure_cached(line_offset)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
value = self.line_cache[line_offset][col_id]
|
|
|
|
if col_id == self.COL_MESSAGE:
|
2016-10-09 10:55:59 +00:00
|
|
|
# strip whitespace + newline
|
|
|
|
value = self.access_offset(line_offset + value).strip()
|
2018-04-14 13:22:11 +00:00
|
|
|
elif col_id in (self.COL_TIME, self.COL_THREAD):
|
|
|
|
value = GObject.Value(GObject.TYPE_UINT64, value)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
return value
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def get_value_range(self, col_id, start, stop):
|
2012-09-21 20:52:25 +00:00
|
|
|
|
|
|
|
if col_id != self.COL_LEVEL:
|
2016-09-28 18:38:55 +00:00
|
|
|
raise NotImplementedError("XXX FIXME")
|
2012-09-21 20:52:25 +00:00
|
|
|
|
|
|
|
return self.line_levels[start:stop]
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def on_iter_next(self, line_index):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
last_index = len(self.line_offsets) - 1
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
if line_index >= last_index:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return line_index + 1
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def on_iter_children(self, parent):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
return self.on_iter_nth_child(parent, 0)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def on_iter_has_child(self, rowref):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
return False
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def on_iter_n_children(self, rowref):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
if rowref is not None:
|
|
|
|
return 0
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
return len(self.line_offsets)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def on_iter_nth_child(self, parent, n):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
last_index = len(self.line_offsets) - 1
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
if parent or n > last_index:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return n
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def on_iter_parent(self, child):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
return None
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
# def on_ref_node (self, rowref):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
# pass
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
# def on_unref_node (self, rowref):
|
|
|
|
|
|
|
|
# pass
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LazyLogModel (LogModelBase):
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self, log_obj=None):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
LogModelBase.__init__(self)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
self.__log_obj = log_obj
|
|
|
|
|
|
|
|
if log_obj:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.set_log(log_obj)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def set_log(self, log_obj):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
self.__fileobj = log_obj.fileobj
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.line_cache.clear()
|
2009-08-06 23:54:10 +00:00
|
|
|
self.line_offsets = log_obj.line_cache.offsets
|
|
|
|
self.line_levels = log_obj.line_cache.levels
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def access_offset(self, offset):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
# TODO: Implement using one slice access instead of seek+readline.
|
2016-09-28 18:38:55 +00:00
|
|
|
self.__fileobj.seek(offset)
|
|
|
|
return self.__fileobj.readline()
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def ensure_cached(self, line_offset):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
if line_offset in self.line_cache:
|
|
|
|
return
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
if len(self.line_cache) > 10000:
|
|
|
|
self.line_cache.clear()
|
|
|
|
|
|
|
|
self.__fileobj.seek(line_offset)
|
|
|
|
line = self.__fileobj.readline()
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.line_cache[line_offset] = Data.LogLine.parse_full(line)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FilteredLogModelBase (LogModelBase):
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self, super_model):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
LogModelBase.__init__(self)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger = logging.getLogger("filter-model-base")
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
self.super_model = super_model
|
|
|
|
self.access_offset = super_model.access_offset
|
|
|
|
self.ensure_cached = super_model.ensure_cached
|
|
|
|
self.line_cache = super_model.line_cache
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def line_index_to_super(self, line_index):
|
|
|
|
|
|
|
|
raise NotImplementedError("index conversion not supported")
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def line_index_from_super(self, super_line_index):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
raise NotImplementedError("index conversion not supported")
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FilteredLogModel (FilteredLogModelBase):
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self, super_model):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
FilteredLogModelBase.__init__(self, super_model)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger = logging.getLogger("filtered-log-model")
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
self.filters = []
|
2016-09-28 18:38:55 +00:00
|
|
|
self.reset()
|
2009-08-06 23:54:10 +00:00
|
|
|
self.__active_process = None
|
|
|
|
self.__filter_progress = 0.
|
2012-08-23 23:42:00 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def reset(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger.debug("reset filter")
|
2016-04-04 20:23:26 +00:00
|
|
|
|
2012-08-23 23:50:44 +00:00
|
|
|
self.line_offsets = self.super_model.line_offsets
|
|
|
|
self.line_levels = self.super_model.line_levels
|
2018-04-14 13:22:11 +00:00
|
|
|
self.super_index = range(len(self.line_offsets))
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
del self.filters[:]
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __filter_process(self, filter):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
YIELD_LIMIT = 10000
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger.debug("preparing new filter")
|
|
|
|
new_line_offsets = array("I")
|
2009-08-06 23:54:10 +00:00
|
|
|
new_line_levels = []
|
2016-09-28 18:38:55 +00:00
|
|
|
new_super_index = array("I")
|
2009-08-06 23:54:10 +00:00
|
|
|
level_id = self.COL_LEVEL
|
|
|
|
func = filter.filter_func
|
2016-09-28 18:38:55 +00:00
|
|
|
|
|
|
|
def enum():
|
2012-08-23 23:50:44 +00:00
|
|
|
i = 0
|
2016-09-28 18:38:55 +00:00
|
|
|
for row, offset in self.iter_rows_offset():
|
2012-08-23 23:50:44 +00:00
|
|
|
line_index = self.super_index[i]
|
|
|
|
yield (line_index, row, offset,)
|
|
|
|
i += 1
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger.debug("running filter")
|
2009-08-06 23:54:10 +00:00
|
|
|
progress = 0.
|
2016-09-28 18:38:55 +00:00
|
|
|
progress_full = float(len(self))
|
2009-08-06 23:54:10 +00:00
|
|
|
y = YIELD_LIMIT
|
2016-09-28 18:38:55 +00:00
|
|
|
for i, row, offset in enum():
|
|
|
|
if func(row):
|
|
|
|
new_line_offsets.append(offset)
|
|
|
|
new_line_levels.append(row[level_id])
|
|
|
|
new_super_index.append(i)
|
2009-08-06 23:54:10 +00:00
|
|
|
y -= 1
|
|
|
|
if y == 0:
|
2016-09-28 18:38:55 +00:00
|
|
|
progress += float(YIELD_LIMIT)
|
2009-08-06 23:54:10 +00:00
|
|
|
self.__filter_progress = progress / progress_full
|
|
|
|
y = YIELD_LIMIT
|
|
|
|
yield True
|
|
|
|
self.line_offsets = new_line_offsets
|
|
|
|
self.line_levels = new_line_levels
|
|
|
|
self.super_index = new_super_index
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger.debug("filtering finished")
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
self.__filter_progress = 1.
|
2016-09-28 18:38:55 +00:00
|
|
|
self.__handle_filter_process_finished()
|
2009-08-06 23:54:10 +00:00
|
|
|
yield False
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def add_filter(self, filter, dispatcher):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
if self.__active_process is not None:
|
2016-09-28 18:38:55 +00:00
|
|
|
raise ValueError("dispatched a filter process already")
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger.debug("adding filter")
|
2016-04-04 20:23:26 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.filters.append(filter)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
self.__dispatcher = dispatcher
|
2016-09-28 18:38:55 +00:00
|
|
|
self.__active_process = self.__filter_process(filter)
|
|
|
|
dispatcher(self.__active_process)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def abort_process(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
if self.__active_process is None:
|
2016-09-28 18:38:55 +00:00
|
|
|
raise ValueError("no filter process running")
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.__dispatcher.cancel()
|
2009-08-06 23:54:10 +00:00
|
|
|
self.__active_process = None
|
|
|
|
self.__dispatcher = None
|
|
|
|
|
|
|
|
del self.filters[-1]
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def get_filter_progress(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
if self.__active_process is None:
|
2016-09-28 18:38:55 +00:00
|
|
|
raise ValueError("no filter process running")
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
return self.__filter_progress
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __handle_filter_process_finished(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
self.__active_process = None
|
2016-09-28 18:38:55 +00:00
|
|
|
self.handle_process_finished()
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_process_finished(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
pass
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def line_index_from_super(self, super_line_index):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
return bisect_left(self.super_index, super_line_index)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def line_index_to_super(self, line_index):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
return self.super_index[line_index]
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def set_range(self, super_start, super_stop):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
old_super_start = self.line_index_to_super(0)
|
|
|
|
old_super_stop = self.line_index_to_super(
|
|
|
|
len(self.super_index) - 1) + 1
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger.debug("set range (%i, %i), current (%i, %i)",
|
|
|
|
super_start, super_stop, old_super_start, old_super_stop)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
if len(self.filters) == 0:
|
2012-08-23 23:50:44 +00:00
|
|
|
# Identity.
|
2018-04-14 13:22:11 +00:00
|
|
|
self.super_index = range(super_start, super_stop)
|
2016-09-28 18:38:55 +00:00
|
|
|
self.line_offsets = SubRange(self.super_model.line_offsets,
|
2012-08-23 23:50:44 +00:00
|
|
|
super_start, super_stop)
|
2016-09-28 18:38:55 +00:00
|
|
|
self.line_levels = SubRange(self.super_model.line_levels,
|
|
|
|
super_start, super_stop)
|
2012-08-23 23:40:24 +00:00
|
|
|
return
|
|
|
|
|
2012-08-23 23:50:44 +00:00
|
|
|
if super_start < old_super_start:
|
2009-08-06 23:54:10 +00:00
|
|
|
# TODO:
|
2016-09-28 18:38:55 +00:00
|
|
|
raise NotImplementedError("Only handling further restriction of the range"
|
2018-04-14 13:22:11 +00:00
|
|
|
" (start offset = %i)" % (super_start,))
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2012-08-23 23:50:44 +00:00
|
|
|
if super_stop > old_super_stop:
|
2009-08-06 23:54:10 +00:00
|
|
|
# TODO:
|
2016-09-28 18:38:55 +00:00
|
|
|
raise NotImplementedError("Only handling further restriction of the range"
|
2018-04-14 13:22:11 +00:00
|
|
|
" (end offset = %i)" % (super_stop,))
|
2016-09-28 18:38:55 +00:00
|
|
|
|
|
|
|
start = self.line_index_from_super(super_start)
|
|
|
|
stop = self.line_index_from_super(super_stop)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.super_index = SubRange(self.super_index, start, stop)
|
|
|
|
self.line_offsets = SubRange(self.line_offsets, start, stop)
|
|
|
|
self.line_levels = SubRange(self.line_levels, start, stop)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SubRange (object):
|
|
|
|
|
2018-04-14 15:04:22 +00:00
|
|
|
__slots__ = ("size", "start", "stop",)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2018-04-14 15:04:22 +00:00
|
|
|
def __init__(self, size, start, stop):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
if start > stop:
|
2016-09-28 18:38:55 +00:00
|
|
|
raise ValueError(
|
|
|
|
"need start <= stop (got %r, %r)" % (start, stop,))
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2018-04-14 15:04:22 +00:00
|
|
|
if type(size) == type(self):
|
2012-08-23 23:50:44 +00:00
|
|
|
# Another SubRange, don't stack:
|
2018-04-14 15:04:22 +00:00
|
|
|
start += size.start
|
|
|
|
stop += size.start
|
|
|
|
size = size.size
|
2012-08-23 23:50:44 +00:00
|
|
|
|
2018-04-14 15:04:22 +00:00
|
|
|
self.size = size
|
2009-08-06 23:54:10 +00:00
|
|
|
self.start = start
|
|
|
|
self.stop = stop
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __getitem__(self, i):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
if isinstance(i, slice):
|
2012-09-21 23:25:22 +00:00
|
|
|
stop = i.stop
|
|
|
|
if stop >= 0:
|
|
|
|
stop += self.start
|
|
|
|
else:
|
|
|
|
stop += self.stop
|
|
|
|
|
2018-04-14 15:04:22 +00:00
|
|
|
return self.size[i.start + self.start:stop]
|
2012-09-21 23:25:22 +00:00
|
|
|
else:
|
2018-04-14 15:04:22 +00:00
|
|
|
return self.size[i + self.start]
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __len__(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
return self.stop - self.start
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __iter__(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2018-04-14 15:04:22 +00:00
|
|
|
size = self.size
|
2018-04-14 13:22:11 +00:00
|
|
|
for i in range(self.start, self.stop):
|
2018-04-14 15:04:22 +00:00
|
|
|
yield size[i]
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
|
2009-08-06 23:54:10 +00:00
|
|
|
class LineViewLogModel (FilteredLogModelBase):
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self, super_model):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
FilteredLogModelBase.__init__(self, super_model)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
self.line_offsets = []
|
|
|
|
self.line_levels = []
|
|
|
|
|
|
|
|
self.parent_indices = []
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def reset(self):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
del self.line_offsets[:]
|
|
|
|
del self.line_levels[:]
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def line_index_to_super(self, line_index):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
return self.parent_indices[line_index]
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def insert_line(self, position, super_line_index):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
if position == -1:
|
2016-09-28 18:38:55 +00:00
|
|
|
position = len(self.line_offsets)
|
2009-08-06 23:54:10 +00:00
|
|
|
li = super_line_index
|
2016-09-28 18:38:55 +00:00
|
|
|
self.line_offsets.insert(position, self.super_model.line_offsets[li])
|
|
|
|
self.line_levels.insert(position, self.super_model.line_levels[li])
|
|
|
|
self.parent_indices.insert(position, super_line_index)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
path = (position,)
|
2016-09-28 18:38:55 +00:00
|
|
|
tree_iter = self.get_iter(path)
|
|
|
|
self.row_inserted(path, tree_iter)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def replace_line(self, line_index, super_line_index):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
li = line_index
|
|
|
|
self.line_offsets[li] = self.super_model.line_offsets[super_line_index]
|
|
|
|
self.line_levels[li] = self.super_model.line_levels[super_line_index]
|
|
|
|
self.parent_indices[li] = super_line_index
|
|
|
|
|
|
|
|
path = (line_index,)
|
2016-09-28 18:38:55 +00:00
|
|
|
tree_iter = self.get_iter(path)
|
|
|
|
self.row_changed(path, tree_iter)
|
2009-08-06 23:54:10 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def remove_line(self, line_index):
|
2009-08-06 23:54:10 +00:00
|
|
|
|
|
|
|
for l in (self.line_offsets,
|
|
|
|
self.line_levels,
|
|
|
|
self.parent_indices,):
|
|
|
|
del l[line_index]
|
|
|
|
|
|
|
|
path = (line_index,)
|
2016-09-28 18:38:55 +00:00
|
|
|
self.row_deleted(path)
|