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): |
80 | 80 | self._treeview.connect('cursor-changed', self._cursor_changed_cb) |
81 | 81 | self._treeview.set_enable_search(False) |
82 | 82 | |
83 | | self._treemodel = Gtk.TreeStore(GObject.TYPE_STRING) |
| 83 | self._treemodel = Gtk.TreeStore(GObject.TYPE_STRING, |
| 84 | GObject.TYPE_STRING) |
84 | 85 | |
85 | 86 | # README: https://bugzilla.gnome.org/show_bug.cgi?id=680009 |
86 | 87 | sorted = self._treemodel.sort_new_with_model() |
… |
… |
class MultiLogView(Gtk.HPaned): |
92 | 93 | col = Gtk.TreeViewColumn(_('Log Files'), renderer, text=0) |
93 | 94 | self._treeview.append_column(col) |
94 | 95 | |
| 96 | renderer = Gtk.CellRendererText() |
| 97 | col = Gtk.TreeViewColumn('', renderer, text=1) |
| 98 | self._treeview.append_column(col) |
| 99 | col.props.visible = False |
| 100 | |
95 | 101 | self.path_iter = {} |
96 | 102 | 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, '']) |
98 | 104 | |
99 | 105 | if len(self.extra_files): |
100 | | self.extra_iter = self._treemodel.append(None, [_('Other')]) |
| 106 | self.extra_iter = self._treemodel.append(None, [_('Other'), '']) |
101 | 107 | |
102 | 108 | scroll = Gtk.ScrolledWindow() |
103 | 109 | scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) |
… |
… |
class MultiLogView(Gtk.HPaned): |
162 | 168 | monitor.connect('changed', self._log_file_changed_cb) |
163 | 169 | self._gio_monitors.append(monitor) |
164 | 170 | |
| 171 | # We don't need monitor old logs, them will no change |
| 172 | |
165 | 173 | for f in self.extra_files: |
166 | 174 | monitor = Gio.File.new_for_path(f)\ |
167 | 175 | .monitor_file(Gio.FileMonitorFlags.NONE, None) |
… |
… |
class MultiLogView(Gtk.HPaned): |
185 | 193 | if selection is not None: |
186 | 194 | treestore, text_iter = selection.get_selected() |
187 | 195 | 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)) |
189 | 197 | if treestore.iter_has_child(text_iter): |
190 | 198 | path = treestore.get_path(text_iter) |
191 | 199 | if treeview.row_expanded(path): |
… |
… |
class MultiLogView(Gtk.HPaned): |
218 | 226 | |
219 | 227 | self._treeview.expand_all() |
220 | 228 | |
221 | | def _add_log_file(self, path): |
| 229 | def _add_log_file(self, path, parent=None, _dir=None): |
222 | 230 | 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 | |
223 | 235 | return False |
224 | 236 | |
225 | 237 | if not os.path.exists(path): |
… |
… |
class MultiLogView(Gtk.HPaned): |
233 | 245 | return False |
234 | 246 | |
235 | 247 | directory, logfile = os.path.split(path) |
| 248 | name = logfile |
236 | 249 | |
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]) |
242 | 259 | |
243 | 260 | model = LogBuffer(path, tree_iter) |
| 261 | |
244 | 262 | self.logs[logfile] = model |
245 | 263 | |
246 | 264 | log = self.logs[logfile] |
… |
… |
class MultiLogView(Gtk.HPaned): |
258 | 276 | self._textview.scroll_to_mark( |
259 | 277 | log.get_insert(), 0, use_align=False, xalign=0.5, yalign=0.5) |
260 | 278 | |
| 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 | |
261 | 289 | def _remove_log_file(self, logfile): |
262 | 290 | log = self.logs[logfile] |
263 | 291 | self._treemodel.remove(log.iter) |