Ticket #2735: 0001-Allow-the-user-to-see-previous-logs-directories.patch

File 0001-Allow-the-user-to-see-previous-logs-directories.patch, 4.7 KB (added by aguz, 10 years ago)
  • logviewer.py

    From ea1fa8baa357a963441ffeff84b9b35d2a07a8a3 Mon Sep 17 00:00:00 2001
    From: Agustin Zubiaga <aguz@sugarlabs.org>
    Date: Fri, 30 Nov 2012 23:38:50 -0200
    Subject: [PATCH] Allow the user to see previous logs directories - SL#2735
    
    http://www.google-melange.com/gci/task/view/google/gci2012/8011208
    
    Signed-off-by: Agustin Zubiaga <aguz@sugarlabs.org>
    ---
     logviewer.py | 48 ++++++++++++++++++++++++++++++++++++++----------
     1 file changed, 38 insertions(+), 10 deletions(-)
    
    diff --git a/logviewer.py b/logviewer.py
    index af12405..89cbdf0 100644
    a b class MultiLogView(Gtk.HPaned): 
    8080        self._treeview.connect('cursor-changed', self._cursor_changed_cb)
    8181        self._treeview.set_enable_search(False)
    8282
    83         self._treemodel = Gtk.TreeStore(GObject.TYPE_STRING)
     83        self._treemodel = Gtk.TreeStore(GObject.TYPE_STRING,
     84                                        GObject.TYPE_STRING)
    8485
    8586        # README: https://bugzilla.gnome.org/show_bug.cgi?id=680009
    8687        sorted = self._treemodel.sort_new_with_model()
    class MultiLogView(Gtk.HPaned): 
    9293        col = Gtk.TreeViewColumn(_('Log Files'), renderer, text=0)
    9394        self._treeview.append_column(col)
    9495
     96        renderer = Gtk.CellRendererText()
     97        col = Gtk.TreeViewColumn('', renderer, text=1)
     98        self._treeview.append_column(col)
     99        col.props.visible = False
     100
    95101        self.path_iter = {}
    96102        for p in self.paths:
    97             self.path_iter[p] = self._treemodel.append(None, [p])
     103            self.path_iter[p] = self._treemodel.append(None, [p, ''])
    98104
    99105        if len(self.extra_files):
    100             self.extra_iter = self._treemodel.append(None, [_('Other')])
     106            self.extra_iter = self._treemodel.append(None, [_('Other'), ''])
    101107
    102108        scroll = Gtk.ScrolledWindow()
    103109        scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
    class MultiLogView(Gtk.HPaned): 
    162168            monitor.connect('changed', self._log_file_changed_cb)
    163169            self._gio_monitors.append(monitor)
    164170
     171        # We don't need monitor old logs, them will no change
     172
    165173        for f in self.extra_files:
    166174            monitor = Gio.File.new_for_path(f)\
    167175                .monitor_file(Gio.FileMonitorFlags.NONE, None)
    class MultiLogView(Gtk.HPaned): 
    185193        if selection is not None:
    186194            treestore, text_iter = selection.get_selected()
    187195            if text_iter is not None:
    188                 self._show_log(treestore.get_value(text_iter, 0))
     196                self._show_log(treestore.get_value(text_iter, 1))
    189197                if treestore.iter_has_child(text_iter):
    190198                    path = treestore.get_path(text_iter)
    191199                    if treeview.row_expanded(path):
    class MultiLogView(Gtk.HPaned): 
    218226
    219227        self._treeview.expand_all()
    220228
    221     def _add_log_file(self, path):
     229    def _add_log_file(self, path, parent=None, _dir=None):
    222230        if os.path.isdir(path):
     231            pdir, _dir = os.path.split(path)
     232            if pdir == self.paths[0]:
     233                self._add_old_logs_dir(pdir, _dir)
     234
    223235            return False
    224236
    225237        if not os.path.exists(path):
    class MultiLogView(Gtk.HPaned): 
    233245            return False
    234246
    235247        directory, logfile = os.path.split(path)
     248        name = logfile
    236249
    237         if not logfile in self.logs:
    238             parent = self.extra_iter
    239             if directory in self.path_iter:
    240                 parent = self.path_iter[directory]
    241             tree_iter = self._treemodel.append(parent, [logfile])
     250        if _dir:
     251            logfile = '%s/%s' % (_dir, logfile)
     252
     253        if not logfile in self.logs or _dir:
     254            if not parent:
     255                parent = self.extra_iter
     256                if directory in self.path_iter:
     257                    parent = self.path_iter[directory]
     258            tree_iter = self._treemodel.append(parent, [name, logfile])
    242259
    243260            model = LogBuffer(path, tree_iter)
     261
    244262            self.logs[logfile] = model
    245263
    246264        log = self.logs[logfile]
    class MultiLogView(Gtk.HPaned): 
    258276            self._textview.scroll_to_mark(
    259277                log.get_insert(), 0, use_align=False, xalign=0.5, yalign=0.5)
    260278
     279    def _add_old_logs_dir(self, path, _dir):
     280        # Add a directory with their respective logs
     281        complete = os.path.join(path, _dir)
     282        name = time.ctime(float(_dir))
     283        parent = self._treemodel.append(self.path_iter[path], [name, ''])
     284        for p in os.listdir(complete):
     285            self._add_log_file(os.path.join(complete, p), parent, _dir)
     286
     287        return parent
     288
    261289    def _remove_log_file(self, logfile):
    262290        log = self.logs[logfile]
    263291        self._treemodel.remove(log.iter)