Debian Codegraph @

troubleshoot/ErrorLogParse.py

raw
1 #!/usr/bin/python3
2
3 ## Printing troubleshooter
4
5 ## Copyright (C) 2008, 2012, 2014 Red Hat, Inc.
6 ## Copyright (C) 2008 Tim Waugh <[email protected]>
7
8 ## This program is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation; either version 2 of the License, or
11 ## (at your option) any later version.
12
13 ## This program is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ## GNU General Public License for more details.
17
18 ## You should have received a copy of the GNU General Public License
19 ## along with this program; if not, write to the Free Software
20 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 from gi.repository import Gtk
23
24 from .base import *
25 from functools import reduce
26 class ErrorLogParse(Question):
27
28 ## This could be a LOT smarter.
29
30 def __init__ (self, troubleshooter):
31 Question.__init__ (self, troubleshooter, "Error log parse")
32 page = self.initial_vbox (_("Error log messages"),
33 _("There are messages in the error log."))
34 sw = Gtk.ScrolledWindow ()
35 textview = Gtk.TextView ()
36 textview.set_editable (False)
37 sw.add (textview)
38 page.pack_start (sw, True, True, 0)
39 self.buffer = textview.get_buffer ()
40 troubleshooter.new_page (page, self)
41
42 def display (self):
43 answers = self.troubleshooter.answers
44 try:
45 journal = answers.get ('journal')
46 error_log = answers.get ('error_log')
47 except KeyError:
48 return False
49
50 display = False
51 if error_log:
52 for line in error_log:
53 if line[0] == 'E':
54 display = error_log
55 break
56
57 if journal and not display:
58 for line in journal:
59 if line[0] == 'E':
60 display = journal
61 break
62
63 if display:
64 self.buffer.set_text (reduce (lambda x, y: x + '\n' + y,
65 display))
66
67 return display != False