openlp/openlp/core/ui/exceptionform.py

229 lines
9.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2011-12-27 10:33:55 +00:00
# Copyright (c) 2008-2012 Raoul Snyman #
# Portions copyright (c) 2008-2012 Tim Bentley, Gerald Britton, Jonathan #
2011-05-26 16:25:54 +00:00
# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, #
2011-05-26 17:11:22 +00:00
# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias #
2011-06-12 16:02:52 +00:00
# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
2011-06-12 15:41:01 +00:00
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
2010-12-21 19:39:35 +00:00
import logging
import re
import os
2010-12-11 00:26:41 +00:00
import platform
2010-12-11 00:26:41 +00:00
import sqlalchemy
import BeautifulSoup
from lxml import etree
2011-12-12 22:10:37 +00:00
from PyQt4 import Qt, QtCore, QtGui, QtWebKit
try:
from PyQt4.phonon import Phonon
PHONON_VERSION = Phonon.phononVersion()
except ImportError:
PHONON_VERSION = u'-'
try:
import migrate
MIGRATE_VERSION = getattr(migrate, u'__version__', u'< 0.7')
except ImportError:
MIGRATE_VERSION = u'-'
try:
import chardet
CHARDET_VERSION = chardet.__version__
except ImportError:
CHARDET_VERSION = u'-'
try:
import enchant
ENCHANT_VERSION = enchant.__version__
except ImportError:
ENCHANT_VERSION = u'-'
2010-12-11 00:26:41 +00:00
try:
import sqlite
SQLITE_VERSION = sqlite.version
2010-12-11 00:26:41 +00:00
except ImportError:
SQLITE_VERSION = u'-'
try:
import mako
MAKO_VERSION = mako.__version__
except ImportError:
MAKO_VERSION = u'-'
try:
import uno
arg = uno.createUnoStruct(u'com.sun.star.beans.PropertyValue')
arg.Name = u'nodepath'
arg.Value = u'/org.openoffice.Setup/Product'
context = uno.getComponentContext()
provider = context.ServiceManager.createInstance(
u'com.sun.star.configuration.ConfigurationProvider')
node = provider.createInstanceWithArguments(
u'com.sun.star.configuration.ConfigurationAccess', (arg,))
UNO_VERSION = node.getByName(u'ooSetupVersion')
except ImportError:
UNO_VERSION = u'-'
except:
UNO_VERSION = u'- (Possible non-standard UNO installation)'
2011-12-12 22:10:37 +00:00
try:
WEBKIT_VERSION = QtWebKit.qWebKitVersion()
except AttributeError:
WEBKIT_VERSION = u'-'
from openlp.core.lib import translate, SettingsManager
2011-02-10 00:37:04 +00:00
from openlp.core.lib.ui import UiStrings
2011-03-28 17:29:25 +00:00
from openlp.core.utils import get_application_version
from exceptiondialog import Ui_ExceptionDialog
2010-12-21 19:39:35 +00:00
log = logging.getLogger(__name__)
class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog):
"""
The exception dialog
"""
def __init__(self, parent):
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.settingsSection = u'crashreport'
2011-02-03 17:11:20 +00:00
def exec_(self):
2011-02-04 17:15:48 +00:00
self.descriptionTextEdit.setPlainText(u'')
2011-02-03 17:11:20 +00:00
self.onDescriptionUpdated()
2011-02-03 19:07:27 +00:00
self.fileAttachment = None
2011-02-03 17:11:20 +00:00
return QtGui.QDialog.exec_(self)
def _createReport(self):
2011-03-28 17:29:25 +00:00
openlp_version = get_application_version()
2011-02-03 17:11:20 +00:00
description = unicode(self.descriptionTextEdit.toPlainText())
2010-12-13 14:24:16 +00:00
traceback = unicode(self.exceptionTextEdit.toPlainText())
system = unicode(translate('OpenLP.ExceptionForm',
'Platform: %s\n')) % platform.platform()
libraries = u'Python: %s\n' % platform.python_version() + \
u'Qt4: %s\n' % Qt.qVersion() + \
u'Phonon: %s\n' % PHONON_VERSION + \
u'PyQt4: %s\n' % Qt.PYQT_VERSION_STR + \
2011-12-12 22:10:37 +00:00
u'QtWebkit: %s\n' % WEBKIT_VERSION + \
u'SQLAlchemy: %s\n' % sqlalchemy.__version__ + \
u'SQLAlchemy Migrate: %s\n' % MIGRATE_VERSION + \
u'BeautifulSoup: %s\n' % BeautifulSoup.__version__ + \
u'lxml: %s\n' % etree.__version__ + \
u'Chardet: %s\n' % CHARDET_VERSION + \
u'PyEnchant: %s\n' % ENCHANT_VERSION + \
u'PySQLite: %s\n' % SQLITE_VERSION + \
u'Mako: %s\n' % MAKO_VERSION + \
u'pyUNO bridge: %s\n' % UNO_VERSION
if platform.system() == u'Linux':
if os.environ.get(u'KDE_FULL_SESSION') == u'true':
system = system + u'Desktop: KDE SC\n'
elif os.environ.get(u'GNOME_DESKTOP_SESSION_ID'):
system = system + u'Desktop: GNOME\n'
2011-02-03 17:11:20 +00:00
return (openlp_version, description, traceback, system, libraries)
2010-12-13 14:24:16 +00:00
def onSaveReportButtonClicked(self):
"""
Saving exception log and system informations to a file.
"""
2011-06-01 05:42:56 +00:00
report_text = unicode(translate('OpenLP.ExceptionForm',
2010-12-11 00:26:41 +00:00
'**OpenLP Bug Report**\n'
'Version: %s\n\n'
2011-02-03 17:11:20 +00:00
'--- Details of the Exception. ---\n\n%s\n\n '
2010-12-11 00:26:41 +00:00
'--- Exception Traceback ---\n%s\n'
'--- System information ---\n%s\n'
'--- Library Versions ---\n%s\n'))
filename = QtGui.QFileDialog.getSaveFileName(self,
translate('OpenLP.ExceptionForm', 'Save Crash Report'),
SettingsManager.get_last_dir(self.settingsSection),
2010-12-21 19:39:35 +00:00
translate('OpenLP.ExceptionForm',
'Text files (*.txt *.log *.text)'))
if filename:
2012-02-26 21:09:22 +00:00
filename = unicode(filename).replace(u'/', os.path.sep)
SettingsManager.set_last_dir(self.settingsSection, os.path.dirname(
filename))
2011-06-01 05:42:56 +00:00
report_text = report_text % self._createReport()
try:
2011-06-01 05:42:56 +00:00
report_file = open(filename, u'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()
report_file = open(filename, u'wb')
report_file.write(report_text.encode(u'utf-8'))
finally:
2011-06-01 05:42:56 +00:00
report_file.close()
except IOError:
log.exception(u'Failed to write crash report')
finally:
2011-06-01 05:42:56 +00:00
report_file.close()
def onSendReportButtonClicked(self):
"""
Opening systems default email client and inserting exception log and
system informations.
"""
body = unicode(translate('OpenLP.ExceptionForm',
'*OpenLP Bug Report*\n'
2010-12-11 00:26:41 +00:00
'Version: %s\n\n'
2011-02-03 17:11:20 +00:00
'--- Details of the Exception. ---\n\n%s\n\n '
2010-12-11 00:26:41 +00:00
'--- Exception Traceback ---\n%s\n'
'--- System information ---\n%s\n'
'--- Library Versions ---\n%s\n',
'Please add the information that bug reports are favoured written '
'in English.'))
content = self._createReport()
2011-10-23 17:22:11 +00:00
source = u''
exception = u''
2011-02-03 17:23:24 +00:00
for line in content[2].split(u'\n'):
if re.search(r'[/\\]openlp[/\\]', line):
source = re.sub(r'.*[/\\]openlp[/\\](.*)".*', r'\1', line)
if u':' in line:
exception = line.split(u'\n')[-1].split(u':')[0]
2011-10-15 21:21:22 +00:00
subject = u'Bug report: %s in %s' % (exception, source)
mailto_url = QtCore.QUrl(u'mailto:bugs@openlp.org')
2011-10-15 21:21:22 +00:00
mailto_url.addQueryItem(u'subject', subject)
mailto_url.addQueryItem(u'body', body % content)
2011-02-03 19:07:27 +00:00
if self.fileAttachment:
mailto_url.addQueryItem(u'attach', self.fileAttachment)
QtGui.QDesktopServices.openUrl(mailto_url)
2011-02-03 17:11:20 +00:00
def onDescriptionUpdated(self):
count = int(20 - len(self.descriptionTextEdit.toPlainText()))
if count < 0:
count = 0
2011-02-03 19:07:27 +00:00
self.__buttonState(True)
else:
self.__buttonState(False)
2011-02-03 17:11:20 +00:00
self.descriptionWordCount.setText(
unicode(translate('OpenLP.ExceptionDialog',
2011-02-16 03:28:06 +00:00
'Description characters to enter : %s')) % count)
2011-02-03 17:11:20 +00:00
def onAttachFileButtonClicked(self):
2011-02-03 19:07:27 +00:00
files = QtGui.QFileDialog.getOpenFileName(
self,translate('ImagePlugin.ExceptionDialog',
'Select Attachment'),
SettingsManager.get_last_dir(u'exceptions'),
u'%s (*.*) (*)' % UiStrings().AllFiles)
2011-02-03 19:07:27 +00:00
log.info(u'New files(s) %s', unicode(files))
if files:
self.fileAttachment = unicode(files)
def __buttonState(self, state):
self.saveReportButton.setEnabled(state)
self.sendReportButton.setEnabled(state)