openlp/openlp/core/ui/exceptionform.py

246 lines
9.8 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2012-12-29 09:35:24 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2015-12-31 22:46:06 +00:00
# Copyright (c) 2008-2016 OpenLP Developers #
# --------------------------------------------------------------------------- #
# 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; version 2 of the License. #
# #
# 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., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
2013-02-01 19:58:18 +00:00
"""
The actual exception dialog form.
"""
2010-12-21 19:39:35 +00:00
import logging
import re
import os
2010-12-11 00:26:41 +00:00
import platform
2013-06-26 18:54:21 +00:00
import bs4
2010-12-11 00:26:41 +00:00
import sqlalchemy
from lxml import etree
2013-07-19 20:56:31 +00:00
from openlp.core.common import RegistryProperties, is_linux
2013-07-21 14:13:44 +00:00
2015-11-07 00:49:40 +00:00
from PyQt5 import Qt, QtCore, QtGui, QtWebKit, QtWidgets
try:
import migrate
2013-08-31 18:17:38 +00:00
MIGRATE_VERSION = getattr(migrate, '__version__', '< 0.7')
except ImportError:
2013-08-31 18:17:38 +00:00
MIGRATE_VERSION = '-'
try:
import chardet
CHARDET_VERSION = chardet.__version__
except ImportError:
2013-08-31 18:17:38 +00:00
CHARDET_VERSION = '-'
try:
import enchant
ENCHANT_VERSION = enchant.__version__
except ImportError:
2013-08-31 18:17:38 +00:00
ENCHANT_VERSION = '-'
try:
import mako
MAKO_VERSION = mako.__version__
except ImportError:
2013-08-31 18:17:38 +00:00
MAKO_VERSION = '-'
try:
import icu
try:
2013-04-16 16:37:26 +00:00
ICU_VERSION = icu.VERSION
except AttributeError:
2013-08-31 18:17:38 +00:00
ICU_VERSION = 'OK'
except ImportError:
2013-08-31 18:17:38 +00:00
ICU_VERSION = '-'
2011-12-12 22:10:37 +00:00
try:
WEBKIT_VERSION = QtWebKit.qWebKitVersion()
except AttributeError:
2013-08-31 18:17:38 +00:00
WEBKIT_VERSION = '-'
2013-03-14 10:46:19 +00:00
try:
from openlp.core.ui.media.vlcplayer import VERSION
VLC_VERSION = VERSION
except ImportError:
2013-08-31 18:17:38 +00:00
VLC_VERSION = '-'
2011-12-12 22:10:37 +00:00
2013-10-13 20:36:42 +00:00
from openlp.core.common import Settings, UiStrings, translate
2011-03-28 17:29:25 +00:00
from openlp.core.utils import get_application_version
2013-08-31 18:17:38 +00:00
from .exceptiondialog import Ui_ExceptionDialog
2010-12-21 19:39:35 +00:00
log = logging.getLogger(__name__)
2013-02-01 19:58:18 +00:00
2015-11-07 00:49:40 +00:00
class ExceptionForm(QtWidgets.QDialog, Ui_ExceptionDialog, RegistryProperties):
"""
The exception dialog
"""
2013-07-19 20:56:31 +00:00
def __init__(self):
2013-02-01 19:58:18 +00:00
"""
Constructor.
"""
2016-01-09 16:26:14 +00:00
super(ExceptionForm, self).__init__(None, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
self.setupUi(self)
2013-08-31 18:17:38 +00:00
self.settings_section = 'crashreport'
2015-08-26 08:20:55 +00:00
self.report_text = '**OpenLP Bug Report**\n' \
'Version: %s\n\n' \
'--- Details of the Exception. ---\n\n%s\n\n ' \
'--- Exception Traceback ---\n%s\n' \
'--- System information ---\n%s\n' \
'--- Library Versions ---\n%s\n'
2015-11-07 00:49:40 +00:00
def exec(self):
2013-02-01 19:58:18 +00:00
"""
Show the dialog.
"""
2013-08-31 18:17:38 +00:00
self.description_text_edit.setPlainText('')
2013-03-05 14:05:19 +00:00
self.on_description_updated()
self.file_attachment = None
2015-11-07 00:49:40 +00:00
return QtWidgets.QDialog.exec(self)
2011-02-03 17:11:20 +00:00
2013-03-05 14:14:37 +00:00
def _create_report(self):
2013-02-01 19:58:18 +00:00
"""
Create an exception report.
"""
2011-03-28 17:29:25 +00:00
openlp_version = get_application_version()
2013-03-05 14:02:56 +00:00
description = self.description_text_edit.toPlainText()
traceback = self.exception_text_edit.toPlainText()
2012-12-29 09:35:24 +00:00
system = translate('OpenLP.ExceptionForm', 'Platform: %s\n') % platform.platform()
2013-08-31 18:17:38 +00:00
libraries = 'Python: %s\n' % platform.python_version() + \
2015-11-07 00:49:40 +00:00
'Qt5: %s\n' % Qt.qVersion() + \
'PyQt5: %s\n' % Qt.PYQT_VERSION_STR + \
2013-08-31 18:17:38 +00:00
'QtWebkit: %s\n' % WEBKIT_VERSION + \
'SQLAlchemy: %s\n' % sqlalchemy.__version__ + \
'SQLAlchemy Migrate: %s\n' % MIGRATE_VERSION + \
'BeautifulSoup: %s\n' % bs4.__version__ + \
'lxml: %s\n' % etree.__version__ + \
'Chardet: %s\n' % CHARDET_VERSION + \
'PyEnchant: %s\n' % ENCHANT_VERSION + \
'Mako: %s\n' % MAKO_VERSION + \
'pyICU: %s\n' % ICU_VERSION + \
'pyUNO bridge: %s\n' % self._pyuno_import() + \
'VLC: %s\n' % VLC_VERSION
if is_linux():
2013-08-31 18:17:38 +00:00
if os.environ.get('KDE_FULL_SESSION') == 'true':
system += 'Desktop: KDE SC\n'
elif os.environ.get('GNOME_DESKTOP_SESSION_ID'):
system += 'Desktop: GNOME\n'
elif os.environ.get('DESKTOP_SESSION') == 'xfce':
system += 'Desktop: Xfce\n'
2013-12-24 11:32:38 +00:00
return openlp_version, description, traceback, system, libraries
2010-12-13 14:24:16 +00:00
2013-03-05 14:14:37 +00:00
def on_save_report_button_clicked(self):
"""
2012-12-29 09:35:24 +00:00
Saving exception log and system information to a file.
"""
2015-11-07 00:49:40 +00:00
filename = QtWidgets.QFileDialog.getSaveFileName(
2014-03-20 19:10:31 +00:00
self,
translate('OpenLP.ExceptionForm', 'Save Crash Report'),
2013-08-31 18:17:38 +00:00
Settings().value(self.settings_section + '/last directory'),
2015-11-07 00:49:40 +00:00
translate('OpenLP.ExceptionForm', 'Text files (*.txt *.log *.text)'))[0]
if filename:
2013-08-31 18:17:38 +00:00
filename = str(filename).replace('/', os.path.sep)
Settings().setValue(self.settings_section + '/last directory', os.path.dirname(filename))
2015-08-26 08:20:55 +00:00
report_text = self.report_text % self._create_report()
try:
2013-08-31 18:17:38 +00:00
report_file = open(filename, 'w')
try:
2011-06-01 05:42:56 +00:00
report_file.write(report_text)
except UnicodeError:
2011-06-01 05:42:56 +00:00
report_file.close()
2013-08-31 18:17:38 +00:00
report_file = open(filename, 'wb')
report_file.write(report_text.encode('utf-8'))
finally:
2011-06-01 05:42:56 +00:00
report_file.close()
except IOError:
2013-08-31 18:17:38 +00:00
log.exception('Failed to write crash report')
finally:
2011-06-01 05:42:56 +00:00
report_file.close()
2013-03-05 14:14:37 +00:00
def on_send_report_button_clicked(self):
"""
2013-03-14 10:46:19 +00:00
Opening systems default email client and inserting exception log and system information.
"""
2013-03-05 14:14:37 +00:00
content = self._create_report()
2013-08-31 18:17:38 +00:00
source = ''
exception = ''
for line in content[2].split('\n'):
if re.search(r'[/\\]openlp[/\\]', line):
source = re.sub(r'.*[/\\]openlp[/\\](.*)".*', r'\1', line)
2013-08-31 18:17:38 +00:00
if ':' in line:
exception = line.split('\n')[-1].split(':')[0]
subject = 'Bug report: %s in %s' % (exception, source)
mail_urlquery = QtCore.QUrlQuery()
mail_urlquery.addQueryItem('subject', subject)
mail_urlquery.addQueryItem('body', self.report_text % content)
2013-03-05 14:05:19 +00:00
if self.file_attachment:
mail_urlquery.addQueryItem('attach', self.file_attachment)
mail_to_url = QtCore.QUrl('mailto:bugs@openlp.org')
mail_to_url.setQuery(mail_urlquery)
2013-12-24 11:32:38 +00:00
QtGui.QDesktopServices.openUrl(mail_to_url)
2011-02-03 17:11:20 +00:00
2013-03-05 14:05:19 +00:00
def on_description_updated(self):
2013-02-01 19:58:18 +00:00
"""
Update the minimum number of characters needed in the description.
"""
2013-03-05 14:02:56 +00:00
count = int(20 - len(self.description_text_edit.toPlainText()))
2011-02-03 17:11:20 +00:00
if count < 0:
count = 0
2013-03-05 14:14:37 +00:00
self.__button_state(True)
2011-02-03 19:07:27 +00:00
else:
2013-03-05 14:14:37 +00:00
self.__button_state(False)
2013-03-05 14:02:56 +00:00
self.description_word_count.setText(
2012-12-29 09:35:24 +00:00
translate('OpenLP.ExceptionDialog', 'Description characters to enter : %s') % count)
2011-02-03 17:11:20 +00:00
2013-03-05 14:14:37 +00:00
def on_attach_file_button_clicked(self):
2013-02-01 19:58:18 +00:00
"""
Attache files to the bug report e-mail.
"""
2015-11-07 00:49:40 +00:00
files, filter_used = QtWidgets.QFileDialog.getOpenFileName(self,
translate('ImagePlugin.ExceptionDialog',
'Select Attachment'),
Settings().value(self.settings_section +
'/last directory'),
'%s (*)' % UiStrings().AllFiles)
2013-08-31 18:17:38 +00:00
log.info('New files(s) %s', str(files))
2011-02-03 19:07:27 +00:00
if files:
2013-08-31 18:17:38 +00:00
self.file_attachment = str(files)
2011-02-03 19:07:27 +00:00
2013-03-05 14:14:37 +00:00
def __button_state(self, state):
2013-02-01 19:58:18 +00:00
"""
Toggle the button state.
"""
2013-03-05 14:02:56 +00:00
self.save_report_button.setEnabled(state)
self.send_report_button.setEnabled(state)
2013-07-19 20:56:31 +00:00
def _pyuno_import(self):
2013-07-21 14:10:21 +00:00
"""
Added here to define only when the form is actioned. The uno interface spits out lots of exception messages
if the import is at a file level. If uno import is changed this could be reverted.
This happens in other classes but there it is localised here it is across the whole system and hides real
errors.
"""
2013-07-19 20:56:31 +00:00
try:
import uno
2013-08-31 18:17:38 +00:00
arg = uno.createUnoStruct('com.sun.star.beans.PropertyValue')
arg.Name = 'nodepath'
arg.Value = '/org.openoffice.Setup/Product'
2013-07-19 20:56:31 +00:00
context = uno.getComponentContext()
2013-08-31 18:17:38 +00:00
provider = context.ServiceManager.createInstance('com.sun.star.configuration.ConfigurationProvider')
node = provider.createInstanceWithArguments('com.sun.star.configuration.ConfigurationAccess', (arg,))
return node.getByName('ooSetupVersion')
2013-07-19 20:56:31 +00:00
except ImportError:
2013-08-31 18:17:38 +00:00
return '-'
2013-07-19 20:56:31 +00:00
except:
2013-08-31 18:17:38 +00:00
return '- (Possible non-standard UNO installation)'