2012-12-21 08:51:59 +01:00
|
|
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
2016-05-31 10:51:40 +02:00
|
|
|
import sys, traceback
|
2013-04-11 07:38:31 +02:00
|
|
|
import cgi
|
2013-10-22 08:30:46 +02:00
|
|
|
|
|
|
|
from anki.lang import _
|
|
|
|
from aqt.qt import *
|
2012-12-21 08:51:59 +01:00
|
|
|
from aqt.utils import showText, showWarning
|
|
|
|
|
2017-01-08 11:30:34 +01:00
|
|
|
if not os.environ.get("DEBUG"):
|
|
|
|
def excepthook(etype,val,tb):
|
|
|
|
sys.stderr.write("Caught exception:\n%s%s\n" % (
|
|
|
|
''.join(traceback.format_tb(tb)),
|
|
|
|
'{0}: {1}'.format(etype, val)))
|
|
|
|
sys.excepthook = excepthook
|
2016-05-31 10:51:40 +02:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
class ErrorHandler(QObject):
|
|
|
|
"Catch stderr and write into buffer."
|
|
|
|
ivl = 100
|
|
|
|
|
2016-05-31 10:51:40 +02:00
|
|
|
errorTimer = pyqtSignal()
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def __init__(self, mw):
|
|
|
|
QObject.__init__(self, mw)
|
|
|
|
self.mw = mw
|
|
|
|
self.timer = None
|
2016-05-31 10:51:40 +02:00
|
|
|
self.errorTimer.connect(self._setTimer)
|
2012-12-21 08:51:59 +01:00
|
|
|
self.pool = ""
|
2017-06-26 05:03:05 +02:00
|
|
|
self._oldstderr = sys.stderr
|
2012-12-21 08:51:59 +01:00
|
|
|
sys.stderr = self
|
|
|
|
|
2017-06-26 05:03:05 +02:00
|
|
|
def unload(self):
|
|
|
|
sys.stderr = self._oldstderr
|
|
|
|
sys.excepthook = None
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def write(self, data):
|
|
|
|
# dump to stdout
|
2016-05-12 06:45:35 +02:00
|
|
|
sys.stdout.write(data)
|
2012-12-21 08:51:59 +01:00
|
|
|
# save in buffer
|
|
|
|
self.pool += data
|
|
|
|
# and update timer
|
|
|
|
self.setTimer()
|
|
|
|
|
|
|
|
def setTimer(self):
|
|
|
|
# we can't create a timer from a different thread, so we post a
|
|
|
|
# message to the object on the main thread
|
2016-05-31 10:51:40 +02:00
|
|
|
self.errorTimer.emit()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def _setTimer(self):
|
|
|
|
if not self.timer:
|
|
|
|
self.timer = QTimer(self.mw)
|
2016-05-31 10:51:40 +02:00
|
|
|
self.timer.timeout.connect(self.onTimeout)
|
2012-12-21 08:51:59 +01:00
|
|
|
self.timer.setInterval(self.ivl)
|
|
|
|
self.timer.setSingleShot(True)
|
|
|
|
self.timer.start()
|
|
|
|
|
2013-10-22 08:30:46 +02:00
|
|
|
def tempFolderMsg(self):
|
|
|
|
return _("""\
|
|
|
|
The permissions on your system's temporary folder are incorrect, and Anki is \
|
|
|
|
not able to correct them automatically. Please search for 'temp folder' in the \
|
|
|
|
Anki manual for more information.""")
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def onTimeout(self):
|
2013-04-11 07:38:31 +02:00
|
|
|
error = cgi.escape(self.pool)
|
2012-12-21 08:51:59 +01:00
|
|
|
self.pool = ""
|
|
|
|
self.mw.progress.clear()
|
|
|
|
if "abortSchemaMod" in error:
|
|
|
|
return
|
2017-07-09 05:26:50 +02:00
|
|
|
if "10013" in error:
|
|
|
|
return showWarning(_("Your firewall or antivirus program is preventing Anki from creating a connection to itself. Please add an exception for Anki."))
|
2012-12-21 08:51:59 +01:00
|
|
|
if "Pyaudio not" in error:
|
|
|
|
return showWarning(_("Please install PyAudio"))
|
|
|
|
if "install mplayer" in error:
|
|
|
|
return showWarning(_("Please install mplayer"))
|
2016-05-31 10:51:40 +02:00
|
|
|
if "no default input" in error.lower():
|
2013-01-08 02:27:34 +01:00
|
|
|
return showWarning(_("Please connect a microphone, and ensure "
|
|
|
|
"other programs are not using the audio device."))
|
2013-10-22 08:30:46 +02:00
|
|
|
if "invalidTempFolder" in error:
|
|
|
|
return showWarning(self.tempFolderMsg())
|
2016-07-04 10:06:08 +02:00
|
|
|
if "Beautiful Soup is not an HTTP client" in error:
|
|
|
|
return
|
2014-07-22 01:01:19 +02:00
|
|
|
if "disk I/O error" in error:
|
|
|
|
return showWarning(_("""\
|
|
|
|
An error occurred while accessing the database.
|
|
|
|
|
|
|
|
Possible causes:
|
|
|
|
|
|
|
|
- Antivirus, firewall, backup, or synchronization software may be \
|
|
|
|
interfering with Anki. Try disabling such software and see if the \
|
|
|
|
problem goes away.
|
|
|
|
- Your disk may be full.
|
|
|
|
- The Documents/Anki folder may be on a network drive.
|
|
|
|
- Files in the Documents/Anki folder may not be writeable.
|
|
|
|
- Your hard disk may have errors.
|
|
|
|
|
|
|
|
It's a good idea to run Tools>Check Database to ensure your collection \
|
|
|
|
is not corrupt.
|
|
|
|
"""))
|
2017-09-06 08:40:35 +02:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
stdText = _("""\
|
2017-09-06 08:40:35 +02:00
|
|
|
<h1>Error</h1>
|
|
|
|
|
|
|
|
<p>An error occurred. Please use <b>Tools > Check Database</b> to see if \
|
|
|
|
that fixes the problem.</p>
|
|
|
|
|
|
|
|
<p>If problems persist, please report the problem on our \
|
|
|
|
<a href="https://help.ankiweb.net">support site</a>. Please copy and paste \
|
|
|
|
the information below into your report.</p>""")
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
pluginText = _("""\
|
2017-09-06 08:40:35 +02:00
|
|
|
<h1>Error</h1>
|
|
|
|
|
2017-08-26 07:14:20 +02:00
|
|
|
<p>An error occurred. Please start Anki while holding down the shift \
|
|
|
|
key, which will temporarily disable the add-ons you have installed.</p>
|
|
|
|
|
2017-09-06 00:25:42 +02:00
|
|
|
<p>If the issue only occurs when add-ons are enabled, please use the \
|
2017-09-06 08:40:35 +02:00
|
|
|
Tools>Add-ons menu item to disable some add-ons and restart Anki, \
|
2017-08-26 07:14:20 +02:00
|
|
|
repeating until you discover the add-on that is causing the problem.</p>
|
2017-09-06 08:40:35 +02:00
|
|
|
|
|
|
|
<p>When you've discovered the add-on that is causing the problem, please \
|
|
|
|
report the issue on the <a href="https://help.ankiweb.net/discussions/add-ons/">\
|
|
|
|
add-ons section</a> of our support site.
|
|
|
|
|
|
|
|
<p>Debug info:</p>
|
2017-04-28 05:31:40 +02:00
|
|
|
""")
|
2017-08-26 07:14:20 +02:00
|
|
|
if self.mw.addonManager.dirty:
|
2012-12-21 08:51:59 +01:00
|
|
|
txt = pluginText
|
|
|
|
else:
|
|
|
|
txt = stdText
|
|
|
|
# show dialog
|
2017-09-06 08:40:35 +02:00
|
|
|
error = self._supportText() + "\n" + error
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
txt = txt + "<div style='white-space: pre-wrap'>" + error + "</div>"
|
|
|
|
showText(txt, type="html")
|
2017-09-06 08:40:35 +02:00
|
|
|
|
|
|
|
def _supportText(self):
|
|
|
|
import platform
|
|
|
|
from aqt import appVersion
|
|
|
|
|
|
|
|
if isWin:
|
|
|
|
platname = "Windows " + platform.win32_ver()[0]
|
|
|
|
elif isMac:
|
|
|
|
platname = "Mac " + platform.mac_ver()[0]
|
|
|
|
else:
|
|
|
|
platname = "Linux"
|
|
|
|
|
|
|
|
return f"""\
|
|
|
|
Anki {appVersion} Python {platform.python_version()} Qt {QT_VERSION_STR} PyQt {PYQT_VERSION_STR}
|
|
|
|
Platform: {platname}
|
|
|
|
Flags: frz={getattr(sys, "frozen", False)} ao={self.mw.addonManager.dirty}
|
|
|
|
"""
|