2018-09-05 02:34:18 +02:00
|
|
|
# Copyright (C) 2016-2018 Philipp Hörist <philipp AT hoerist.com>
|
|
|
|
# Copyright (C) 2005-2006 Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
# Copyright (C) 2005-2014 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
# Copyright (C) 2008 Stephan Erb <steve-e AT h3c.de>
|
|
|
|
#
|
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
|
|
|
# Gajim 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; version 3 only.
|
|
|
|
#
|
|
|
|
# Gajim 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 Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2005-09-09 22:26:06 +02:00
|
|
|
|
2005-09-09 19:09:04 +02:00
|
|
|
import sys
|
2006-05-26 15:26:53 +02:00
|
|
|
import os
|
2005-09-09 19:09:04 +02:00
|
|
|
import traceback
|
2005-09-13 13:11:39 +02:00
|
|
|
import threading
|
2017-01-02 23:45:11 +01:00
|
|
|
import webbrowser
|
2018-01-17 21:02:31 +01:00
|
|
|
import platform
|
2018-10-24 21:14:54 +02:00
|
|
|
from pathlib import Path
|
2018-01-17 21:02:31 +01:00
|
|
|
from io import StringIO
|
|
|
|
from urllib.parse import urlencode
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2018-10-24 21:14:54 +02:00
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import GObject
|
|
|
|
from gi.repository import GLib
|
2018-01-17 21:02:31 +01:00
|
|
|
|
2018-10-24 21:14:54 +02:00
|
|
|
import nbxmpp
|
2018-04-22 22:34:27 +02:00
|
|
|
|
2018-10-24 21:14:54 +02:00
|
|
|
import gajim
|
|
|
|
from gajim.common import configpaths
|
|
|
|
from gajim.gtk.util import get_builder
|
2017-01-02 23:45:11 +01:00
|
|
|
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2005-09-13 13:11:39 +02:00
|
|
|
_exception_in_progress = threading.Lock()
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2018-01-17 21:02:31 +01:00
|
|
|
ISSUE_TEXT = '''## Versions
|
|
|
|
- OS: {}
|
|
|
|
- GTK+ Version: {}
|
|
|
|
- PyGObject Version: {}
|
2018-10-24 21:14:54 +02:00
|
|
|
- GLib Version : {}
|
2018-01-17 21:02:31 +01:00
|
|
|
- python-nbxmpp Version: {}
|
2018-02-05 21:00:28 +01:00
|
|
|
- Gajim Version: {}
|
2018-01-17 21:02:31 +01:00
|
|
|
|
|
|
|
## Traceback
|
|
|
|
```
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
## Steps to reproduce the problem
|
|
|
|
...'''
|
2017-01-02 23:45:11 +01:00
|
|
|
|
2018-04-22 22:34:27 +02:00
|
|
|
|
2017-01-02 23:45:11 +01:00
|
|
|
def _hook(type_, value, tb):
|
2010-02-08 15:08:40 +01:00
|
|
|
if not _exception_in_progress.acquire(False):
|
|
|
|
# Exceptions have piled up, so we use the default exception
|
|
|
|
# handler for such exceptions
|
2017-01-02 23:45:11 +01:00
|
|
|
sys.__excepthook__(type_, value, tb)
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2017-01-02 23:45:11 +01:00
|
|
|
ExceptionDialog(type_, value, tb)
|
|
|
|
_exception_in_progress.release()
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2017-01-02 23:45:11 +01:00
|
|
|
class ExceptionDialog():
|
|
|
|
def __init__(self, type_, value, tb):
|
2018-10-24 21:14:54 +02:00
|
|
|
path = Path(configpaths.get('GUI')) / 'exception_dialog.ui'
|
|
|
|
self._ui = get_builder(path.resolve())
|
|
|
|
self._ui.connect_signals(self)
|
|
|
|
|
|
|
|
self._ui.report_btn.grab_focus()
|
|
|
|
|
|
|
|
buffer_ = self._ui.exception_view.get_buffer()
|
2017-01-02 23:45:11 +01:00
|
|
|
trace = StringIO()
|
|
|
|
traceback.print_exception(type_, value, tb, None, trace)
|
2018-01-17 21:02:31 +01:00
|
|
|
self.text = self.get_issue_text(trace.getvalue())
|
|
|
|
buffer_.set_text(self.text)
|
2018-04-22 22:34:27 +02:00
|
|
|
print(self.text)
|
2018-10-24 21:14:54 +02:00
|
|
|
|
|
|
|
self._ui.exception_view.set_editable(False)
|
|
|
|
self._ui.exception_dialog.show()
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2017-01-02 23:45:11 +01:00
|
|
|
def on_report_clicked(self, *args):
|
2018-01-17 21:02:31 +01:00
|
|
|
issue_url = 'https://dev.gajim.org/gajim/gajim/issues/new'
|
|
|
|
params = {'issue[description]': self.text}
|
|
|
|
url = '{}?{}'.format(issue_url, urlencode(params))
|
2017-01-02 23:45:11 +01:00
|
|
|
webbrowser.open(url, new=2)
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2017-01-02 23:45:11 +01:00
|
|
|
def on_close_clicked(self, *args):
|
2018-10-24 21:14:54 +02:00
|
|
|
self._ui.exception_dialog.destroy()
|
2005-09-11 15:41:21 +02:00
|
|
|
|
2018-10-24 21:14:54 +02:00
|
|
|
@staticmethod
|
|
|
|
def get_issue_text(traceback_text):
|
2018-01-17 21:02:31 +01:00
|
|
|
gtk_ver = '%i.%i.%i' % (
|
|
|
|
Gtk.get_major_version(),
|
|
|
|
Gtk.get_minor_version(),
|
|
|
|
Gtk.get_micro_version())
|
|
|
|
gobject_ver = '.'.join(map(str, GObject.pygobject_version))
|
2018-11-20 00:04:41 +01:00
|
|
|
glib_ver = '.'.join(map(str, [GLib.MAJOR_VERSION,
|
|
|
|
GLib.MINOR_VERSION,
|
|
|
|
GLib.MICRO_VERSION]))
|
2018-01-17 21:02:31 +01:00
|
|
|
|
|
|
|
return ISSUE_TEXT.format(get_os_info(),
|
|
|
|
gtk_ver,
|
|
|
|
gobject_ver,
|
2018-10-24 21:14:54 +02:00
|
|
|
glib_ver,
|
2018-01-17 21:02:31 +01:00
|
|
|
nbxmpp.__version__,
|
2018-10-24 21:14:54 +02:00
|
|
|
gajim.__version__,
|
2018-01-17 21:02:31 +01:00
|
|
|
traceback_text)
|
|
|
|
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2017-01-02 23:45:11 +01:00
|
|
|
def init():
|
|
|
|
if os.name == 'nt' or not sys.stderr.isatty():
|
|
|
|
sys.excepthook = _hook
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2018-01-17 21:02:31 +01:00
|
|
|
|
|
|
|
def get_os_info():
|
|
|
|
if os.name == 'nt' or sys.platform == 'darwin':
|
|
|
|
return platform.system() + " " + platform.release()
|
2018-09-18 10:14:04 +02:00
|
|
|
if os.name == 'posix':
|
2018-01-17 21:02:31 +01:00
|
|
|
try:
|
|
|
|
import distro
|
|
|
|
return distro.name(pretty=True)
|
|
|
|
except ImportError:
|
|
|
|
return platform.system()
|
|
|
|
return ''
|