Remove log file from list when deleted
When logs are deleted by the user they are removed from the list, except
logs from previous Sugar sessions, because they were not monitored for
change.
- add previous logs to the watcher,
- on a changed event, convert the absolute path into displayed path,
- refactor common code for Gio.File and Gio.FileMonitor,
- update line numbers in translations template.
Regression was introduced in 3673659a2ef602a507619f1448226aa546512d27 or
the port to GTK+ 3.
Fixes https://github.com/sugarlabs/log-activity/issues/12
Co-authored-by: James Cameron <quozl@laptop.org>
nswarup14 authored 5 years ago
James Cameron committed 5 years ago
173 | 173 | return 0 |
174 | 174 | |
175 | 175 | def _configure_watcher(self): |
176 | # Setting where GIO will be watching | |
177 | 176 | for p in self.paths: |
178 | monitor = Gio.File.new_for_path(p)\ | |
179 | .monitor_directory(Gio.FileMonitorFlags.NONE, None) | |
180 | monitor.connect('changed', self._log_file_changed_cb) | |
181 | self._gio_monitors.append(monitor) | |
182 | ||
183 | # We don't need monitor old logs, them will no change | |
177 | for q in os.listdir(p): | |
178 | r = os.path.join(p, q) | |
179 | if os.path.isdir(r): | |
180 | self._create_gio_monitor(r) | |
181 | self._create_gio_monitor(p) | |
184 | 182 | |
185 | 183 | for f in self.extra_files: |
186 | monitor = Gio.File.new_for_path(f)\ | |
187 | .monitor_file(Gio.FileMonitorFlags.NONE, None) | |
188 | monitor.connect('changed', self._log_file_changed_cb) | |
189 | self._gio_monitors.append(monitor) | |
184 | self._create_gio_monitor(f) | |
185 | ||
186 | def _create_gio_monitor(self, direc_path): | |
187 | monitor = Gio.File.new_for_path(direc_path)\ | |
188 | .monitor_directory(Gio.FileMonitorFlags.NONE, None) | |
189 | monitor.connect('changed', self._log_file_changed_cb) | |
190 | self._gio_monitors.append(monitor) | |
190 | 191 | |
191 | 192 | def _log_file_changed_cb(self, monitor, log_file, other_file, event): |
192 | logfile = log_file.get_basename() | |
193 | filepath = log_file.get_path() | |
194 | logfile = None | |
195 | for p in self.paths: | |
196 | if filepath.startswith(p): | |
197 | logfile = os.path.relpath(filepath, p) | |
198 | break | |
193 | 199 | |
194 | 200 | if event == Gio.FileMonitorEvent.CHANGED: |
195 | 201 | if logfile in self.logs: |
7 | 7 | msgstr "" |
8 | 8 | "Project-Id-Version: PACKAGE VERSION\n" |
9 | 9 | "Report-Msgid-Bugs-To: \n" |
10 | "POT-Creation-Date: 2018-09-18 18:56+1000\n" | |
10 | "POT-Creation-Date: 2019-01-23 13:01+0530\n" | |
11 | 11 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
12 | 12 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
13 | 13 | "Language-Team: LANGUAGE <LL@li.org>\n" |
34 | 34 | msgid "Other" |
35 | 35 | msgstr "" |
36 | 36 | |
37 | #: logviewer.py:230 | |
37 | #: logviewer.py:239 | |
38 | 38 | #, python-format |
39 | 39 | msgid "ERROR: Failed to look for files in '%(path)s'." |
40 | 40 | msgstr "" |
41 | 41 | |
42 | #: logviewer.py:250 | |
42 | #: logviewer.py:259 | |
43 | 43 | #, python-format |
44 | 44 | msgid "ERROR: File '%(file)s' does not exist." |
45 | 45 | msgstr "" |
46 | 46 | |
47 | #: logviewer.py:255 | |
47 | #: logviewer.py:264 | |
48 | 48 | #, python-format |
49 | 49 | msgid "ERROR: Unable to read file '%(file)s'." |
50 | 50 | msgstr "" |
51 | 51 | |
52 | #: logviewer.py:403 | |
52 | #: logviewer.py:412 | |
53 | 53 | #, python-format |
54 | 54 | msgid "Error: Can't open file '%s'\n" |
55 | 55 | msgstr "" |
56 | 56 | |
57 | #: logviewer.py:457 | |
57 | #: logviewer.py:466 | |
58 | 58 | msgid "Show list of files" |
59 | 59 | msgstr "" |
60 | 60 | |
61 | #: logviewer.py:467 | |
61 | #: logviewer.py:476 | |
62 | 62 | msgid "Word Wrap" |
63 | 63 | msgstr "" |
64 | 64 | |
65 | #: logviewer.py:483 | |
65 | #: logviewer.py:492 | |
66 | 66 | msgid "Previous" |
67 | 67 | msgstr "" |
68 | 68 | |
69 | #: logviewer.py:488 | |
69 | #: logviewer.py:497 | |
70 | 70 | msgid "Next" |
71 | 71 | msgstr "" |
72 | 72 | |
73 | #: logviewer.py:502 | |
73 | #: logviewer.py:511 | |
74 | 74 | msgid "Delete Log File" |
75 | 75 | msgstr "" |
76 | 76 | |
77 | #: logviewer.py:608 | |
77 | #: logviewer.py:617 | |
78 | 78 | msgid "Error" |
79 | 79 | msgstr "" |
80 | 80 | |
81 | #: logviewer.py:609 | |
81 | #: logviewer.py:618 | |
82 | 82 | #, python-format |
83 | 83 | msgid "%(error)s when deleting %(file)s" |
84 | 84 | msgstr "" |
85 | 85 | |
86 | #: logviewer.py:620 | |
86 | #: logviewer.py:629 | |
87 | 87 | msgid "Log Collector: Capture information" |
88 | 88 | msgstr "" |
89 | 89 | |
90 | #: logviewer.py:626 | |
90 | #: logviewer.py:635 | |
91 | 91 | msgid "" |
92 | 92 | "This captures information about the system\n" |
93 | 93 | "and running processes to a journal entry.\n" |
94 | 94 | "Use this to improve a problem report." |
95 | 95 | msgstr "" |
96 | 96 | |
97 | #: logviewer.py:631 | |
97 | #: logviewer.py:640 | |
98 | 98 | msgid "Capture information" |
99 | 99 | msgstr "" |
100 | 100 | |
101 | #: logviewer.py:660 | |
101 | #: logviewer.py:669 | |
102 | 102 | msgid "Logs not captured" |
103 | 103 | msgstr "" |
104 | 104 | |
105 | #: logviewer.py:661 | |
105 | #: logviewer.py:670 | |
106 | 106 | msgid "The logs could not be captured." |
107 | 107 | msgstr "" |
108 | 108 | |
109 | #: logviewer.py:671 | |
109 | #: logviewer.py:680 | |
110 | 110 | #, python-format |
111 | 111 | msgid "log-%s" |
112 | 112 | msgstr "" |