2010-09-07 20:42:33 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2010-12-26 11:04:47 +00:00
|
|
|
# Copyright (c) 2008-2011 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
|
2010-09-07 20:42:33 +00:00
|
|
|
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
|
|
|
|
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
|
|
|
|
# Carsten Tinggaard, 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
|
2010-12-11 15:39:12 +00:00
|
|
|
import re
|
2010-12-10 20:42:20 +00:00
|
|
|
import os
|
2010-12-11 00:26:41 +00:00
|
|
|
import platform
|
2010-12-10 20:42:20 +00:00
|
|
|
|
2010-12-11 00:26:41 +00:00
|
|
|
import sqlalchemy
|
|
|
|
import BeautifulSoup
|
2010-12-11 15:39:12 +00:00
|
|
|
from lxml import etree
|
|
|
|
from PyQt4 import Qt, QtCore, QtGui
|
|
|
|
|
|
|
|
try:
|
|
|
|
from PyQt4.phonon import Phonon
|
|
|
|
phonon_version = Phonon.phononVersion()
|
|
|
|
except ImportError:
|
|
|
|
phonon_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
|
|
|
|
except ImportError:
|
|
|
|
sqlite_version = u'-'
|
2010-12-10 20:42:20 +00:00
|
|
|
|
2010-12-11 15:39:12 +00:00
|
|
|
from openlp.core.lib import translate, SettingsManager
|
|
|
|
from openlp.core.lib.mailto import mailto
|
2010-09-07 20:42:33 +00:00
|
|
|
|
|
|
|
from exceptiondialog import Ui_ExceptionDialog
|
|
|
|
|
2010-12-21 19:39:35 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2010-09-07 20:42:33 +00:00
|
|
|
class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog):
|
|
|
|
"""
|
|
|
|
The exception dialog
|
|
|
|
"""
|
|
|
|
def __init__(self, parent):
|
|
|
|
QtGui.QDialog.__init__(self, parent)
|
|
|
|
self.setupUi(self)
|
2010-12-10 20:42:20 +00:00
|
|
|
self.settingsSection = u'crashreport'
|
|
|
|
|
|
|
|
def _createReport(self):
|
2010-12-11 00:26:41 +00:00
|
|
|
openlp_version = self.parent().applicationVersion[u'full']
|
2010-12-13 14:24:16 +00:00
|
|
|
traceback = unicode(self.exceptionTextEdit.toPlainText())
|
2010-12-10 20:42:20 +00:00
|
|
|
system = unicode(translate('OpenLP.ExceptionForm',
|
2010-12-11 15:39:12 +00:00
|
|
|
'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 + \
|
|
|
|
u'SQLAlchemy: %s\n' % sqlalchemy.__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 + \
|
2010-12-27 22:57:35 +00:00
|
|
|
u'PySQLite: %s\n' % sqlite_version
|
2010-12-11 15:39:12 +00:00
|
|
|
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'
|
2010-12-11 00:26:41 +00:00
|
|
|
return (openlp_version, traceback, system, libraries)
|
2010-12-13 14:24:16 +00:00
|
|
|
|
2010-12-10 20:42:20 +00:00
|
|
|
def onSaveReportButtonPressed(self):
|
|
|
|
"""
|
|
|
|
Saving exception log and system informations to a file.
|
|
|
|
"""
|
|
|
|
report = unicode(translate('OpenLP.ExceptionForm',
|
2010-12-11 00:26:41 +00:00
|
|
|
'**OpenLP Bug Report**\n'
|
|
|
|
'Version: %s\n\n'
|
|
|
|
'--- Exception Traceback ---\n%s\n'
|
|
|
|
'--- System information ---\n%s\n'
|
2010-12-10 20:42:20 +00:00
|
|
|
'--- 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)'))
|
2010-12-10 20:42:20 +00:00
|
|
|
if filename:
|
|
|
|
filename = unicode(QtCore.QDir.toNativeSeparators(filename))
|
|
|
|
SettingsManager.set_last_dir(self.settingsSection, os.path.dirname(
|
|
|
|
filename))
|
|
|
|
report = report % self._createReport()
|
|
|
|
try:
|
|
|
|
file = open(filename, u'w')
|
|
|
|
try:
|
|
|
|
file.write(report)
|
|
|
|
except UnicodeError:
|
|
|
|
file.close()
|
|
|
|
file = open(filename, u'wb')
|
|
|
|
file.write(report.encode(u'utf-8'))
|
|
|
|
file.close()
|
|
|
|
except IOError:
|
|
|
|
log.exception(u'Failed to write crash report')
|
|
|
|
|
|
|
|
def onSendReportButtonPressed(self):
|
|
|
|
"""
|
|
|
|
Opening systems default email client and inserting exception log and
|
|
|
|
system informations.
|
|
|
|
"""
|
2010-12-11 15:39:12 +00:00
|
|
|
body = unicode(translate('OpenLP.ExceptionForm',
|
2010-12-10 20:42:20 +00:00
|
|
|
'*OpenLP Bug Report*\n'
|
2010-12-11 00:26:41 +00:00
|
|
|
'Version: %s\n\n'
|
2010-12-10 20:42:20 +00:00
|
|
|
'--- Please enter the report below this line. ---\n\n\n'
|
2010-12-11 00:26:41 +00:00
|
|
|
'--- Exception Traceback ---\n%s\n'
|
|
|
|
'--- System information ---\n%s\n'
|
2010-12-31 02:17:41 +00:00
|
|
|
'--- Library Versions ---\n%s\n',
|
|
|
|
'Please add the information that bug reports are favoured written '
|
|
|
|
'in English.'))
|
2010-12-11 15:39:12 +00:00
|
|
|
content = self._createReport()
|
|
|
|
for line in content[1].split(u'\n'):
|
|
|
|
if re.search(r'[/\\]openlp[/\\]', line):
|
|
|
|
source = re.sub(r'.*[/\\]openlp[/\\](.*)".*', r'\1', line)
|
|
|
|
if u':' in line:
|
2010-12-16 17:11:02 +00:00
|
|
|
exception = line.split(u'\n')[-1].split(u':')[0]
|
2010-12-11 15:39:12 +00:00
|
|
|
subject = u'Bug report: %s in %s' % (exception, source)
|
2010-12-21 19:39:35 +00:00
|
|
|
mailto(address=u'bugs@openlp.org', subject=subject,
|
2010-12-27 22:57:35 +00:00
|
|
|
body=body % content)
|