~tomasgroth/openlp/portable-path

« back to all changes in this revision

Viewing changes to openlp/core/ui/exceptionform.py

  • Committer: Tomas Groth
  • Date: 2019-04-30 19:02:42 UTC
  • mfrom: (2829.2.32 openlp)
  • Revision ID: tomasgroth@yahoo.dk-20190430190242-6zwjk8724tyux70m
trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
###############################################################################
5
5
# OpenLP - Open Source Lyrics Projection                                      #
6
6
# --------------------------------------------------------------------------- #
7
 
# Copyright (c) 2008-2018 OpenLP Developers                                   #
 
7
# Copyright (c) 2008-2019 OpenLP Developers                                   #
8
8
# --------------------------------------------------------------------------- #
9
9
# This program is free software; you can redistribute it and/or modify it     #
10
10
# under the terms of the GNU General Public License as published by the Free  #
27
27
import platform
28
28
import re
29
29
 
30
 
import bs4
31
 
import sqlalchemy
32
 
from PyQt5 import Qt, QtCore, QtGui, QtWebKit, QtWidgets
33
 
from lxml import etree
34
 
 
35
 
try:
36
 
    import migrate
37
 
    MIGRATE_VERSION = getattr(migrate, '__version__', '< 0.7')
38
 
except ImportError:
39
 
    MIGRATE_VERSION = '-'
40
 
try:
41
 
    import chardet
42
 
    CHARDET_VERSION = chardet.__version__
43
 
except ImportError:
44
 
    CHARDET_VERSION = '-'
45
 
try:
46
 
    import enchant
47
 
    ENCHANT_VERSION = enchant.__version__
48
 
except ImportError:
49
 
    ENCHANT_VERSION = '-'
50
 
try:
51
 
    import mako
52
 
    MAKO_VERSION = mako.__version__
53
 
except ImportError:
54
 
    MAKO_VERSION = '-'
55
 
try:
56
 
    import icu
57
 
    try:
58
 
        ICU_VERSION = icu.VERSION
59
 
    except AttributeError:
60
 
        ICU_VERSION = 'OK'
61
 
except ImportError:
62
 
    ICU_VERSION = '-'
63
 
try:
64
 
    WEBKIT_VERSION = QtWebKit.qWebKitVersion()
65
 
except AttributeError:
66
 
    WEBKIT_VERSION = '-'
67
 
try:
68
 
    from openlp.core.ui.media.vlcplayer import VERSION
69
 
    VLC_VERSION = VERSION
70
 
except ImportError:
71
 
    VLC_VERSION = '-'
 
30
from PyQt5 import QtCore, QtGui, QtWidgets
72
31
 
73
32
from openlp.core.common import is_linux
74
33
from openlp.core.common.i18n import UiStrings, translate
75
34
from openlp.core.common.mixins import RegistryProperties
76
35
from openlp.core.common.settings import Settings
77
36
from openlp.core.ui.exceptiondialog import Ui_ExceptionDialog
 
37
from openlp.core.version import get_library_versions, get_version
78
38
from openlp.core.widgets.dialogs import FileDialog
79
 
from openlp.core.version import get_version
80
39
 
81
40
 
82
41
log = logging.getLogger(__name__)
91
50
        Constructor.
92
51
        """
93
52
        super(ExceptionForm, self).__init__(None, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
94
 
        self.setupUi(self)
 
53
        self.setup_ui(self)
95
54
        self.settings_section = 'crashreport'
96
55
        self.report_text = '**OpenLP Bug Report**\n' \
97
56
            'Version: {version}\n\n' \
117
76
        description = self.description_text_edit.toPlainText()
118
77
        traceback = self.exception_text_edit.toPlainText()
119
78
        system = translate('OpenLP.ExceptionForm', 'Platform: {platform}\n').format(platform=platform.platform())
120
 
        libraries = ('Python: {python}\nQt5: {qt5}\nPyQt5: {pyqt5}\nQtWebkit: {qtwebkit}\nSQLAlchemy: {sqalchemy}\n'
121
 
                     'SQLAlchemy Migrate: {migrate}\nBeautifulSoup: {soup}\nlxml: {etree}\nChardet: {chardet}\n'
122
 
                     'PyEnchant: {enchant}\nMako: {mako}\npyICU: {icu}\npyUNO bridge: {uno}\n'
123
 
                     'VLC: {vlc}\n').format(python=platform.python_version(), qt5=Qt.qVersion(),
124
 
                                            pyqt5=Qt.PYQT_VERSION_STR, qtwebkit=WEBKIT_VERSION,
125
 
                                            sqalchemy=sqlalchemy.__version__, migrate=MIGRATE_VERSION,
126
 
                                            soup=bs4.__version__, etree=etree.__version__, chardet=CHARDET_VERSION,
127
 
                                            enchant=ENCHANT_VERSION, mako=MAKO_VERSION, icu=ICU_VERSION,
128
 
                                            uno=self._pyuno_import(), vlc=VLC_VERSION)
 
79
        library_versions = get_library_versions()
 
80
        library_versions['PyUNO'] = self._get_pyuno_version()
 
81
        libraries = '\n'.join(['{}: {}'.format(library, version) for library, version in library_versions.items()])
129
82
 
130
83
        if is_linux():
131
84
            if os.environ.get('KDE_FULL_SESSION') == 'true':
142
95
        """
143
96
        Saving exception log and system information to a file.
144
97
        """
145
 
        file_path, filter_used = FileDialog.getSaveFileName(
146
 
            self,
147
 
            translate('OpenLP.ExceptionForm', 'Save Crash Report'),
148
 
            Settings().value(self.settings_section + '/last directory'),
149
 
            translate('OpenLP.ExceptionForm', 'Text files (*.txt *.log *.text)'))
150
 
        if file_path:
 
98
        while True:
 
99
            file_path, filter_used = FileDialog.getSaveFileName(
 
100
                self,
 
101
                translate('OpenLP.ExceptionForm', 'Save Crash Report'),
 
102
                Settings().value(self.settings_section + '/last directory'),
 
103
                translate('OpenLP.ExceptionForm', 'Text files (*.txt *.log *.text)'))
 
104
            if file_path is None:
 
105
                break
151
106
            Settings().setValue(self.settings_section + '/last directory', file_path.parent)
152
107
            opts = self._create_report()
153
108
            report_text = self.report_text.format(version=opts['version'], description=opts['description'],
155
110
            try:
156
111
                with file_path.open('w') as report_file:
157
112
                    report_file.write(report_text)
158
 
            except OSError:
 
113
                    break
 
114
            except OSError as e:
159
115
                log.exception('Failed to write crash report')
 
116
                QtWidgets.QMessageBox.warning(
 
117
                    self, translate('OpenLP.ExceptionDialog', 'Failed to Save Report'),
 
118
                    translate('OpenLP.ExceptionDialog', 'The following error occured when saving the report.\n\n'
 
119
                                                        '{exception}').format(file_name=file_path, exception=e))
160
120
 
161
121
    def on_send_report_button_clicked(self):
162
122
        """
223
183
        self.save_report_button.setEnabled(state)
224
184
        self.send_report_button.setEnabled(state)
225
185
 
226
 
    def _pyuno_import(self):
 
186
    def _get_pyuno_version(self):
227
187
        """
228
188
        Added here to define only when the form is actioned. The uno interface spits out lots of exception messages
229
189
        if the import is at a file level.  If uno import is changed this could be reverted.
241
201
            return node.getByName('ooSetupVersion')
242
202
        except ImportError:
243
203
            return '-'
244
 
        except:
 
204
        except Exception:
245
205
            return '- (Possible non-standard UNO installation)'