/
gnome-abrt
executable file
·296 lines (257 loc) · 11.5 KB
/
gnome-abrt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/usr/bin/python3
# coding=UTF-8
## Copyright (C) 2012 ABRT team <abrt-devel-list@redhat.com>
## Copyright (C) 2001-2005 Red Hat, Inc.
## 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 2 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, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
import locale
import logging
import signal
import sys
# pygobject
#pylint: disable=C0411, C0413
import gi
gi.require_version('Gio', '2.0')
gi.require_version('GLib', '2.0')
gi.require_version('GObject', '2.0')
gi.require_version('Gtk', '3.0')
gi.require_version('Pango', '1.0')
#pylint: disable=E0611, C0411, C0413
from gi.repository import Gtk
#pylint: disable=E0611, C0411, C0413
from gi.repository import GLib
#pylint: disable=E0611, C0411, C0413
from gi.repository import Gio
# gnome-abrt
#pylint: disable=C0413, C0412
import gnome_abrt
gnome_abrt.init()
#pylint: disable=C0413
from gnome_abrt.views import OopsWindow
#pylint: disable=C0413
from gnome_abrt.controller import Controller
#pylint: disable=C0413
from gnome_abrt.signals import glib_sigchld_signal_handler
#pylint: disable=C0413
from gnome_abrt.problems import MultipleSources
#pylint: disable=C0413
from gnome_abrt.dbus_problems import (get_standard_problems_source,
get_foreign_problems_source)
#pylint: disable=C0413
from gnome_abrt.errors import UnavailableSource
#pylint: disable=C0413
from gnome_abrt.l10n import _, C_
#pylint: disable=C0413
from gnome_abrt.config import get_configuration
from gnome_abrt.wrappers import show_events_list_dialog
GNOME_ABRT_APPLICATION_ID = 'org.freedesktop.GnomeAbrt'
GNOME_ABRT_INTERFACE = 'org.freedesktop.GnomeAbrt'
GNOME_ABRT_OBJECT_PATH = '/org/freedesktop/GnomeAbrt'
GNOME_ABRT_URL_POOL_CAPACITY = 10
class OopsApplication(Gtk.Application):
def __init__(self):
Gtk.Application.__init__(self,
application_id=GNOME_ABRT_APPLICATION_ID,
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE)
self.all_sources = None
self.gnome_settings = None
# pylint: disable=W0105
'''
Again a trick to make xgettext think we are C language and emit the
translators comment correctly.
See: bugs.launchpad.net/intltool/+bug/377872
// Translators: This is a description of --verbose command line option
// displayed when a user runs: `gnome-abrt --help'
_("Be verbose")
'''
self.add_main_option('verbose',
ord('v'),
GLib.OptionFlags.NONE,
GLib.OptionArg.NONE,
_('Be verbose'),
None)
# pylint: disable=W0105
'''
// Translators: This is a description of --problem command line option
// displayed when a user runs: `gnome-abrt --help'
_("Selected problem ID")
'''
self.add_main_option('problem',
ord('p'),
GLib.OptionFlags.NONE,
GLib.OptionArg.STRING,
_('Selected problem ID'),
'PROBLEM')
def _bind_to_gsettings(self, conf):
def set_time_format(conf, gsettings):
clck_fmt = None
try:
clck_fmt = gsettings.get_value('clock-format').get_string()
# What exception types is less general?
#pylint: disable=W0703
except Exception as ex:
logging.exception(ex)
return
if clck_fmt == '24h':
conf['T_FMT'] = '%k:%M'
conf['D_T_FMT'] = '%Y-%m-%d %k:%M'
else:
conf['T_FMT'] = '%l:%M %p'
conf['D_T_FMT'] = '%Y-%m-%d %l:%M %p'
def settings_changed(settings, key, conf):
if key == 'clock-format':
set_time_format(conf, settings)
if self.gnome_settings is None:
self.gnome_settings = Gio.Settings(
schema='org.gnome.desktop.interface')
self.gnome_settings.connect(
'changed', settings_changed, conf)
conf.add_option('T_FMT',
default_value=locale.nl_langinfo(locale.T_FMT))
conf.add_option('D_T_FMT',
default_value=locale.nl_langinfo(locale.D_T_FMT))
set_time_format(conf, self.gnome_settings)
def do_command_line(self, *args, **kwargs):
command_line, *_ = args
options = command_line.get_options_dict().end().unpack()
configuration = get_configuration()
if 'verbose' in options:
logging.getLogger().setLevel(logging.DEBUG)
for option in options:
if option in configuration:
configuration[option] = options[option]
self.activate()
return 0
#pylint: disable=W0221
def do_activate(self):
try:
windows = self.get_windows()
if windows:
windows[0].present()
else:
conf = get_configuration()
conf.add_option("all_problems", default_value=False)
self._bind_to_gsettings(conf)
sources = []
try:
sources.append(
get_standard_problems_source())
except UnavailableSource as ex:
logging.warning(str(ex))
if not sources:
raise UnavailableSource(None, None,
message="No available problem source.")
# pylint: disable=W0105
'''
This is a trick to make xgettext think we are C language
and emit the translators comment correctly. It's a bug
in xgettext that it recognizes Python files only after
their .py extension, there is no way to force the format.
See: bugs.launchpad.net/intltool/+bug/377872
// Translators: a list header, "My" is a shortcut for "My bugs"
_("My")
'''
self.all_sources = [(_("My"), MultipleSources(sources))]
try:
# pylint: disable=W0105
'''
The same trick as above:
// Translators: a list header, a shortcut for "System
// bugs". In this context "System" may be an adjective
// or a genitive noun, as required by your language.
C_("bugs", "System")
'''
self.all_sources.append((C_("bugs", "System"),
get_foreign_problems_source()))
except UnavailableSource as ex:
logging.warning(str(ex))
controller = Controller(self.all_sources,
glib_sigchld_signal_handler)
main_window = OopsWindow(self, self.all_sources, controller)
main_window.show_all()
self.add_window(main_window)
#pylint: disable=W0703
except Exception as ex:
logging.exception(ex)
sys.exit(1)
#pylint: disable=W0221
def do_startup(self):
Gtk.Application.do_startup(self)
Gtk.Window.set_default_icon_name(GNOME_ABRT_APPLICATION_ID)
action = Gio.SimpleAction.new("preferences", None)
action.connect("activate", self.on_action_prefrences)
self.add_action(action)
action = Gio.SimpleAction.new("about", None)
action.connect("activate", self.on_action_about)
self.add_action(action)
action = Gio.SimpleAction.new("quit", None)
action.connect("activate", self.on_action_quit)
self.add_action(action)
self.set_accels_for_action("app.quit", ["<Control>q"])
#pylint: disable=W0613
def on_action_prefrences(self, action, parameter):
windows = self.get_windows()
if windows:
show_events_list_dialog(windows[0])
else:
show_events_list_dialog()
#pylint: disable=W0613
def on_action_about(self, action, parameter):
#pylint: disable=E1120
dialog = Gtk.AboutDialog.new()
dialog.set_version(gnome_abrt.VERSION)
dialog.set_logo_icon_name(GNOME_ABRT_APPLICATION_ID)
dialog.set_program_name(_("Problem Reporting"))
dialog.set_copyright("Copyright © 2024 Red Hat, Inc")
dialog.set_license(
"This program is free software; you can redistribut"
"e it and/or modify it under the terms of the GNU General Public License "
"as published by the Free Software Foundation; either version 2 of the Li"
"cense, or (at your option) any later version.\n\nThis program is distrib"
"uted in the hope that it will be useful, but WITHOUT ANY WARRANTY; witho"
"ut even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICU"
"LAR PURPOSE. See the GNU General Public License for more details.\n\nYo"
"u should have received a copy of the GNU General Public License along wi"
"th this program. If not, see <http://www.gnu.org/licenses/>.")
dialog.set_wrap_license(True)
dialog.set_website("https://github.com/abrt/gnome-abrt")
dialog.set_authors(["aboobed <0otibi0@gmail.com>",
"Allan Day <allanpday@gmail.com>",
"Bastien Nocera <hadess@hadess.net>",
"Chris Lockfort <clockfort@csh.rit.edu>",
"Daniel Aleksandersen <code@daniel.priv.no>",
"Denys Vlasenko <dvlasenk@redhat.com>",
"Elad Alfassa <elad@fedoraproject.org>",
"Francesco Frassinelli <fraph24@gmail.com>",
"Jakub Filák <filak.jakub@gmail.com>",
"Jiri Moskovčák <moskovcak@gmail.com>",
"Martin Milata <mmilata@redhat.com>",
"Matěj Habrnál <mhabrnal@redhat.com>",
"Marek Bryša <marek.brysa@gmail.com>",
"Michael Catanzaro <mcatanzaro@gnome.org>",
"Michal Toman <michal.toman@gmail.com>",
"Rafał Lużyński <digitalfreak@lingonborough.com>",
"Richard Marko <rmarko@fedoraproject.org>"])
#dialog.set_artists(artists)
#dialog.set_translator_credits(_("translator-credits"))
windows = self.get_windows()
if windows:
dialog.set_transient_for(windows[0])
dialog.run()
dialog.destroy()
#pylint: disable=W0613
def on_action_quit(self, action, parameter):
self.quit()
if __name__ == "__main__":
signal.signal(signal.SIGINT, lambda signum, frame: sys.exit(1))
get_configuration().add_option('problem', default_value=None)
OopsApplication().run(sys.argv)